Skip to content

Commit 0c76c94

Browse files
poovamrajtanya732
authored andcommitted
Automate release workflow
1 parent fb6d00a commit 0c76c94

File tree

9 files changed

+343
-8
lines changed

9 files changed

+343
-8
lines changed
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: 42 additions & 0 deletions
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 }}
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish release to Java
2+
3+
inputs:
4+
ossr-username:
5+
required: true
6+
ossr-password:
7+
required: true
8+
signing-key:
9+
required: true
10+
signing-password:
11+
required: true
12+
java-version:
13+
required: true
14+
is-android:
15+
required: true
16+
version:
17+
required: true
18+
19+
runs:
20+
using: composite
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Java
27+
shell: bash
28+
run: |
29+
curl -s "https://get.sdkman.io" | bash
30+
source "/home/runner/.sdkman/bin/sdkman-init.sh"
31+
sdk list java
32+
sdk install java ${{ inputs.java-version }} && sdk default java ${{ inputs.java-version }}
33+
34+
- uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # pin@1.1.0
35+
36+
- name: Publish Java
37+
shell: bash
38+
if: inputs.is-android == 'false'
39+
run: ./gradlew clean assemble sign publishMavenJavaPublicationToMavenRepository -PisSnapshot=false -Pversion="${{ inputs.version }}" -PossrhUsername="${{ inputs.ossr-username }}" -PossrhPassword="${{ inputs.ossr-password }}" -PsigningKey="${{ inputs.signing-key }}" -PsigningPassword="${{ inputs.signing-password }}"
40+
41+
- name: Publish Android
42+
shell: bash
43+
if: inputs.is-android == 'true'
44+
run: ./gradlew clean assemble sign publishAndroidLibraryPublicationToMavenRepository -PisSnapshot=false -Pversion="${{ inputs.version }}" -PossrhUsername="${{ inputs.ossr-username }}" -PossrhPassword="${{ inputs.ossr-password }}" -PsigningKey="${{ inputs.signing-key }}" -PsigningPassword="${{ inputs.signing-password }}"
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 }}

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

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: 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/java-release.yml

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

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
12+
### TODO: Replace instances of './.github/workflows/' w/ `auth0/dx-sdk-actions/workflows/` and append `@latest` after the common `dx-sdk-actions` repo is made public.
13+
### TODO: Also remove `get-prerelease`, `get-release-notes`, `get-version`, `maven-publish`, `release-create`, and `tag-exists` actions from this repo's .github/actions folder once the repo is public.
14+
### TODO: Also remove `java-release` workflow from this repo's .github/workflows folder once the repo is public.
15+
16+
jobs:
17+
release:
18+
uses: ./.github/workflows/java-release.yml
19+
with:
20+
java-version: 8.0.382-tem
21+
is-android: false
22+
secrets:
23+
ossr-username: ${{ secrets.OSSR_USERNAME }}
24+
ossr-password: ${{ secrets.OSSR_PASSWORD }}
25+
signing-key: ${{ secrets.SIGNING_KEY }}
26+
signing-password: ${{ secrets.SIGNING_PASSWORD }}
27+
github-token: ${{ secrets.GITHUB_TOKEN }}

lib/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ tasks.named("checkstyleJmh").configure({
3131

3232
logger.lifecycle("Using version ${version} for ${group}.${name}")
3333

34+
def signingKey = findProperty('signingKey')
35+
def signingKeyPwd = findProperty('signingPassword')
36+
3437
oss {
3538
name "java jwt"
3639
repository "java-jwt"
3740
organization "auth0"
3841
description "Java implementation of JSON Web Token (JWT)"
3942
baselineCompareVersion "4.1.0"
43+
skipAssertSigningConfiguration true
4044

4145
developers {
4246
auth0 {
@@ -54,6 +58,10 @@ oss {
5458
}
5559
}
5660

61+
signing {
62+
useInMemoryPgpKeys(signingKey, signingKeyPwd)
63+
}
64+
5765
java {
5866
toolchain {
5967
languageVersion = JavaLanguageVersion.of(11)
@@ -158,14 +166,6 @@ jar {
158166
compileModuleInfoJava.dependsOn compileJava
159167
classes.dependsOn compileModuleInfoJava
160168

161-
// Creates a version.txt file containing the current version of the SDK.
162-
// This file is picked up and parsed by our Ship Orb to determine the version.
163-
task exportVersion() {
164-
doLast {
165-
new File(rootDir, "version.txt").text = "$version"
166-
}
167-
}
168-
169169
// you can pass any arguments JMH accepts via Gradle args.
170170
// Example: ./gradlew runJMH --args="-lrf"
171171
tasks.register('runJMH', JavaExec) {

0 commit comments

Comments
 (0)