From 80153f43e59a67a3db69011d2644bec096d66e4a Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Wed, 6 Dec 2023 20:48:58 +0100 Subject: [PATCH 1/5] Read version from .version file and add get_release_notes --- .github/actions/get-release-notes/action.yml | 44 ++++++++++++++++++++ .github/actions/get-version/action.yml | 6 +-- .github/workflows/release.yml | 22 +++++++--- .shiprc | 11 +++-- .version | 1 + 5 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 .github/actions/get-release-notes/action.yml create mode 100644 .version diff --git a/.github/actions/get-release-notes/action.yml b/.github/actions/get-release-notes/action.yml new file mode 100644 index 000000000..8b15cef0c --- /dev/null +++ b/.github/actions/get-release-notes/action.yml @@ -0,0 +1,44 @@ +name: Return the release notes extracted from the PR body + +# +# Returns the release notes from the content of a pull request linked to a release branch. It expects the branch name to be in the format release/vX.Y.Z, release/X.Y.Z, release/vX.Y.Z-beta.N. etc. +# +# TODO: Remove once the common repo is public. +# +inputs: + version : + required: true + repo_name: + required: false + repo_owner: + required: true + token: + required: true + +runs: + using: composite + + steps: + - id: get_release_notes + shell: bash + run: | + RELEASE_PR_BRANCH="release/$VERSION" + API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls" + RELEASE_NOTES=$(curl -G \ + -H "Accept: application/json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + --data-urlencode "state=all" \ + --data-urlencode "head=$REPO_OWNER:$RELEASE_PR_BRANCH" \ + "$API_URL" | jq -r ".[0].body" + ) + { + echo 'RELEASE_NOTES<> $GITHUB_ENV + + env: + GITHUB_TOKEN: ${{ inputs.token }} + REPO_OWNER: ${{ inputs.repo_owner }} + REPO_NAME: ${{ inputs.repo_name }} + VERSION: ${{ inputs.version }} diff --git a/.github/actions/get-version/action.yml b/.github/actions/get-version/action.yml index 387fdba67..9440ec920 100644 --- a/.github/actions/get-version/action.yml +++ b/.github/actions/get-version/action.yml @@ -1,7 +1,7 @@ name: Return the version extracted from the branch name # -# Returns the version from a branch name of a pull request. It expects the branch name to be in the format release/vX.Y.Z, release/X.Y.Z, release/vX.Y.Z-beta.N. etc. +# Returns the version from the .version file. # # TODO: Remove once the common repo is public. # @@ -17,7 +17,5 @@ runs: - id: get_version shell: bash run: | - VERSION=$(echo ${BRANCH_NAME} | sed -r 's#release/+##g') + VERSION=$(head -1 .version) echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT - env: - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b11376ffe..5b86549fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,7 @@ on: pull_request: types: - closed + workflow_dispatch: permissions: contents: write @@ -16,7 +17,7 @@ env: jobs: release: - if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/') + if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) runs-on: ubuntu-latest environment: release @@ -35,6 +36,16 @@ jobs: uses: ./.github/actions/get-prerelease with: version: ${{ steps.get_version.outputs.version }} + + # Get the release notes + # This will expose the release notes as env.RELEASE_NOTES + - id: get_release_notes + uses: ./.github/actions/get-release-notes + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: ${{ steps.get_version.outputs.version }} + repo_owner: ${{ github.repository_owner }} + repo_name: ${{ github.event.repository.name }} # Check if the tag already exists - id: tag_exists @@ -43,28 +54,27 @@ jobs: tag: ${{ steps.get_version.outputs.version }} token: ${{ secrets.GITHUB_TOKEN }} - # If the tag already exists, exit with an error - - if: steps.tag_exists.outputs.exists == 'true' - run: exit 1 - # Publish the release to our package manager - uses: ./.github/actions/publish-package + if: steps.tag_exists.outputs.exists == 'false' with: node-version: ${{ env.NODE_VERSION }} npm-token: ${{ secrets.NPM_TOKEN }} # Create a tag for the release - uses: ./.github/actions/tag-create + if: steps.tag_exists.outputs.exists == 'false' with: tag: ${{ steps.get_version.outputs.version }} token: ${{ secrets.GITHUB_TOKEN }} # Create a release for the tag - uses: ./.github/actions/release-create + if: steps.tag_exists.outputs.exists == 'false' with: token: ${{ secrets.GITHUB_TOKEN }} name: ${{ steps.get_version.outputs.version }} - body: ${{ github.event.pull_request.body }} + body: ${{ env.RELEASE_NOTES }} tag: ${{ steps.get_version.outputs.version }} commit: ${{ github.sha }} prerelease: ${{ steps.get_prerelease.outputs.prerelease }} diff --git a/.shiprc b/.shiprc index 5215f1661..17e66ff1b 100644 --- a/.shiprc +++ b/.shiprc @@ -1,8 +1,13 @@ { "files": { "src/version.ts": [], - "README.md": ["{MAJOR}.{MINOR}"], - "FAQ.md": ["{MAJOR}.{MINOR}.{PATCH}"] + ".version": [], + "README.md": [ + "{MAJOR}.{MINOR}" + ], + "FAQ.md": [ + "{MAJOR}.{MINOR}.{PATCH}" + ] }, "postbump": "npm run docs" -} +} \ No newline at end of file diff --git a/.version b/.version new file mode 100644 index 000000000..18f3fb198 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +v2.1.2 \ No newline at end of file From 6da251b9af631dfb17671d5de27433a0db3862d0 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Wed, 6 Dec 2023 23:54:03 +0100 Subject: [PATCH 2/5] Bring back exit 1 when tag exists --- .github/workflows/release.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b86549fe..c5b4e71da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,23 +54,24 @@ jobs: tag: ${{ steps.get_version.outputs.version }} token: ${{ secrets.GITHUB_TOKEN }} + # If the tag already exists, exit with an error + - if: steps.tag_exists.outputs.exists == 'true' + run: exit 1 + # Publish the release to our package manager - uses: ./.github/actions/publish-package - if: steps.tag_exists.outputs.exists == 'false' with: node-version: ${{ env.NODE_VERSION }} npm-token: ${{ secrets.NPM_TOKEN }} # Create a tag for the release - uses: ./.github/actions/tag-create - if: steps.tag_exists.outputs.exists == 'false' with: tag: ${{ steps.get_version.outputs.version }} token: ${{ secrets.GITHUB_TOKEN }} # Create a release for the tag - uses: ./.github/actions/release-create - if: steps.tag_exists.outputs.exists == 'false' with: token: ${{ secrets.GITHUB_TOKEN }} name: ${{ steps.get_version.outputs.version }} From 9ee710d936dca8d2ead7a238d024f0048f22582f Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 11 Dec 2023 10:06:03 +0100 Subject: [PATCH 3/5] Avoid creating a tag manually --- .github/actions/tag-create/action.yml | 33 --------------------------- .github/workflows/release.yml | 6 ----- 2 files changed, 39 deletions(-) delete mode 100644 .github/actions/tag-create/action.yml diff --git a/.github/actions/tag-create/action.yml b/.github/actions/tag-create/action.yml deleted file mode 100644 index 727df4854..000000000 --- a/.github/actions/tag-create/action.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Create a repository tag - -# -# Creates a tag with the given version. -# -# TODO: Remove once the common repo is public. -# - -inputs: - token: - required: true - tag: - required: true - -runs: - using: composite - - steps: - - shell: bash - run: | - git config user.name "${AUTHOR_USERNAME}" - git config user.email "${AUTHOR_EMAIL}" - env: - AUTHOR_USERNAME: ${{ github.event.pull_request.user.login }} - AUTHOR_EMAIL: ${{ github.event.pull_request.user.email }} - - - shell: bash - run: | - git tag -a ${TAG_NAME} -m "Version ${TAG_NAME}" - git push --follow-tags - env: - TAG_NAME: ${{ inputs.tag }} - GITHUB_TOKEN: ${{ inputs.token }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5b4e71da..4aeb31c7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,12 +64,6 @@ jobs: node-version: ${{ env.NODE_VERSION }} npm-token: ${{ secrets.NPM_TOKEN }} - # Create a tag for the release - - uses: ./.github/actions/tag-create - with: - tag: ${{ steps.get_version.outputs.version }} - token: ${{ secrets.GITHUB_TOKEN }} - # Create a release for the tag - uses: ./.github/actions/release-create with: From 0b78278895be090d9a60eaeada07f33494536407 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 11 Dec 2023 10:06:19 +0100 Subject: [PATCH 4/5] Drop automated trigger for now to test manual trigger --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4aeb31c7a..e01357bc7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ env: jobs: release: - if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) + if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest environment: release From fc2f80608651c5f534bce0207931015f045e297a Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 11 Dec 2023 11:17:07 +0100 Subject: [PATCH 5/5] Update get-release-notes to use github-scripts --- .github/actions/get-release-notes/action.yml | 30 ++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/actions/get-release-notes/action.yml b/.github/actions/get-release-notes/action.yml index 8b15cef0c..846aa45c9 100644 --- a/.github/actions/get-release-notes/action.yml +++ b/.github/actions/get-release-notes/action.yml @@ -19,24 +19,18 @@ runs: using: composite steps: - - id: get_release_notes - shell: bash - run: | - RELEASE_PR_BRANCH="release/$VERSION" - API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls" - RELEASE_NOTES=$(curl -G \ - -H "Accept: application/json" \ - -H "Authorization: token $GITHUB_TOKEN" \ - --data-urlencode "state=all" \ - --data-urlencode "head=$REPO_OWNER:$RELEASE_PR_BRANCH" \ - "$API_URL" | jq -r ".[0].body" - ) - { - echo 'RELEASE_NOTES<> $GITHUB_ENV - + - uses: actions/github-script@v7 + id: get_release_notes + with: + result-encoding: string + script: | + const { data: pulls } = await github.rest.pulls.list({ + owner: process.env.REPO_OWNER, + repo: process.env.REPO_NAME, + state: 'all', + head: `${process.env.REPO_OWNER}:release/${process.env.VERSION}`, + }); + core.exportVariable('RELEASE_NOTES', pulls[0].body) env: GITHUB_TOKEN: ${{ inputs.token }} REPO_OWNER: ${{ inputs.repo_owner }}