Skip to content

Commit

Permalink
Updated release process to be automated (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck authored Dec 12, 2023
1 parent c18c386 commit 4690dcd
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ runs:

- name: Build package
shell: bash
run: npm run build:prod
run: npm run build
30 changes: 30 additions & 0 deletions .github/actions/get-prerelease/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Return a boolean indicating if the version contains prerelease identifiers

#
# Returns a simple true/false boolean indicating whether the version indicates it's a prerelease or not.
#
# TODO: Remove once the common repo is public.
#

inputs:
version:
required: true

outputs:
prerelease:
value: ${{ steps.get_prerelease.outputs.PRERELEASE }}

runs:
using: composite

steps:
- id: get_prerelease
shell: bash
run: |
if [[ "${VERSION}" == *"beta"* || "${VERSION}" == *"alpha"* ]]; then
echo "PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
fi
env:
VERSION: ${{ inputs.version }}
38 changes: 38 additions & 0 deletions .github/actions/get-release-notes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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:
- 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 }}
REPO_NAME: ${{ inputs.repo_name }}
VERSION: ${{ inputs.version }}
21 changes: 21 additions & 0 deletions .github/actions/get-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Return the version extracted from the branch name

#
# Returns the version from the .version file.
#
# TODO: Remove once the common repo is public.
#

outputs:
version:
value: ${{ steps.get_version.outputs.VERSION }}

runs:
using: composite

steps:
- id: get_version
shell: bash
run: |
VERSION=$(head -1 .version)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
46 changes: 46 additions & 0 deletions .github/actions/publish-package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish release to package manager

inputs:
node-version:
required: true
npm-token:
required: true
version:
required: true
release-directory:
default: './'

runs:
using: composite

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Build package
uses: ./.github/actions/build
with:
node: ${{ inputs.node-version }}

- name: Publish release to NPM
shell: bash
working-directory: ${{ inputs.release-directory }}
run: |
if [[ "${VERSION}" == *"beta"* ]]; then
TAG="beta"
elif [[ "${VERSION}" == *"alpha"* ]]; then
TAG="alpha"
else
TAG="latest"
fi
npm publish --provenance --tag $TAG
env:
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
VERSION: ${{ inputs.version }}
47 changes: 47 additions & 0 deletions .github/actions/release-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create a GitHub release

#
# Creates a GitHub release with the given version.
#
# TODO: Remove once the common repo is public.
#

inputs:
token:
required: true
files:
required: false
name:
required: true
body:
required: true
tag:
required: true
commit:
required: true
draft:
default: false
required: false
prerelease:
default: false
required: false
fail_on_unmatched_files:
default: true
required: false

runs:
using: composite

steps:
- uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
body: ${{ inputs.body }}
name: ${{ inputs.name }}
tag_name: ${{ inputs.tag }}
target_commitish: ${{ inputs.commit }}
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}
fail_on_unmatched_files: ${{ inputs.fail_on_unmatched_files }}
files: ${{ inputs.files }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
36 changes: 36 additions & 0 deletions .github/actions/tag-exists/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Return a boolean indicating if a tag already exists for the repository

#
# Returns a simple true/false boolean indicating whether the tag exists or not.
#
# TODO: Remove once the common repo is public.
#

inputs:
token:
required: true
tag:
required: true

outputs:
exists:
description: 'Whether the tag exists or not'
value: ${{ steps.tag-exists.outputs.EXISTS }}

runs:
using: composite

steps:
- id: check
shell: bash
run: |
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s -H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo "EXISTS=true" >> $GITHUB_OUTPUT
else
echo "EXISTS=false" >> $GITHUB_OUTPUT
fi
env:
TAG_NAME: ${{ inputs.tag }}
GITHUB_TOKEN: ${{ inputs.token }}
78 changes: 78 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Create GitHub Release

on:
pull_request:
types:
- closed
workflow_dispatch:

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: ${{ env.NODE_VERSION }}
version: ${{ steps.get_version.outputs.version }}
npm-token: ${{ secrets.NPM_TOKEN }}
release-directory: './dist/auth0-angular'

# Create a release for the tag
- uses: ./.github/actions/release-create
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.get_version.outputs.version }}
body: ${{ env.RELEASE_NOTES }}
tag: ${{ steps.get_version.outputs.version }}
commit: ${{ github.sha }}
prerelease: ${{ steps.get_prerelease.outputs.prerelease }}
7 changes: 5 additions & 2 deletions .shiprc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"packagePath": "projects/auth0-angular",
"postbump": "npm run build"
}
"files": {
".version": []
},
"postbump": "npm run docs"
}
1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.2.1
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
"start:local:oidc": "node scripts/oidc-provider",
"start:local:playground": "ng serve --configuration=local",
"prebuild": "npm run update-useragent",
"build": "ng build && npm run build:schematics",
"build:prod": "ng build --configuration=production && npm run build:schematics",
"build:dev": "ng build && npm run build:schematics",
"build": "ng build --configuration=production && npm run build:schematics",
"build:schematics": "npm run build --prefix projects/auth0-angular",
"prepublishOnly": "node scripts/prepublish-stopper.js",
"postbuild": "npm run docs",
"postbuild": "cp README.md ./dist/auth0-angular/",
"test": "jest",
"test:ci": "jest --coverage --silent",
"e2e": "ng e2e",
Expand All @@ -21,7 +20,6 @@
"lint": "ng lint",
"docs": "typedoc",
"pretty-quick": "pretty-quick",
"release:publish": "node scripts/publish.js",
"update-useragent": "node projects/auth0-angular/scripts/update-useragent.js",
"server:api": "node api-server.js"
},
Expand Down
6 changes: 0 additions & 6 deletions scripts/prepublish-stopper.js

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/publish.js

This file was deleted.

0 comments on commit 4690dcd

Please sign in to comment.