Skip to content

Commit c2a45f4

Browse files
committed
ci: Update Workflows
1 parent ac12090 commit c2a45f4

File tree

7 files changed

+268
-0
lines changed

7 files changed

+268
-0
lines changed

Diff for: .github/actions/get-prerelease/action.yml

+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 }}

Diff for: .github/actions/get-version/action.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Return the version extracted from the branch name
2+
3+
#
4+
# Returns the version from a branch name of a pull request. 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+
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=$(echo ${BRANCH_NAME} | sed -r 's#release/+##g')
21+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
22+
env:
23+
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}

Diff for: .github/actions/publish-package/action.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish release to package manager
2+
3+
inputs:
4+
token:
5+
required: true
6+
files:
7+
required: false
8+
name:
9+
required: true
10+
body:
11+
required: true
12+
tag:
13+
required: true
14+
commit:
15+
required: true
16+
draft:
17+
default: false
18+
required: false
19+
prerelease:
20+
default: false
21+
required: false
22+
23+
runs:
24+
using: composite
25+
26+
steps:
27+
# Nothing to do for PHP.
28+
- run: exit 0
29+
shell: bash

Diff for: .github/actions/release-create/action.yml

+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 }}

Diff for: .github/actions/tag-create/action.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Create a repository tag
2+
3+
#
4+
# Creates a tag with the given version.
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+
runs:
16+
using: composite
17+
18+
steps:
19+
- shell: bash
20+
run: |
21+
git config user.name "${AUTHOR_USERNAME}"
22+
git config user.email "${AUTHOR_EMAIL}"
23+
env:
24+
AUTHOR_USERNAME: ${{ github.event.pull_request.user.login }}
25+
AUTHOR_EMAIL: ${{ github.event.pull_request.user.email }}
26+
27+
- shell: bash
28+
run: |
29+
git tag -a ${TAG_NAME} -m "Version ${TAG_NAME}"
30+
git push --follow-tags
31+
env:
32+
TAG_NAME: ${{ inputs.tag }}
33+
GITHUB_TOKEN: ${{ inputs.token }}

Diff for: .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: 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 }}

Diff for: .github/workflows/release.yml

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

0 commit comments

Comments
 (0)