Skip to content

Commit 1f3964e

Browse files
Update automated release process to latest version (auth0#1611)
1 parent dc66422 commit 1f3964e

File tree

11 files changed

+339
-111
lines changed

11 files changed

+339
-111
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Return a boolean indicating if the version contains prerelease identifiers
2+
3+
#
4+
# Returns a simple true/false boolean indicating whether the version indicates it's a prerelease or not.
5+
#
6+
# TODO: Remove once the common repo is public.
7+
#
8+
9+
inputs:
10+
version:
11+
required: true
12+
13+
outputs:
14+
prerelease:
15+
value: ${{ steps.get_prerelease.outputs.PRERELEASE }}
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- id: get_prerelease
22+
shell: bash
23+
run: |
24+
if [[ "${VERSION}" == *"beta"* || "${VERSION}" == *"alpha"* ]]; then
25+
echo "PRERELEASE=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
28+
fi
29+
env:
30+
VERSION: ${{ inputs.version }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Return the release notes extracted from the body of the PR associated with the release.
2+
3+
#
4+
# 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.
5+
#
6+
# TODO: Remove once the common repo is public.
7+
#
8+
inputs:
9+
version:
10+
required: true
11+
repo_name:
12+
required: false
13+
repo_owner:
14+
required: true
15+
token:
16+
required: true
17+
18+
outputs:
19+
release-notes:
20+
value: ${{ steps.get_release_notes.outputs.RELEASE_NOTES }}
21+
22+
runs:
23+
using: composite
24+
25+
steps:
26+
- uses: actions/github-script@v7
27+
id: get_release_notes
28+
with:
29+
result-encoding: string
30+
script: |
31+
const { data: pulls } = await github.rest.pulls.list({
32+
owner: process.env.REPO_OWNER,
33+
repo: process.env.REPO_NAME,
34+
state: 'all',
35+
head: `${process.env.REPO_OWNER}:release/${process.env.VERSION}`,
36+
});
37+
core.setOutput('RELEASE_NOTES', pulls[0].body);
38+
env:
39+
GITHUB_TOKEN: ${{ inputs.token }}
40+
REPO_OWNER: ${{ inputs.repo_owner }}
41+
REPO_NAME: ${{ inputs.repo_name }}
42+
VERSION: ${{ inputs.version }}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Return the version extracted from the branch name
2+
3+
#
4+
# Returns the version from the .version file.
5+
#
6+
# TODO: Remove once the common repo is public.
7+
#
8+
9+
outputs:
10+
version:
11+
value: ${{ steps.get_version.outputs.VERSION }}
12+
13+
runs:
14+
using: composite
15+
16+
steps:
17+
- id: get_version
18+
shell: bash
19+
run: |
20+
VERSION=$(head -1 .version)
21+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Publish release to npm
2+
3+
inputs:
4+
node-version:
5+
required: true
6+
npm-token:
7+
required: true
8+
version:
9+
required: true
10+
require-build:
11+
default: true
12+
release-directory:
13+
default: './'
14+
15+
runs:
16+
using: composite
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ inputs.node-version }}
26+
cache: 'npm'
27+
registry-url: 'https://registry.npmjs.org'
28+
29+
- name: Install dependencies
30+
shell: bash
31+
run: npm ci --include=dev
32+
33+
- name: Build package
34+
if: inputs.require-build == 'true'
35+
shell: bash
36+
run: npm run build
37+
38+
- name: Publish release to NPM
39+
shell: bash
40+
working-directory: ${{ inputs.release-directory }}
41+
run: |
42+
if [[ "${VERSION}" == *"beta"* ]]; then
43+
TAG="beta"
44+
elif [[ "${VERSION}" == *"alpha"* ]]; then
45+
TAG="alpha"
46+
else
47+
TAG="latest"
48+
fi
49+
npm publish --provenance --tag $TAG
50+
env:
51+
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
52+
VERSION: ${{ inputs.version }}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create a GitHub release
2+
3+
#
4+
# Creates a GitHub release with the given version.
5+
#
6+
# TODO: Remove once the common repo is public.
7+
#
8+
9+
inputs:
10+
token:
11+
required: true
12+
files:
13+
required: false
14+
name:
15+
required: true
16+
body:
17+
required: true
18+
tag:
19+
required: true
20+
commit:
21+
required: true
22+
draft:
23+
default: false
24+
required: false
25+
prerelease:
26+
default: false
27+
required: false
28+
fail_on_unmatched_files:
29+
default: true
30+
required: false
31+
32+
runs:
33+
using: composite
34+
35+
steps:
36+
- uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
37+
with:
38+
body: ${{ inputs.body }}
39+
name: ${{ inputs.name }}
40+
tag_name: ${{ inputs.tag }}
41+
target_commitish: ${{ inputs.commit }}
42+
draft: ${{ inputs.draft }}
43+
prerelease: ${{ inputs.prerelease }}
44+
fail_on_unmatched_files: ${{ inputs.fail_on_unmatched_files }}
45+
files: ${{ inputs.files }}
46+
env:
47+
GITHUB_TOKEN: ${{ inputs.token }}

.github/actions/tag-exists/action.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Return a boolean indicating if a tag already exists for the repository
2+
3+
#
4+
# Returns a simple true/false boolean indicating whether the tag exists or not.
5+
#
6+
# TODO: Remove once the common repo is public.
7+
#
8+
9+
inputs:
10+
token:
11+
required: true
12+
tag:
13+
required: true
14+
15+
outputs:
16+
exists:
17+
description: 'Whether the tag exists or not'
18+
value: ${{ steps.tag-exists.outputs.EXISTS }}
19+
20+
runs:
21+
using: composite
22+
23+
steps:
24+
- id: tag-exists
25+
shell: bash
26+
run: |
27+
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}"
28+
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s -H "Authorization: token ${GITHUB_TOKEN}")
29+
if [ "$http_status_code" -ne "404" ] ; then
30+
echo "EXISTS=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "EXISTS=false" >> $GITHUB_OUTPUT
33+
fi
34+
env:
35+
TAG_NAME: ${{ inputs.tag }}
36+
GITHUB_TOKEN: ${{ inputs.token }}

.github/workflows/npm-release.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Create npm and GitHub Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-version:
7+
required: true
8+
type: string
9+
require-build:
10+
default: true
11+
type: string
12+
release-directory:
13+
default: './'
14+
type: string
15+
secrets:
16+
github-token:
17+
required: true
18+
npm-token:
19+
required: true
20+
21+
### TODO: Replace instances of './.github/actions/' w/ `auth0/dx-sdk-actions/` and append `@latest` after the common `dx-sdk-actions` repo is made public.
22+
### 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.
23+
24+
jobs:
25+
release:
26+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/'))
27+
runs-on: ubuntu-latest
28+
environment: release
29+
30+
steps:
31+
# Checkout the code
32+
- uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
# Get the version from the branch name
37+
- id: get_version
38+
uses: ./.github/actions/get-version
39+
40+
# Get the prerelease flag from the branch name
41+
- id: get_prerelease
42+
uses: ./.github/actions/get-prerelease
43+
with:
44+
version: ${{ steps.get_version.outputs.version }}
45+
46+
# Get the release notes
47+
- id: get_release_notes
48+
uses: ./.github/actions/get-release-notes
49+
with:
50+
token: ${{ secrets.github-token }}
51+
version: ${{ steps.get_version.outputs.version }}
52+
repo_owner: ${{ github.repository_owner }}
53+
repo_name: ${{ github.event.repository.name }}
54+
55+
# Check if the tag already exists
56+
- id: tag_exists
57+
uses: ./.github/actions/tag-exists
58+
with:
59+
tag: ${{ steps.get_version.outputs.version }}
60+
token: ${{ secrets.github-token }}
61+
62+
# If the tag already exists, exit with an error
63+
- if: steps.tag_exists.outputs.exists == 'true'
64+
run: exit 1
65+
66+
# Publish the release to npm
67+
- uses: ./.github/actions/npm-publish
68+
with:
69+
node-version: ${{ inputs.node-version }}
70+
require-build: ${{ inputs.require-build }}
71+
release-directory: ${{ inputs.release-directory }}
72+
version: ${{ steps.get_version.outputs.version }}
73+
npm-token: ${{ secrets.npm-token }}
74+
75+
# Create a release for the tag
76+
- uses: ./.github/actions/release-create
77+
with:
78+
token: ${{ secrets.github-token }}
79+
name: ${{ steps.get_version.outputs.version }}
80+
body: ${{ steps.get_release_notes.outputs.release-notes }}
81+
tag: ${{ steps.get_version.outputs.version }}
82+
commit: ${{ github.sha }}
83+
prerelease: ${{ steps.get_prerelease.outputs.prerelease }}

0 commit comments

Comments
 (0)