From 8a9684dfa458459773e0db81a0a2969697dc024c Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Fri, 15 Dec 2023 12:57:42 +0100 Subject: [PATCH] Update automated release process to latest version (#705) ### Changes Update the workflow to incorporate the latest, and hopefully final, changes. ### Checklist - [x] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md) - [x] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md) - [x] All code quality tools/guidelines have been run/followed --------- Signed-off-by: Frederik Prijck --- .github/actions/get-release-notes/action.yml | 4 +- .../action.yml | 16 ++-- .github/workflows/npm-release.yml | 80 +++++++++++++++++++ .github/workflows/release.yml | 74 +++-------------- 4 files changed, 104 insertions(+), 70 deletions(-) rename .github/actions/{publish-package => npm-publish}/action.yml (76%) create mode 100644 .github/workflows/npm-release.yml diff --git a/.github/actions/get-release-notes/action.yml b/.github/actions/get-release-notes/action.yml index 45de354c..4c3219b6 100644 --- a/.github/actions/get-release-notes/action.yml +++ b/.github/actions/get-release-notes/action.yml @@ -1,4 +1,4 @@ -name: Return the release notes extracted from the PR body +name: Return the release notes extracted from the body of the PR associated with the release. # # 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. @@ -39,4 +39,4 @@ runs: GITHUB_TOKEN: ${{ inputs.token }} REPO_OWNER: ${{ inputs.repo_owner }} REPO_NAME: ${{ inputs.repo_name }} - VERSION: ${{ inputs.version }} + VERSION: ${{ inputs.version }} \ No newline at end of file diff --git a/.github/actions/publish-package/action.yml b/.github/actions/npm-publish/action.yml similarity index 76% rename from .github/actions/publish-package/action.yml rename to .github/actions/npm-publish/action.yml index abbfcaaa..45c87d19 100644 --- a/.github/actions/publish-package/action.yml +++ b/.github/actions/npm-publish/action.yml @@ -1,4 +1,4 @@ -name: Publish release to package manager +name: Publish release to npm inputs: node-version: @@ -7,6 +7,8 @@ inputs: required: true version: required: true + require-build: + default: true release-directory: default: './' @@ -24,10 +26,14 @@ runs: cache: 'npm' registry-url: 'https://registry.npmjs.org' + - name: Install dependencies + shell: bash + run: npm ci --include=dev + - name: Build package - uses: ./.github/actions/build - with: - node: ${{ inputs.node-version }} + if: inputs.require-build == 'true' + shell: bash + run: npm run build - name: Publish release to NPM shell: bash @@ -43,4 +49,4 @@ runs: npm publish --provenance --tag $TAG env: NODE_AUTH_TOKEN: ${{ inputs.npm-token }} - VERSION: ${{ inputs.version }} + VERSION: ${{ inputs.version }} \ No newline at end of file diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml new file mode 100644 index 00000000..1595357d --- /dev/null +++ b/.github/workflows/npm-release.yml @@ -0,0 +1,80 @@ +name: Create npm and GitHub Release + +on: + workflow_call: + inputs: + node-version: + required: true + type: string + require-build: + default: true + type: string + release-directory: + default: './' + type: string + secrets: + github-token: + required: true + npm-token: + required: true + +jobs: + release: + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) + runs-on: ubuntu-latest + environment: release + + steps: + # Checkout the code + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Get the version from the branch name + - id: get_version + uses: ./get-version + + # Get the prerelease flag from the branch name + - id: get_prerelease + uses: ./get-prerelease + with: + version: ${{ steps.get_version.outputs.version }} + + # Get the release notes + - id: get_release_notes + uses: ./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 + uses: ./tag-exists + with: + 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: ./npm-publish + with: + node-version: ${{ inputs.node-version }} + require-build: ${{ inputs.require-build }} + version: ${{ steps.get_version.outputs.version }} + npm-token: ${{ secrets.npm-token }} + release-directory: ${{ inputs.release-directory }} + + # Create a release for the tag + - uses: ./release-create + with: + token: ${{ secrets.github-token }} + name: ${{ steps.get_version.outputs.version }} + body: ${{ steps.get_release_notes.outputs.release-notes }} + tag: ${{ steps.get_version.outputs.version }} + commit: ${{ github.sha }} + prerelease: ${{ steps.get_prerelease.outputs.prerelease }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db2fec97..592a3e34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Create GitHub Release +name: Create npm and GitHub Release on: pull_request: @@ -10,68 +10,16 @@ permissions: contents: write id-token: write # For publishing to npm using --provenance -env: - NODE_VERSION: 18 - -### TODO: Replace instances of './.github/actions/' w/ `auth0/dx-sdk-actions/` and append `@latest` after the common `dx-sdk-actions` repo is made public. -### TODO: Also remove `get-prerelease`, `get-version`, `release-create`, `tag-create` and `tag-exists` actions from this repo's .github/actions folder once the repo is public. +### TODO: Replace instances of './.github/workflows/' w/ `auth0/dx-sdk-actions/workflows/` and append `@latest` after the common `dx-sdk-actions` repo is made public. +### TODO: Also remove `get-prerelease`, `get-release-notes`, `get-version`, `npm-publish`, `release-create`, and `tag-exists` actions from this repo's .github/actions folder once the repo is public. +### TODO: Also remove `npm-release` workflow from this repo's .github/workflows folder once the repo is public. jobs: release: - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) - runs-on: ubuntu-latest - environment: release - - steps: - # Checkout the code - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # Get the version from the branch name - - id: get_version - uses: ./.github/actions/get-version - - # Get the prerelease flag from the branch name - - id: get_prerelease - 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 - uses: ./.github/actions/tag-exists - with: - 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 - with: - node-version: ${{ env.NODE_VERSION }} - version: ${{ steps.get_version.outputs.version }} - npm-token: ${{ secrets.NPM_TOKEN }} - - # Create a release for the tag - - uses: ./.github/actions/release-create - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: ${{ steps.get_version.outputs.version }} - body: ${{ steps.get_release_notes.outputs.release-notes }} - tag: ${{ steps.get_version.outputs.version }} - commit: ${{ github.sha }} - prerelease: ${{ steps.get_prerelease.outputs.prerelease }} + uses: ./.github/workflows/npm-release.yml + with: + node-version: 18 + require-build: true + secrets: + npm-token: ${{ secrets.NPM_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file