Skip to content

Commit bbe6146

Browse files
committed
Move to automated relase workflow
1 parent 7e82ef6 commit bbe6146

File tree

8 files changed

+226
-4
lines changed

8 files changed

+226
-4
lines changed
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 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+
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 }}
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
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 }}
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/publish.yml

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
name: Publish Release
22

33
on:
4-
workflow_dispatch:
5-
release:
4+
pull_request:
65
types:
7-
- published
6+
- closed
7+
workflow_dispatch:
8+
9+
### TODO: Replace instances of './.github/actions/' with reference to the `dx-sdk-actions` repo is made public and this file is transferred over
10+
### 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.
811

912
permissions:
1013
contents: read
1114
id-token: write # Required for trusted publishing to PyPI
1215

1316
jobs:
1417
publish-pypi:
18+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/'))
1519
name: "PyPI"
1620
runs-on: ubuntu-latest
1721
environment: release
@@ -22,6 +26,37 @@ jobs:
2226
with:
2327
fetch-depth: 0
2428
fetch-tags: true
29+
30+
# Get the version from the branch name
31+
- id: get_version
32+
uses: ./.github/actions/get-version
33+
34+
# Get the prerelease flag from the branch name
35+
- id: get_prerelease
36+
uses: ./.github/actions/get-prerelease
37+
with:
38+
version: ${{ steps.get_version.outputs.version }}
39+
40+
# Get the release notes
41+
# This will expose the release notes as env.RELEASE_NOTES
42+
- id: get_release_notes
43+
uses: ./.github/actions/get-release-notes
44+
with:
45+
token: ${{ secrets.github-token }}
46+
version: ${{ steps.get_version.outputs.version }}
47+
repo_owner: ${{ github.repository_owner }}
48+
repo_name: ${{ github.event.repository.name }}
49+
50+
# Check if the tag already exists
51+
- id: tag_exists
52+
uses: ./.github/actions/tag-exists
53+
with:
54+
tag: ${{ steps.get_version.outputs.version }}
55+
token: ${{ secrets.github-token }}
56+
57+
# If the tag already exists, exit with an error
58+
- if: steps.tag_exists.outputs.exists == 'true'
59+
run: exit 1
2560

2661
- name: Configure Python
2762
uses: actions/setup-python@v5
@@ -44,3 +79,13 @@ jobs:
4479
4580
- name: Publish release
4681
uses: pypa/gh-action-pypi-publish@release/v1
82+
83+
# Create a release for the tag
84+
- uses: ./.github/actions/release-create
85+
with:
86+
token: ${{ secrets.github-token }}
87+
name: ${{ steps.get_version.outputs.version }}
88+
body: ${{ steps.get_release_notes.outputs.release-notes }}
89+
tag: ${{ steps.get_version.outputs.version }}
90+
commit: ${{ github.sha }}
91+
prerelease: ${{ steps.get_prerelease.outputs.prerelease }}

.shiprc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": {
3-
"auth0/__init__.py": []
3+
".version": []
44
},
55
"prefixVersion": false
66
}

.version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.7.0

0 commit comments

Comments
 (0)