cf-reeve-platform-pr #202
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: Sync platform versions | |
| on: | |
| repository_dispatch: | |
| types: | |
| - cf-reeve-platform-pr | |
| jobs: | |
| create-or-update-pr: | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.CF_REEVE_APPLICATION_REPO_PAT }} | |
| fetch-depth: 0 | |
| - name: Setup git | |
| run: | | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| - name: Update platform version | |
| env: | |
| VERSION: "${{ github.event.client_payload.TRIGGERING_PAYLOAD.version }}" | |
| PR_NAME: "${{ github.event.client_payload.TRIGGERING_PAYLOAD.prName }}" | |
| SOURCE_BRANCH: "${{ github.event.client_payload.TRIGGERING_PAYLOAD.sourceBranch }}" | |
| TARGET_BRANCH: "${{ github.event.client_payload.TRIGGERING_PAYLOAD.targetBranch }}" | |
| GITHUB_RUN_ID: "${{ github.event.client_payload.TRIGGERING_GHRUNID }}" | |
| run: | | |
| echo "Checkout branch $SOURCE_BRANCH" | |
| if ! git checkout $SOURCE_BRANCH | |
| then | |
| echo "Branch does not exist. Creating new branch $SOURCE_BRANCH" | |
| git checkout --track -b $SOURCE_BRANCH "origin/${TARGET_BRANCH}" | |
| fi | |
| BUILD_GRADLE_FILE=build.gradle.kts | |
| echo "Set platform version to $VERSION" | |
| sed -i -E "s|extra\[\"cfLobPlatformVersion\"\] = \".*\"|extra\[\"cfLobPlatformVersion\"\] = \"$VERSION\"|g" $BUILD_GRADLE_FILE | |
| echo "Commit and push new platform version" | |
| git add $BUILD_GRADLE_FILE | |
| if git commit $BUILD_GRADLE_FILE -m "chore: Bump platform version to $VERSION (automated commit by gha run id $GITHUB_RUN_ID)" | |
| then | |
| git push origin $SOURCE_BRANCH | |
| else | |
| echo "No changes detected" | |
| fi | |
| echo "Check if PR for branch $SOURCE_BRANCH exists" | |
| PR_STATE=$(gh pr view $SOURCE_BRANCH --json state --jq '.state' || echo "") | |
| if [ "$PR_STATE" != "OPEN" ] | |
| then | |
| echo "PR does not exist. Creating new PR \"$PR_NAME\" from $SOURCE_BRANCH to $TARGET_BRANCH" | |
| gh pr create --title "$PR_NAME" --body "" --base $TARGET_BRANCH --head $SOURCE_BRANCH | |
| fi |