test: pre-release on PR #1
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: Pre Release Prepare - Update Version and Create PR | |
| on: | |
| push: | |
| branches: | |
| - chore/release-workflows | |
| workflow_dispatch: | |
| inputs: | |
| is_patch: | |
| description: 'Is this a patch? (true or false)' | |
| required: true | |
| default: 'false' | |
| env: | |
| AWS_DEFAULT_REGION: us-west-2 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| jobs: | |
| update-version-and-create-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Configure AWS credentials for BOT secrets | |
| uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 #v5.0.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN_SECRETS_MANAGER }} | |
| role-session-name: GitHubActions-PreRelease | |
| aws-region: ${{ env.AWS_DEFAULT_REGION }} | |
| audience: sts.amazonaws.com | |
| - name: Get Bot secrets | |
| uses: aws-actions/aws-secretsmanager-get-secrets@a9a7eb4e2f2871d30dc5b892576fde60a2ecc802 #v2.0.10 | |
| id: bot_secrets | |
| with: | |
| secret-ids: | | |
| BOT_TOKEN,${{ secrets.BOT_TOKEN_SECRET_ARN }} | |
| - name: Set environment variables | |
| run: | | |
| echo "BOT_TOKEN_GITHUB_RW_PATOKEN=${{ env.BOT_TOKEN }}" >> $GITHUB_ENV | |
| - name: Checkout main branch | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0 | |
| with: | |
| ref: main | |
| token: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }} | |
| - name: Setup Git | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| - name: Extract version from gradle.properties | |
| run: | | |
| VERSION=$(grep '^version=' gradle.properties | cut -d'=' -f2) | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "MAJOR_MINOR=$(echo $VERSION | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV | |
| - name: Create branches | |
| run: | | |
| IS_PATCH=${{ github.event.inputs.is_patch || 'false' }} | |
| if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then | |
| echo "Invalid input for IS_PATCH. Must be 'true' or 'false'." | |
| exit 1 | |
| fi | |
| if git ls-remote --heads origin release/v${MAJOR_MINOR}.x | grep -q "release/v${MAJOR_MINOR}.x"; then | |
| if [ "$IS_PATCH" = "true" ]; then | |
| git fetch origin release/v${MAJOR_MINOR}.x | |
| echo "Branch release/v${MAJOR_MINOR}.x already exists, checking out." | |
| git checkout "release/v${MAJOR_MINOR}.x" | |
| else | |
| echo "Error, release series branch release/v${MAJOR_MINOR}.x exist for non-patch release" | |
| echo "Check your input or branch" | |
| exit 1 | |
| fi | |
| else | |
| if [ "$IS_PATCH" = "true" ]; then | |
| echo "Error, release series branch release/v${MAJOR_MINOR}.x NOT exist for patch release" | |
| echo "Check your input or branch" | |
| exit 1 | |
| else | |
| echo "Creating branch release/v${MAJOR_MINOR}.x." | |
| git checkout -b "release/v${MAJOR_MINOR}.x" | |
| git push origin "release/v${MAJOR_MINOR}.x" | |
| fi | |
| fi | |
| git checkout -b "v${VERSION}_release" | |
| git push origin "v${VERSION}_release" | |
| - name: Update CHANGELOG for release | |
| run: | | |
| echo "VERSION is: $VERSION" | |
| echo "Date is: $(date +%Y-%m-%d)" | |
| echo "Before sed:" | |
| head -10 CHANGELOG.md | |
| sed -i "s/## Unreleased/## Unreleased\n\n## v${VERSION} - $(date +%Y-%m-%d)/" CHANGELOG.md | |
| echo "After sed:" | |
| head -10 CHANGELOG.md | |
| if git diff --quiet CHANGELOG.md; then | |
| echo "ERROR: No changes made to CHANGELOG.md" | |
| exit 1 | |
| fi | |
| - name: Create pull request against the release branch | |
| env: | |
| GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }} | |
| run: | | |
| gh pr create --title "Pre-release: Update version to ${VERSION}" \ | |
| --body "This PR updates the version to ${VERSION}. | |
| By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \ | |
| --head v${VERSION}_release \ | |
| --base release/v${MAJOR_MINOR}.x |