diff --git a/.github/actions/gitlog/action.yaml b/.github/actions/gitlog/action.yaml index 2b345637..b4a4e9be 100644 --- a/.github/actions/gitlog/action.yaml +++ b/.github/actions/gitlog/action.yaml @@ -4,10 +4,17 @@ inputs: output-file: description: File path where to place the content of the changed commits required: true + crate: + description: Name of the crate to get git log for + required: true +outputs: + last_release: + description: Last release commit or first commit of history + value: ${{ steps.gitlog.outputs.last_release }} runs: using: composite steps: - shell: bash id: gitlog run: | - ${{ github.action_path }}/gitlog.sh --output-file ${{ inputs.output-file }} + ${{ github.action_path }}/gitlog.sh --output-file ${{ inputs.output-file }} --crate ${{ inputs.crate }} diff --git a/.github/actions/gitlog/gitlog.sh b/.github/actions/gitlog/gitlog.sh index 6d420a22..855f7304 100755 --- a/.github/actions/gitlog/gitlog.sh +++ b/.github/actions/gitlog/gitlog.sh @@ -2,10 +2,8 @@ # This mangles git log entries for change lop purposes -from_commit=HEAD -last_release=$(git tag | sort -r | head -1) # get last tag - output_file="" +crate="" while true; do case $1 in "--output-file") @@ -13,12 +11,32 @@ while true; do output_file="$1" shift ;; + "--crate") + shift + crate="$1" + shift + ;; *) break ;; esac done +if [[ "$output_file" == "" ]]; then + echo "Missing --output-file option argument, define path to file or - for stdout" && exit 1 +fi +if [[ "$crate" == "" ]]; then + echo "Missing --crate option argument, need an explisit crate to get git log for" && exit 1 +fi + +from_commit=HEAD +last_release=$(git tag | grep -E "$crate-[0-9]*\.[0-9]*\.[0-9]*" | sort -r | head -1) +echo "Found tag: $last_release" +if [[ "$last_release" == "" ]]; then + last_release=$(git tag | sort -r | head -1) # get last tag + echo "Using latest tag: $last_release" +fi + commit_range="" if [[ $last_release != "" ]]; then commit_range="$from_commit...$last_release" @@ -33,10 +51,40 @@ fi mapfile -t log_lines < <(git log --pretty=format:'(%h) %s' $ancestry_path $commit_range) +function is_crate_related { + commit="$1" + changes="$(git diff --name-only "$commit"~ "$commit" | awk -F / '{print $1}' | xargs)" + + is_related=false + if [[ "$crate" != "utoipa" ]] && [[ "$changes" == *"$crate"* ]]; then + is_related=true + fi + if [[ "$crate" == "utoipa" ]] && [[ ! $changes =~ (utoipa-gen|utoipa-swagger-ui) ]]; then + is_related=true + fi + + echo $is_related +} + log="" for line in "${log_lines[@]}"; do - log=$log"* $line\n" + commit=$(echo "$line" | awk -F ' ' '{print $1}') + commit=${commit//[\(\)]/} + + if [[ $(is_crate_related "$commit") == true ]]; then + log=$log"* $line\n" + fi done + if [[ "$output_file" != "" ]]; then - echo -e "$log" > "$output_file" + if [[ "$output_file" == "-" ]]; then + echo -e "$log" + else + echo -e "$log" > "$output_file" + fi +fi + +if [[ "$last_release" == "" ]]; then + last_release=$(git rev-list --reverse HEAD | head -1) fi +echo "::set-output name=last_release::$last_release" \ No newline at end of file diff --git a/.github/actions/publish/action.yaml b/.github/actions/publish/action.yaml index 97e46d6c..35bde60b 100644 --- a/.github/actions/publish/action.yaml +++ b/.github/actions/publish/action.yaml @@ -4,10 +4,13 @@ inputs: token: description: Cargo login token to use the publish the crate required: true + ref: + description: "Github release tag ref" + required: true runs: using: composite steps: - shell: bash id: publish_crate run: | - ${{ github.action_path }}/publish.sh --token ${{ inputs.token }} + ${{ github.action_path }}/publish.sh --token ${{ inputs.token }} --ref ${{ inputs.ref }} diff --git a/.github/actions/publish/publish.sh b/.github/actions/publish/publish.sh index 713dc043..7b5951d2 100755 --- a/.github/actions/publish/publish.sh +++ b/.github/actions/publish/publish.sh @@ -3,6 +3,7 @@ # Publishes crate to crates.io token="" +ref="" while true; do case $1 in "--token") @@ -10,6 +11,11 @@ while true; do token="$1" shift ;; + "--ref") + shift + ref=${1/refs\/tags\//} + shift + ;; *) break ;; @@ -19,6 +25,9 @@ done if [[ "$token" == "" ]]; then echo "Missing --token option argument, cannot publish crates without it!" && exit 1 fi +if [[ "$ref" == "" ]]; then + echo "Missing --ref option argument, need an explisit ref to release!" && exit 1 +fi function publish { module="$1" @@ -35,15 +44,26 @@ fi echo "$token" | cargo login while read -r module; do - echo "Publishing module $module..." + # crate=$(echo "$ref" | sed 's|-[0-9]*\.[0-9]*\.[0-9].*||') + crate=${ref/-[0-9]\.[0-9]\.[0-9]*/} + if [[ "$crate" != "$module" ]]; then + echo "Module: $module does not match to release crate: $crate, skipping release for module" + continue + fi - current_version=$(cargo read-manifest --manifest-path "$module"/Cargo.toml | jq -r '.version') + toml="Cargo.toml" + if [[ "$module" != "utoipa" ]]; then + toml="$module/Cargo.toml" + fi + + current_version=$(cargo read-manifest --manifest-path "$toml" | jq -r '.version') last_version=$(curl -sS https://crates.io/api/v1/crates/"$module"/versions | jq -r '.versions[0].num') if [[ "$last_version" == "$current_version" ]]; then echo "Module: $module, is already at it's latest release ($last_version), nothing to release" continue fi + echo "Publishing module $module..." max_retries=10 retry=0 while ! publish "$module" && [[ $retry -lt $max_retries ]]; do diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 983883bb..3b2dfe08 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -18,10 +18,9 @@ jobs: strategy: matrix: testset: - - default - - actix - - gen - - swagger + - utoipa + - utoipa-gen + - utoipa-swagger-ui fail-fast: true runs-on: ubuntu-latest @@ -61,14 +60,13 @@ jobs: - name: Run tests run: | - if [[ "${{ matrix.testset }}" == "default" ]] && [[ ${{ steps.changes.outputs.root_changed }} == true ]]; then + if [[ "${{ matrix.testset }}" == "utoipa" ]] && [[ ${{ steps.changes.outputs.root_changed }} == true ]]; then cargo test cargo test --test path_response_derive_test_no_serde_json --no-default-features cargo test --test component_derive_no_serde_json --no-default-features - elif [[ "${{ matrix.testset }}" == "actix" ]] && [[ ${{ steps.changes.outputs.root_changed }} == true ]]; then - cargo test --features actix_extras - elif [[ "${{ matrix.testset }}" == "gen" ]] && [[ ${{ steps.changes.outputs.gen_changed }} == true ]]; then + cargo test --test path_derive_actix --test path_parameter_derive_actix --features actix_extras + elif [[ "${{ matrix.testset }}" == "utoipa-gen" ]] && [[ ${{ steps.changes.outputs.gen_changed }} == true ]]; then cargo test -p utoipa-gen --features actix_extras - elif [[ "${{ matrix.testset }}" == "swagger" ]] && [[ ${{ steps.changes.outputs.swagger_changed }} == true ]]; then + elif [[ "${{ matrix.testset }}" == "utoipa-swagger-ui" ]] && [[ ${{ steps.changes.outputs.swagger_changed }} == true ]]; then cargo test -p utoipa-swagger-ui --features actix-web fi diff --git a/.github/workflows/draft.yaml b/.github/workflows/draft.yaml index cbed9a6f..57aa2c8a 100644 --- a/.github/workflows/draft.yaml +++ b/.github/workflows/draft.yaml @@ -10,6 +10,13 @@ env: jobs: draft: + strategy: + matrix: + crate: + - utoipa + - utoipa-gen + - utoipa-swagger-ui + fail-fast: true runs-on: ubuntu-latest steps: @@ -22,18 +29,22 @@ jobs: id: gitlog with: output-file: ./draft-gitlog.md + crate: ${{ matrix.crate }} - name: Prepare changes run: | - echo "# Changes in this Release" > ./draft-changes.md + echo "## What's New :gem: :new: :tada:" > ./draft-changes.md cat < ./draft-gitlog.md >> ./draft-changes.md - cat ./draft-changes.md - - name: Get release info id: release_info run: | - version=$(cargo read-manifest | jq -r .version) + version="" + if [[ "${{ matrix.crate }}" == "utoipa" ]]; then + version=$(cargo read-manifest | jq -r .version) + else + version=$(cargo read-manifest --manifest-path "${{ matrix.crate }}/Cargo.toml" | jq -r .version) + fi prerelease=false if [[ "$version" =~ .*-.* ]]; then @@ -41,17 +52,21 @@ jobs: fi echo "::set-output name=is_prerelease::$prerelease" echo "::set-output name=version::$version" + + - name: Add full change log link + run: | + echo -e "#### Full [change log](${{ github.server_url }}/${{ github.repository }}/compare/${{ steps.gitlog.outputs.last_release }}...${{ matrix.crate }}-${{ steps.release_info.outputs.version }})" >> ./draft-changes.md - name: Check existing release run: | - if git tag | grep ${{ steps.release_info.outputs.version }} > /dev/null; then - echo "Tag tag with ${{ steps.release_info.outputs.version }} already exists, cannot draft a release for already existing tag!, Consider upgrading versions to Cargo.toml file" && exit 1 + if git tag | grep ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} > /dev/null; then + echo "Tag tag with ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} already exists, cannot draft a release for already existing tag!, Consider upgrading versions to Cargo.toml file" && exit 1 fi - name: Remove previous release run: | echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token - gh release delete ${{ steps.release_info.outputs.version }} -y || true + gh release delete ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} -y || true - name: Create release id: create_release @@ -59,8 +74,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ steps.release_info.outputs.version }} - release_name: Release ${{ steps.release_info.outputs.version }} + tag_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} + release_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} body_path: ./draft-changes.md draft: true prerelease: ${{ steps.release_info.outputs.is_prerelease }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9fcd2702..1e0e7032 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,3 +20,4 @@ jobs: name: Cargo publish with: token: ${{ secrets.CARGO_LOGIN }} + ref: ${{ github.ref }}