Merge remote-tracking branch 'origin/stable-beta' into stable-beta #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Beta Version Bump PR | |
| on: | |
| push: | |
| branches: | |
| - stable-beta | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| beta-version-bump: | |
| name: Prepare Beta Release Branch | |
| runs-on: ubuntu-latest | |
| if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: npm install -g semantic-release @semantic-release/exec @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits conventional-changelog-cli | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Extract current version | |
| id: current_version | |
| run: | | |
| # Read version from gradle.properties | |
| CURRENT_VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2) | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Get next beta version | |
| id: get_version | |
| run: | | |
| CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}" | |
| # Run semantic-release dry-run to determine bump type | |
| npx semantic-release --dry-run --no-ci > semantic-output.txt 2>&1 || true | |
| cat semantic-output.txt | |
| # Check if semantic-release determined a new version is needed | |
| if ! grep -q "The next release version is" semantic-output.txt; then | |
| echo "::notice::No new version needed." | |
| echo "should_create_pr=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Get the version that semantic-release would create (for comparison) | |
| SR_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) | |
| # Strip -beta suffix from current version to get base version | |
| BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-beta$//') | |
| # Parse current version components | |
| CURRENT_MAJOR=$(echo "$BASE_VERSION" | cut -d. -f1) | |
| CURRENT_MINOR=$(echo "$BASE_VERSION" | cut -d. -f2) | |
| CURRENT_PATCH=$(echo "$BASE_VERSION" | cut -d. -f3) | |
| # Parse semantic-release suggested version components | |
| SR_MAJOR=$(echo "$SR_VERSION" | cut -d. -f1) | |
| SR_MINOR=$(echo "$SR_VERSION" | cut -d. -f2) | |
| SR_PATCH=$(echo "$SR_VERSION" | cut -d. -f3) | |
| # Determine bump type and apply to current version | |
| if [ "$SR_MAJOR" -gt "$CURRENT_MAJOR" ]; then | |
| # Major bump | |
| NEXT_VERSION="$((CURRENT_MAJOR + 1)).0.0" | |
| elif [ "$SR_MINOR" -gt "$CURRENT_MINOR" ]; then | |
| # Minor bump | |
| NEXT_VERSION="${CURRENT_MAJOR}.$((CURRENT_MINOR + 1)).0" | |
| else | |
| # Patch bump | |
| NEXT_VERSION="${CURRENT_MAJOR}.${CURRENT_MINOR}.$((CURRENT_PATCH + 1))" | |
| fi | |
| # Create beta version | |
| BETA_VERSION="${NEXT_VERSION}-beta" | |
| if [ "$BETA_VERSION" = "$CURRENT_VERSION" ]; then | |
| echo "::notice::Version already matches." | |
| echo "should_create_pr=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
| echo "beta_version=$BETA_VERSION" >> $GITHUB_OUTPUT | |
| echo "should_create_pr=true" >> $GITHUB_OUTPUT | |
| echo "release_branch=beta-release/${BETA_VERSION}" >> $GITHUB_OUTPUT | |
| echo "::notice::Bumping version: $CURRENT_VERSION -> $BETA_VERSION" | |
| - name: Check if beta release branch exists | |
| if: steps.get_version.outputs.should_create_pr == 'true' | |
| id: check_branch | |
| run: | | |
| RELEASE_BRANCH="${{ steps.get_version.outputs.release_branch }}" | |
| if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then | |
| echo "branch_exists=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "branch_exists=false" >> $GITHUB_OUTPUT | |
| - name: Create beta release branch | |
| if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false' | |
| run: | | |
| BRANCH_NAME="${{ steps.get_version.outputs.release_branch }}" | |
| git checkout -b "$BRANCH_NAME" | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV | |
| - name: Update Gradle version | |
| if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false' | |
| run: | | |
| BETA_VERSION="${{ steps.get_version.outputs.beta_version }}" | |
| echo "Running bump_version.sh..." | |
| chmod +x ./scripts/bump_version.sh | |
| ./scripts/bump_version.sh "$BETA_VERSION" | |
| grep "^GLOBAL_VERSION_NAME=" gradle.properties | |
| - name: Generate Changelog | |
| if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false' | |
| run: | | |
| BETA_VERSION="${{ steps.get_version.outputs.beta_version }}" | |
| echo "Generating changelog for version $BETA_VERSION..." | |
| # Create a temporary context file to force the correct version header | |
| echo '{"version":"'${BETA_VERSION}'"}' > context.json | |
| # Generate changelog updates and save to files without tagging | |
| npx conventional-changelog-cli -p conventionalcommits -i CHANGELOG.md -s --context context.json | |
| rm context.json | |
| echo "CHANGELOG.md updated successfully." | |
| - name: Commit changes | |
| if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false' | |
| run: | | |
| BETA_VERSION="${{ steps.get_version.outputs.beta_version }}" | |
| git add gradle.properties CHANGELOG.md | |
| git commit -m "chore(beta-release): prepare version ${BETA_VERSION}" | |
| echo "Committed version bump and changelog." | |
| - name: Push and Create PR | |
| if: steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false' | |
| run: | | |
| BETA_VERSION="${{ steps.get_version.outputs.beta_version }}" | |
| BRANCH_NAME="${{ env.branch_name }}" | |
| BASE_BRANCH="${{ github.ref_name }}" | |
| git push origin "$BRANCH_NAME" | |
| if [ -f CHANGELOG.md ]; then | |
| CHANGELOG_EXCERPT=$(sed -n "/## \[$BETA_VERSION\]/,/## \[/p" CHANGELOG.md | sed '$ d' || echo "See CHANGELOG.md") | |
| else | |
| CHANGELOG_EXCERPT="See CHANGELOG.md for details" | |
| fi | |
| # We construct the body string first to avoid multiline string issues in the CLI command | |
| PR_BODY="🚀 Automated beta release PR | |
| **Beta Version:** \`$BETA_VERSION\` | |
| ## Changes | |
| $CHANGELOG_EXCERPT | |
| ### JitPack Usage | |
| \`\`\`gradle | |
| dependencies { | |
| implementation 'com.github.newrelic.NewRelicVideoCore:$BETA_VERSION' | |
| implementation 'com.github.newrelic.NRExoPlayerTracker:$BETA_VERSION' | |
| implementation 'com.github.newrelic.NRIMATracker:$BETA_VERSION' | |
| } | |
| \`\`\` | |
| --- | |
| *Merge this PR to publish the beta release.*" | |
| gh pr create \ | |
| --base "$BASE_BRANCH" \ | |
| --head "$BRANCH_NAME" \ | |
| --title "chore(beta-release): $BETA_VERSION" \ | |
| --body "$PR_BODY" | |
| # Add beta-release label | |
| PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --base "$BASE_BRANCH" --json number --jq '.[0].number') | |
| gh pr edit "$PR_NUMBER" --add-label "beta-release" |