From 34bc230b725010c5e5f6bf823d03ecdfaa2984e9 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 25 Jul 2023 15:33:44 -0500 Subject: [PATCH 1/2] auto detect latest --- .github/workflows/github-release.yml | 73 ++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index b7ced31a..a6fcf8dd 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -182,7 +182,7 @@ jobs: needs: [check-release-exists, audit-release-different-commit] if: >- needs.check-release-exists.outputs.draft_exists == 'true' && - inputs.test_run == false + inputs.test_run == false steps: - name: "Publish Draft Release - ${{ needs.check-release-exists.outputs.tag }}" @@ -192,25 +192,54 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ needs.check-release-exists.outputs.tag }} - create-github-release: + set-release-flags: runs-on: ubuntu-latest needs: [check-release-exists, audit-release-different-commit] + outputs: + latest: ${{ steps.latest_check.outputs.latest }} + prerelease: ${{ steps.release_type.outputs.prerelease }} + draft: ${{ steps.draft.outputs.draft }} + if: needs.check-release-exists.outputs.draft_exists == 'false' - steps: - - name: "Download Artifact ${{ inputs.version_number }}" - uses: actions/download-artifact@v3 + - name: "Get current latest release" + # not specifying tag means it will return the release marked as latest + id: latest_check + run: | + output=$(gh release view --json tagName) + latest_tag=$(jq -r '.tagName' <<< "$output") + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: "Parse Latest Version Into Parts" + id: semver-latest + uses: dbt-labs/actions/parse-semver@main with: - name: ${{ inputs.version_number }} - path: . + version: ${{ steps.latest_check.outputs.latest_tag }} - - name: "[DEBUG] Display Structure Of All Downloaded Files" - run: ls -R + - name: "Parse Input Version Into Parts" + id: semver-pending-release + uses: dbt-labs/actions/parse-semver@main + with: + version: ${{ inputs.version_number }} + + - name: "Determine if new release should be marked as latest" + id: mark_latest + run: | + if [[ ${{ steps.semver-pending-release.outputs.is-pre-release }} == 1 || ${{ inputs.test_run }} ]] + then + echo "This is a prerelease or test run. Cannot be marked as latest." + elif [[ ${{ steps.semver-latest.outputs.minor }} <= ${{ steps.semver-pending-release.outputs.minor }} ]] + then + echo "Marking as latest. Current latest is ${{ steps.latest_check.outputs.latest_tag }}" + echo "latest=--latest" >> $GITHUB_OUTPUT + fi - name: "Set Release Type" id: release_type run: | - if ${{ contains(inputs.version_number, 'rc') || contains(inputs.version_number, 'b') }} + if [[ ${{ steps.semver-pending-release.outputs.is-pre-release }} == 1 ]] then echo Release will be set as pre-release echo "prerelease=--prerelease" >> $GITHUB_OUTPUT @@ -229,20 +258,36 @@ jobs: echo This is not a draft release fi + create-github-release: + runs-on: ubuntu-latest + needs: [check-release-exists, set-release-flags] + if: needs.check-release-exists.outputs.draft_exists == 'false' + + steps: + - name: "Download Artifact ${{ inputs.version_number }}" + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.version_number }} + path: . + + - name: "[DEBUG] Display Structure Of All Downloaded Files" + run: ls -R + - name: "GitHub Release Workflow Annotation" run: | title="Release ${{ needs.check-release-exists.outputs.tag }}" - message="Configuration: ${{ steps.release_type.outputs.prerelease }} ${{ steps.draft.outputs.draft }}" + message="Configuration: ${{ needs.set-release-flags.outputs.prerelease }} ${{ needs.set-release-flags.outputs.draft }} ${{ needs.set-release-flags.outputs.latest }}" echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message" - name: "Create New GitHub Release - ${{ needs.check-release-exists.outputs.tag }}" run: | - gh release create $TAG ./dist/* --title "$TITLE" --notes-file $RELEASE_NOTES --target $COMMIT $PRERELEASE $DRAFT --repo ${{ env.REPO_LINK }} + gh release create $TAG ./dist/* --title "$TITLE" --notes-file $RELEASE_NOTES --target $COMMIT $PRERELEASE $DRAFT $LATEST legacy --repo ${{ env.REPO_LINK }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ needs.check-release-exists.outputs.tag }} TITLE: ${{ github.event.repository.name }} ${{ needs.check-release-exists.outputs.tag }} RELEASE_NOTES: ${{ inputs.changelog_path }} COMMIT: ${{ inputs.sha }} - PRERELEASE: ${{ steps.release_type.outputs.prerelease }} - DRAFT: ${{ steps.draft.outputs.draft }} + PRERELEASE: ${{ needs.set-release-flags.outputs.prerelease }} + DRAFT: ${{ needs.set-release-flags.outputs.draft }} + LATEST: ${{ needs.set-release-flags.outputs.latest }} From 33a751b5745cfd194b709780428205b8fa2eca6b Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 25 Jul 2023 15:38:46 -0500 Subject: [PATCH 2/2] fix some typos --- .github/workflows/github-release.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index a6fcf8dd..83ad52c5 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -196,19 +196,17 @@ jobs: runs-on: ubuntu-latest needs: [check-release-exists, audit-release-different-commit] outputs: - latest: ${{ steps.latest_check.outputs.latest }} + latest: ${{ steps.mark_latest.outputs.latest }} prerelease: ${{ steps.release_type.outputs.prerelease }} draft: ${{ steps.draft.outputs.draft }} - if: needs.check-release-exists.outputs.draft_exists == 'false' steps: - name: "Get current latest release" - # not specifying tag means it will return the release marked as latest + # not specifying tag means it will return the release currently marked as latest id: latest_check run: | output=$(gh release view --json tagName) latest_tag=$(jq -r '.tagName' <<< "$output") - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}