Skip to content

Commit 4690dcd

Browse files
Updated release process to be automated (#547)
1 parent c18c386 commit 4690dcd

File tree

13 files changed

+306
-60
lines changed

13 files changed

+306
-60
lines changed

.github/actions/build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ runs:
2323

2424
- name: Build package
2525
shell: bash
26-
run: npm run build:prod
26+
run: npm run build
Lines changed: 30 additions & 0 deletions
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 }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Return the release notes extracted from the PR body
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+
runs:
19+
using: composite
20+
21+
steps:
22+
- uses: actions/github-script@v7
23+
id: get_release_notes
24+
with:
25+
result-encoding: string
26+
script: |
27+
const { data: pulls } = await github.rest.pulls.list({
28+
owner: process.env.REPO_OWNER,
29+
repo: process.env.REPO_NAME,
30+
state: 'all',
31+
head: `${process.env.REPO_OWNER}:release/${process.env.VERSION}`,
32+
});
33+
core.exportVariable('RELEASE_NOTES', pulls[0].body)
34+
env:
35+
GITHUB_TOKEN: ${{ inputs.token }}
36+
REPO_OWNER: ${{ inputs.repo_owner }}
37+
REPO_NAME: ${{ inputs.repo_name }}
38+
VERSION: ${{ inputs.version }}
Lines changed: 21 additions & 0 deletions
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
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish release to package manager
2+
3+
inputs:
4+
node-version:
5+
required: true
6+
npm-token:
7+
required: true
8+
version:
9+
required: true
10+
release-directory:
11+
default: './'
12+
13+
runs:
14+
using: composite
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ inputs.node-version }}
24+
cache: 'npm'
25+
registry-url: 'https://registry.npmjs.org'
26+
27+
- name: Build package
28+
uses: ./.github/actions/build
29+
with:
30+
node: ${{ inputs.node-version }}
31+
32+
- name: Publish release to NPM
33+
shell: bash
34+
working-directory: ${{ inputs.release-directory }}
35+
run: |
36+
if [[ "${VERSION}" == *"beta"* ]]; then
37+
TAG="beta"
38+
elif [[ "${VERSION}" == *"alpha"* ]]; then
39+
TAG="alpha"
40+
else
41+
TAG="latest"
42+
fi
43+
npm publish --provenance --tag $TAG
44+
env:
45+
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
46+
VERSION: ${{ inputs.version }}
Lines changed: 47 additions & 0 deletions
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 }}
Lines changed: 36 additions & 0 deletions
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: check
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/release.yml

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

.shiprc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"packagePath": "projects/auth0-angular",
3-
"postbump": "npm run build"
4-
}
3+
"files": {
4+
".version": []
5+
},
6+
"postbump": "npm run docs"
7+
}

.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v2.2.1

0 commit comments

Comments
 (0)