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"
0 commit comments