From 8be1d07f880b97bc1bf00f859346353c0678d401 Mon Sep 17 00:00:00 2001 From: cvetty Date: Sun, 15 Dec 2024 14:51:44 +0200 Subject: [PATCH] Update the release notes generation. --- .github/actions/draft-release/script.js | 2 +- .github/actions/pre-release/script.js | 2 +- .../{release => release-cleanup}/action.yml | 8 +-- .github/actions/release-cleanup/script.js | 48 +++++++++++++++ .../unpublish-beta-versions.sh | 0 .github/actions/release/script.js | 59 ------------------ .github/release.yml | 2 - .github/workflows/cd_draft_release.yml | 2 +- .github/workflows/cd_release.yml | 61 ++++++++----------- 9 files changed, 78 insertions(+), 106 deletions(-) rename .github/actions/{release => release-cleanup}/action.yml (80%) create mode 100644 .github/actions/release-cleanup/script.js rename .github/actions/{release => release-cleanup}/unpublish-beta-versions.sh (100%) delete mode 100644 .github/actions/release/script.js diff --git a/.github/actions/draft-release/script.js b/.github/actions/draft-release/script.js index 08a39e1..c5589ea 100644 --- a/.github/actions/draft-release/script.js +++ b/.github/actions/draft-release/script.js @@ -1,5 +1,5 @@ module.exports = async ({ github, context, inputs }) => { - const tagName = `unreleased[${inputs.branchName}]`; + const tagName = `${inputs.branchName}-unreleased`; const releases = await github.rest.repos.listReleases({ owner: context.repo.owner, repo: context.repo.repo, diff --git a/.github/actions/pre-release/script.js b/.github/actions/pre-release/script.js index 1d312ec..b2bb577 100644 --- a/.github/actions/pre-release/script.js +++ b/.github/actions/pre-release/script.js @@ -1,5 +1,5 @@ module.exports = async ({ github, context, inputs }) => { - const draftTagName = `unreleased[${inputs.branchName}]`; + const draftTagName = `${inputs.branchName}-unreleased`; const releases = await github.rest.repos.listReleases({ owner: context.repo.owner, diff --git a/.github/actions/release/action.yml b/.github/actions/release-cleanup/action.yml similarity index 80% rename from .github/actions/release/action.yml rename to .github/actions/release-cleanup/action.yml index 7e01be1..a532346 100644 --- a/.github/actions/release/action.yml +++ b/.github/actions/release-cleanup/action.yml @@ -1,10 +1,7 @@ -name: "Release" -description: "Release the pre-release release" +name: "Release cleanup" +description: "Beta versions cleanup" inputs: - release_id: - description: "The id of the target release" - required: true tag_name: description: "The release version tag" required: true @@ -24,7 +21,6 @@ runs: github, context, inputs: { - releaseId: '${{ inputs.release_id }}', tagName: '${{ inputs.tag_name }}', } }) diff --git a/.github/actions/release-cleanup/script.js b/.github/actions/release-cleanup/script.js new file mode 100644 index 0000000..c5c03c4 --- /dev/null +++ b/.github/actions/release-cleanup/script.js @@ -0,0 +1,48 @@ +module.exports = async ({ github, context, inputs }) => { + const majorVersion = inputs.tagName.split(".")[0]; + + // Cleanup beta releases + console.log("Cleaning up beta releases..."); + const { data: releases } = await github.rest.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + + for (const release of releases) { + if ( + !release.tag_name.startsWith(`${majorVersion}.`) || + !release.tag_name.includes("-beta") + ) { + continue; + } + + console.log(`Deleting beta release: ${release.tag_name}`); + await github.rest.repos.deleteRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + }); + } + + // Cleanup beta tags + console.log("Cleaning up beta tags..."); + const { data: tags } = await github.rest.repos.listTags({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + for (const tag of tags) { + if ( + !tag.name.startsWith(`${majorVersion}.`) || + !tag.name.includes("-beta") + ) { + continue; + } + + console.log(`Deleting beta tag: ${tag.name}`); + await github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${tag.name}`, + }); + } +}; diff --git a/.github/actions/release/unpublish-beta-versions.sh b/.github/actions/release-cleanup/unpublish-beta-versions.sh similarity index 100% rename from .github/actions/release/unpublish-beta-versions.sh rename to .github/actions/release-cleanup/unpublish-beta-versions.sh diff --git a/.github/actions/release/script.js b/.github/actions/release/script.js deleted file mode 100644 index a189259..0000000 --- a/.github/actions/release/script.js +++ /dev/null @@ -1,59 +0,0 @@ -module.exports = async ({ github, context, inputs }) => { - const majorVersion = inputs.tagName.split(".")[0]; - - // Get current release - const { data: release } = await github.rest.repos.getRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: inputs.releaseId, - }); - - console.log("Updating release tag..."); - await github.rest.repos.updateRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: release.id, - name: inputs.tagName, - tag_name: inputs.tagName, - draft: false, - prerelease: false, - }); - - // Cleanup beta releases - console.log("Cleaning up beta releases..."); - const { data: releases } = await github.rest.repos.listReleases({ - owner: context.repo.owner, - repo: context.repo.repo, - }); - - for (const release of releases) { - if ( - release.tag_name.startsWith(`${majorVersion}.`) && - release.tag_name.includes("-beta") - ) { - console.log(`Deleting beta release: ${release.tag_name}`); - await github.rest.repos.deleteRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: release.id, - }); - } - } - - // Cleanup beta tags - console.log("Cleaning up beta tags..."); - const { data: tags } = await github.rest.repos.listTags({ - owner: context.repo.owner, - repo: context.repo.repo, - }); - for (const tag of tags) { - if (tag.name.startsWith(`${majorVersion}.`) && tag.name.includes("-beta")) { - console.log(`Deleting beta tag: ${tag.name}`); - await github.rest.git.deleteRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/tags/${tag.name}`, - }); - } - } -}; diff --git a/.github/release.yml b/.github/release.yml index a7d9488..ad76b63 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -1,5 +1,3 @@ -# .github/release.yml -# Contains configure for auto generated release notes changelog: exclude: labels: diff --git a/.github/workflows/cd_draft_release.yml b/.github/workflows/cd_draft_release.yml index 764815c..3180a4f 100644 --- a/.github/workflows/cd_draft_release.yml +++ b/.github/workflows/cd_draft_release.yml @@ -1,5 +1,5 @@ name: Draft Release -run-name: Draft Release latest updates of ${{ github.ref_name }} (@${{ github.actor }}) +run-name: Draft Release of ${{ github.ref_name }} triggered by @${{ github.actor }} on: push: diff --git a/.github/workflows/cd_release.yml b/.github/workflows/cd_release.yml index b1d90f3..ce3f730 100644 --- a/.github/workflows/cd_release.yml +++ b/.github/workflows/cd_release.yml @@ -26,7 +26,6 @@ jobs: runs-on: "ubuntu-22.04" outputs: version_branch: ${{ steps.get-version-details.outputs.major_version}}.x - release_version: ${{ steps.get-clean-version.outputs.version }} steps: - name: Get Github token id: get-github-token @@ -35,32 +34,29 @@ jobs: application_id: ${{ vars.GH_MTR_PACKAGE_VERSIONS_APP_ID }} application_private_key: ${{ secrets.GH_MTR_PACKAGE_VERSIONS_APP_SECRET }} - - name: Get release title and tag + - name: Get release version details id: get-version-details run: | - echo "release_title=${{ github.event.release.name }}" >> $GITHUB_OUTPUT - echo "release_tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT - # Extract major version (handles v1.2.3-beta.0 or 1.2.3-beta.0) MAJOR_VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v\{0,1\}\([0-9]\+\)[^0-9].*/\1/') echo "major_version=$MAJOR_VERSION" >> $GITHUB_OUTPUT - - name: Checkout code + - name: Checkout the repository uses: actions/checkout@v4 with: ref: ${{ steps.get-version-details.outputs.major_version}}.x token: ${{ steps.get-github-token.outputs.token }} - - name: Check release title format + - name: Verify the release title env: - RELEASE_TITLE: ${{ steps.get-version-details.outputs.release_title }} + RELEASE_TITLE: ${{ github.event.release.name }} run: | if [[ -z "$RELEASE_TITLE" ]]; then echo "Release title cannot be empty" exit 1 fi - TITLE_VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+(-alpha|-beta)?$" + TITLE_VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$" if [[ ! $RELEASE_TITLE =~ $TITLE_VERSION_REGEX ]]; then echo "Invalid release title format: $RELEASE_TITLE" exit 1 @@ -68,36 +64,27 @@ jobs: echo "Release title $RELEASE_TITLE is valid" fi - - name: Get the clean version - id: get-clean-version - env: - TAG_NAME: ${{ steps.get-version-details.outputs.tag_name }} - run: | - VERSION=$(echo "$TAG_NAME" | sed 's/^v//' | cut -d'-' -f1) - echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - name: Update package.json version env: - CLEAN_VERSION: ${{ steps.get-clean-version.outputs.version }} + VERSION: ${{ github.event.release.tag_name }} run: | - npm version $CLEAN_VERSION + npm version $VERSION - - name: Commit version bump in different branch - id: create-release-branch + - name: Commit the version bump update env: - CLEAN_VERSION: ${{ steps.get-clean-version.outputs.version }} + VERSION: ${{ github.event.release.tag_name }} GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} run: | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" git add . - git commit -am "Bump version to $CLEAN_VERSION" + git commit -am "[GHA] Update package version to $VERSION" git push origin HEAD:$CLEAN_VERSION release: @@ -153,18 +140,22 @@ jobs: - name: Delete existing release asset uses: actions/github-script@v6 + env: + ASSET_ID: ${{ steps.download-production-build.outputs.result }} with: script: | - const assetId = ${{ steps.download-production-build.outputs.result }} + const {ASSET_ID} = process.env await github.rest.repos.deleteReleaseAsset({ owner: context.repo.owner, repo: context.repo.repo, - asset_id: assetId + asset_id: ASSET_ID }); - name: Upload an Asset in GitHub Release uses: actions/github-script@v6 + env: + RELEASE_ID: ${{ github.event.release.id }} with: script: | const {RELEASE_ID} = process.env @@ -177,16 +168,6 @@ jobs: release_id: ${{ env.RELEASE_ID }}, data: await fs.readFile('./krait-ui/distribution-package.zip') }); - env: - RELEASE_ID: ${{ github.event.release.id }} - - - name: Set pre-release tag - id: update-release - uses: ./.github/actions/release - with: - release_id: ${{ github.event.release.id }} - tag_name: ${{ needs.bump_version.outputs.release_version }} - node_auth_token: ${{ secrets.NPM_AUTH_TOKEN }} - name: Unzip the distribution build working-directory: krait-ui @@ -197,3 +178,11 @@ jobs: # run: npm publish --access public # env: # NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + - name: Release cleanup + id: update-release + uses: ./.github/actions/release-cleanup + with: + release_id: ${{ github.event.release.id }} + tag_name: ${{ needs.bump_version.outputs.release_version }} + node_auth_token: ${{ secrets.NPM_AUTH_TOKEN }}