Skip to content

Commit d12c170

Browse files
fix: triggering the automated release on staging
chore: setup automated android release workflow
2 parents de41632 + 1778039 commit d12c170

File tree

8 files changed

+291
-4
lines changed

8 files changed

+291
-4
lines changed

.github/workflows/publish.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Publish Release
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- master
9+
- staging
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
publish-release:
16+
name: Create GitHub Release
17+
runs-on: ubuntu-latest
18+
# Run only if merged AND has 'release' label
19+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
24+
- name: Create Release and Tag
25+
id: create_release
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
# 1. Extract Version
30+
VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2)
31+
32+
if [ -z "$VERSION" ]; then
33+
echo "Error: Could not detect version from gradle.properties."
34+
exit 1
35+
fi
36+
37+
echo "Detected Version: $VERSION"
38+
TAG_NAME="v$VERSION"
39+
40+
# Output for next steps
41+
echo "version=$VERSION" >> $GITHUB_OUTPUT
42+
43+
# 2. Create the GitHub Release
44+
gh release create "$TAG_NAME" \
45+
--title "$TAG_NAME" \
46+
--notes "Automated release for version $TAG_NAME. See CHANGELOG.md for details." \
47+
--target ${{ github.base_ref }}
48+
49+
- name: Delete release branch
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
VERSION="${{ steps.create_release.outputs.version }}"
54+
RELEASE_BRANCH="release/${VERSION}"
55+
56+
# Check if branch exists before deleting
57+
if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
58+
echo "Deleting release branch: $RELEASE_BRANCH"
59+
git push origin --delete "$RELEASE_BRANCH"
60+
else
61+
echo "Release branch $RELEASE_BRANCH already deleted."
62+
fi

.github/workflows/release.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Version Bump PR
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- staging
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
version-bump:
16+
name: Prepare Release Branch
17+
runs-on: ubuntu-latest
18+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
19+
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '20'
34+
35+
- name: Install dependencies
36+
run: npm install -g semantic-release @semantic-release/exec @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits
37+
38+
- name: Configure Git
39+
run: |
40+
git config user.name "github-actions[bot]"
41+
git config user.email "github-actions[bot]@users.noreply.github.com"
42+
43+
- name: Extract current version
44+
id: current_version
45+
run: |
46+
# Read version from gradle.properties
47+
CURRENT_VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2)
48+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
49+
echo "Current version: $CURRENT_VERSION"
50+
51+
- name: Get next version
52+
id: get_version
53+
run: |
54+
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
55+
56+
# Run dry-run
57+
npx semantic-release --dry-run --no-ci > semantic-output.txt 2>&1 || true
58+
59+
# Parse output
60+
NEXT_VERSION=$(grep "The next release version is" semantic-output.txt | sed -E 's/.*The next release version is ([0-9]+\.[0-9]+\.[0-9]+).*/\1/' | head -1)
61+
62+
if [ -z "$NEXT_VERSION" ]; then
63+
echo "::notice::No new version needed."
64+
echo "should_create_pr=false" >> $GITHUB_OUTPUT
65+
exit 0
66+
fi
67+
68+
if [ "$NEXT_VERSION" = "$CURRENT_VERSION" ]; then
69+
echo "::notice::Version already matches."
70+
echo "should_create_pr=false" >> $GITHUB_OUTPUT
71+
exit 0
72+
fi
73+
74+
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
75+
echo "should_create_pr=true" >> $GITHUB_OUTPUT
76+
echo "release_branch=release/${NEXT_VERSION}" >> $GITHUB_OUTPUT
77+
echo "::notice::Bumping version: $CURRENT_VERSION -> $NEXT_VERSION"
78+
79+
- name: Check if release branch exists
80+
if: steps.get_version.outputs.should_create_pr == 'true'
81+
id: check_branch
82+
run: |
83+
RELEASE_BRANCH="${{ steps.get_version.outputs.release_branch }}"
84+
if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
85+
echo "branch_exists=true" >> $GITHUB_OUTPUT
86+
exit 0
87+
fi
88+
echo "branch_exists=false" >> $GITHUB_OUTPUT
89+
90+
- name: Create release branch
91+
if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
92+
run: |
93+
BRANCH_NAME="${{ steps.get_version.outputs.release_branch }}"
94+
git checkout -b "$BRANCH_NAME"
95+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
96+
97+
- name: Update Gradle version
98+
if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
99+
run: |
100+
VERSION="${{ steps.get_version.outputs.next_version }}"
101+
102+
echo "Running bump_version.sh..."
103+
chmod +x ./scripts/bump_version.sh
104+
./scripts/bump_version.sh "$VERSION"
105+
106+
grep "^GLOBAL_VERSION_NAME=" gradle.properties
107+
108+
- name: Generate Changelog
109+
if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
110+
run: |
111+
npx semantic-release --no-ci 2>&1 | tee release-output.txt || true
112+
113+
- name: Commit changes
114+
if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
115+
run: |
116+
VERSION="${{ steps.get_version.outputs.next_version }}"
117+
118+
git add gradle.properties CHANGELOG.md
119+
git commit -m "chore(release): prepare version ${VERSION}"
120+
echo "Committed version bump and changelog."
121+
122+
- name: Push and Create PR
123+
if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
124+
run: |
125+
VERSION="${{ steps.get_version.outputs.next_version }}"
126+
BRANCH_NAME="${{ env.branch_name }}"
127+
BASE_BRANCH="${{ github.ref_name }}"
128+
129+
git push origin "$BRANCH_NAME"
130+
131+
if [ -f CHANGELOG.md ]; then
132+
CHANGELOG_EXCERPT=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$ d' || echo "See CHANGELOG.md")
133+
else
134+
CHANGELOG_EXCERPT="See CHANGELOG.md for details"
135+
fi
136+
137+
# We construct the body string first to avoid multiline string issues in the CLI command
138+
PR_BODY="Automated release PR
139+
140+
**Version:** \`$VERSION\`
141+
142+
## Changes
143+
$CHANGELOG_EXCERPT
144+
145+
---
146+
*Merge this PR to publish the release.*"
147+
148+
gh pr create \
149+
--base "$BASE_BRANCH" \
150+
--head "$BRANCH_NAME" \
151+
--title "chore(release): $VERSION" \
152+
--body "$PR_BODY"
153+
154+
# Add release label
155+
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --base "$BASE_BRANCH" --json number --jq '.[0].number')
156+
gh pr edit "$PR_NUMBER" --add-label "release"

.releaserc.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"branches": ["master"],
3+
"plugins": [
4+
[
5+
"@semantic-release/commit-analyzer",
6+
{
7+
"preset": "angular",
8+
"releaseRules": [
9+
{"breaking": true, "release": "major"},
10+
{"type": "feat", "release": "minor"},
11+
{"type": "fix", "release": "patch"},
12+
{"type": "perf", "release": "patch"},
13+
{"type": "revert", "release": "patch"},
14+
{"type": "docs", "release": false},
15+
{"type": "chore", "release": false},
16+
{"type": "refactor", "release": false},
17+
{"type": "style", "release": false}
18+
]
19+
}
20+
],
21+
[
22+
"@semantic-release/release-notes-generator",
23+
{
24+
"preset": "conventionalcommits",
25+
"presetConfig": {
26+
"types": [
27+
{"type": "feat", "section": "Features"},
28+
{"type": "fix", "section": "Bug Fixes"},
29+
{"type": "perf", "section": "Performance Improvements"},
30+
{"type": "revert", "section": "Reverts"}
31+
]
32+
}
33+
}
34+
],
35+
[
36+
"@semantic-release/changelog",
37+
{
38+
"changelogFile": "CHANGELOG.md"
39+
}
40+
],
41+
[
42+
"@semantic-release/exec",
43+
{
44+
"prepareCmd": "./scripts/bump_version.sh ${nextRelease.version}"
45+
}
46+
]
47+
]
48+
}

NRExoPlayerTracker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 6
11-
versionName "4.0.3"
11+
versionName GLOBAL_VERSION_NAME
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

NRIMATracker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 6
11-
versionName "4.0.3"
11+
versionName GLOBAL_VERSION_NAME
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

NewRelicVideoCore/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 9
11-
versionName "4.0.3"
11+
versionName GLOBAL_VERSION_NAME
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020
android.defaults.buildfeatures.buildconfig=true
2121
android.nonTransitiveRClass=false
22-
android.nonFinalResIds=false
22+
android.nonFinalResIds=false
23+
24+
GLOBAL_VERSION_NAME=4.0.3

scripts/bump_version.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Get the new version passed from semantic-release
4+
NEW_VERSION=$1
5+
6+
if [ -z "$NEW_VERSION" ]; then
7+
echo "Error: No version argument provided."
8+
exit 1
9+
fi
10+
11+
echo "Bumping version to $NEW_VERSION in gradle.properties..."
12+
13+
# Use sed to find the line starting with GLOBAL_VERSION_NAME and replace it
14+
sed -i.bak "s/^GLOBAL_VERSION_NAME=.*/GLOBAL_VERSION_NAME=$NEW_VERSION/" gradle.properties
15+
16+
# Remove the backup file created by sed
17+
rm -f gradle.properties.bak
18+
19+
echo "Successfully updated gradle.properties to $NEW_VERSION"

0 commit comments

Comments
 (0)