Skip to content

Commit 9010ccc

Browse files
ci: automate release process using semantic-release
1 parent e820114 commit 9010ccc

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

.github/workflows/publish-android.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Publish Native Android Library
22

3-
on: workflow_dispatch
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version being released"
8+
required: false
49

510
jobs:
611
publish-android:

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- ci/RMET-3995/automate-releases
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # needed for semantic-release
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
24+
- name: Install Semantic Release and plugins
25+
run: |
26+
npm install -g semantic-release \
27+
@semantic-release/git \
28+
@semantic-release/changelog \
29+
@semantic-release/exec \
30+
@semantic-release/github \
31+
@semantic-release/commit-analyzer \
32+
@semantic-release/release-notes-generator
33+
34+
- name: Run Semantic Release
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: semantic-release

.releaserc.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
tagFormat: '${version}',
3+
branches: [
4+
"main",
5+
"ci/RMET-3995/automate-releases",
6+
],
7+
plugins: [
8+
"@semantic-release/commit-analyzer",
9+
"@semantic-release/release-notes-generator",
10+
[
11+
"@semantic-release/changelog",
12+
{
13+
changelogFile: "CHANGELOG.md",
14+
},
15+
],
16+
[
17+
"@semantic-release/exec",
18+
{
19+
// Step 1: bump version in pom.xml
20+
prepareCmd: `
21+
echo "Updating pom.xml version to \${nextRelease.version}"
22+
sed -i'' -e 's#<version>.*</version>#<version>\${nextRelease.version}</version>#' pom.xml
23+
`,
24+
// Step 2: trigger publish workflow after release is done
25+
successCmd: `
26+
echo "Triggering publish-android.yml workflow..."
27+
curl -X POST \
28+
-H "Accept: application/vnd.github+json" \
29+
-H "Authorization: Bearer $GITHUB_TOKEN" \
30+
https://api.github.com/repos/ionic-team/ion-android-geolocation/actions/workflows/publish-android.yml/dispatches \
31+
-d '{"ref": "main", "inputs": {"version": "\${nextRelease.version}"}}'
32+
`,
33+
},
34+
],
35+
[
36+
"@semantic-release/git",
37+
{
38+
assets: ["CHANGELOG.md", "pom.xml"],
39+
message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
40+
},
41+
],
42+
"@semantic-release/github",
43+
],
44+
};

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "ion-android-geolocation",
3+
"private": true,
4+
"devDependencies": {
5+
"semantic-release": "^25.0.1",
6+
"@semantic-release/changelog": "^6.0.3",
7+
"@semantic-release/git": "^10.0.1",
8+
"@semantic-release/commit-analyzer": "^13.0.0",
9+
"@semantic-release/release-notes-generator": "^14.0.1",
10+
"@semantic-release/exec": "^6.0.3",
11+
"@semantic-release/github": "^10.0.3"
12+
}
13+
}

scripts/publish-android.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else
2121

2222
printf %"s\n" "Attempting to build and publish version $THE_VERSION"
2323
# Publish a release to the Maven repo
24-
"$ANDROID_PATH"/gradlew clean build publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository --no-daemon --max-workers 1 -b "$ANDROID_PATH"/build.gradle -Pandroid.useAndroidX=true > $LOG_OUTPUT 2>&1
24+
# "$ANDROID_PATH"/gradlew clean build publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository --no-daemon --max-workers 1 -b "$ANDROID_PATH"/build.gradle -Pandroid.useAndroidX=true > $LOG_OUTPUT 2>&1
2525
# Stage a version
2626
# "$ANDROID_PATH"/gradlew clean build publishReleasePublicationToSonatypeRepository --no-daemon --max-workers 1 -b "$ANDROID_PATH"/build.gradle -Pandroid.useAndroidX=true > $LOG_OUTPUT 2>&1
2727

0 commit comments

Comments
 (0)