From c3c015ef542c4bbe0c2d16b9d5a7aa0d4a632a2b Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 13 Dec 2023 14:00:35 +0100 Subject: [PATCH 1/3] Making release workflow reusable --- .github/workflows/npm-release.yml | 83 +++++++++++++++++++++++++++++++ .github/workflows/release.yml | 63 +++-------------------- 2 files changed, 89 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/npm-release.yml diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml new file mode 100644 index 00000000..7d33b5ed --- /dev/null +++ b/.github/workflows/npm-release.yml @@ -0,0 +1,83 @@ +name: Create GitHub Release + +on: + workflow_call: + inputs: + node-version: + required: true + type: string + secrets: + github-token: + required: true + npm-token: + required: true + +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. + +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: ${{ inputs.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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db2fec97..f61dc7fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,60 +18,9 @@ env: 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: ${{ env.NODE_VERSION }} + secrets: + npm-token: ${{ secrets.NPM_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} From 190d135de8410efcf045706d5b42a69b81c8f949 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 13 Dec 2023 15:50:18 +0100 Subject: [PATCH 2/3] Remove permissions that are duplicated --- .github/workflows/release.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f61dc7fc..1446783e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,10 +6,6 @@ on: - closed workflow_dispatch: -permissions: - contents: write - id-token: write # For publishing to npm using --provenance - env: NODE_VERSION: 18 From 8b17f96a3b503328eb8ae2bfb7db5d3b04dc1881 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 13 Dec 2023 15:52:19 +0100 Subject: [PATCH 3/3] Remove unused NODE_VERSION env --- .github/workflows/npm-release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml index 7d33b5ed..888c6795 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/npm-release.yml @@ -16,9 +16,6 @@ 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.