Skip to content

Commit 94475c6

Browse files
committed
feat: add beta release workflow for JitPack from stable-beta branch
1 parent 8dcadd0 commit 94475c6

File tree

3 files changed

+299
-0
lines changed

3 files changed

+299
-0
lines changed

.github/workflows/beta-publish.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Publish Beta Release
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- stable-beta
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
publish-beta-release:
15+
name: Create GitHub Beta Release
16+
runs-on: ubuntu-latest
17+
# Run only if merged AND has 'beta-release' label
18+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'beta-release')
19+
steps:
20+
- name: Checkout Code
21+
uses: actions/checkout@v4
22+
23+
- name: Create Beta Release and Tag
24+
id: create_release
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
run: |
28+
# 1. Extract Version
29+
VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2)
30+
31+
if [ -z "$VERSION" ]; then
32+
echo "Error: Could not detect version from gradle.properties."
33+
exit 1
34+
fi
35+
36+
echo "Detected Beta Version: $VERSION"
37+
TAG_NAME="v$VERSION"
38+
39+
# 2. Extract Changelog for this version
40+
# We initialize NOTES as empty
41+
NOTES=""
42+
43+
if [ -f CHANGELOG.md ]; then
44+
echo "CHANGELOG.md found. Extracting notes for $VERSION..."
45+
# This command extracts the text between the current version header and the next one
46+
NOTES=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$ d')
47+
else
48+
echo "Warning: CHANGELOG.md not found."
49+
fi
50+
51+
# Add JitPack usage instructions to notes
52+
JITPACK_USAGE="
53+
54+
### 📦 JitPack Usage
55+
\`\`\`gradle
56+
dependencies {
57+
implementation 'com.github.newrelic.NewRelicVideoCore:$VERSION'
58+
implementation 'com.github.newrelic.NRExoPlayerTracker:$VERSION'
59+
implementation 'com.github.newrelic.NRIMATracker:$VERSION'
60+
}
61+
\`\`\`"
62+
63+
FULL_NOTES="$NOTES$JITPACK_USAGE"
64+
65+
# 3. Log extracted notes
66+
echo "Extracted notes:"
67+
echo "$FULL_NOTES"
68+
69+
# 4. Create the GitHub Release AND Tag as pre-release
70+
# We use the extracted "$FULL_NOTES" here and mark as pre-release
71+
gh release create "$TAG_NAME" \
72+
--title "🚀 Beta Release $TAG_NAME" \
73+
--notes "$FULL_NOTES" \
74+
--prerelease \
75+
--target ${{ github.base_ref }}
76+
77+
echo "✅ Beta release created: $TAG_NAME"
78+
echo "🎯 JitPack will automatically detect and build this beta release"

.github/workflows/beta-release.yml

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

scripts/check_beta_version.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Script to check current beta version generation
4+
# Usage: ./scripts/check_beta_version.sh
5+
6+
set -e
7+
8+
echo "🔍 Checking Beta Version Generation"
9+
echo "=================================="
10+
11+
# Get current branch
12+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
13+
echo "Current branch: $CURRENT_BRANCH"
14+
15+
# Get base version
16+
BASE_VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2)
17+
echo "Base version: $BASE_VERSION"
18+
19+
# Show what version would be generated
20+
echo ""
21+
echo "📦 Generated Versions:"
22+
if [ "$CURRENT_BRANCH" = "stable-beta" ]; then
23+
TIMESTAMP=$(date +"%Y%m%d%H%M")
24+
BETA_VERSION="${BASE_VERSION}-beta.${TIMESTAMP}"
25+
echo " Beta version: $BETA_VERSION"
26+
echo " JitPack usage: com.github.newrelic.[module]:${BETA_VERSION}"
27+
else
28+
echo " Regular version: $BASE_VERSION"
29+
echo " JitPack usage: com.github.newrelic.[module]:${BASE_VERSION}"
30+
fi
31+
32+
echo ""
33+
echo "✅ Version check complete!"
34+
35+
if [ "$CURRENT_BRANCH" = "stable-beta" ]; then
36+
echo ""
37+
echo "💡 Tips for beta releases:"
38+
echo " - Merge PR to stable-beta to trigger beta release"
39+
echo " - Beta versions include timestamp for uniqueness"
40+
echo " - Beta releases are marked as 'pre-release' on GitHub"
41+
fi

0 commit comments

Comments
 (0)