|
| 1 | +name: Update PrintVersion on release branch creation |
| 2 | + |
| 3 | +on: |
| 4 | + create: |
| 5 | + branches: |
| 6 | + - "release/*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-version: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + steps: |
| 15 | + - name: Checkout repo |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + |
| 21 | + - name: Extract version from branch name |
| 22 | + run: | |
| 23 | + BRANCH_NAME="${GITHUB_REF_NAME}" |
| 24 | + VERSION="${BRANCH_NAME#release/}" |
| 25 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 26 | + echo "RELEASE_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV |
| 27 | + echo "UPDATE_BRANCH=updateversion/$VERSION" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Create updateversion branch |
| 30 | + run: | |
| 31 | + git checkout -b $UPDATE_BRANCH $RELEASE_BRANCH |
| 32 | +
|
| 33 | + - name: Update PrintVersion.swift |
| 34 | + run: | |
| 35 | + # Update the version string in PrintVersion.swift |
| 36 | + sed -i "s/print(\".*\")/print(\"$VERSION\")/" Sources/swift-format/PrintVersion.swift |
| 37 | +
|
| 38 | + - name: Commit and push changes |
| 39 | + run: | |
| 40 | + git config user.name "swift-ci" |
| 41 | + git config user.email "swift-ci@users.noreply.github.com" |
| 42 | + git add Sources/swift-format/PrintVersion.swift |
| 43 | + git commit -m "Update version to $VERSION" |
| 44 | + git push origin $UPDATE_BRANCH |
| 45 | +
|
| 46 | + - name: Create Pull Request |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ github.token }} |
| 49 | + run: | |
| 50 | + gh pr create \ |
| 51 | + --base "${{ env.RELEASE_BRANCH }}" \ |
| 52 | + --head "${{ env.UPDATE_BRANCH }}" \ |
| 53 | + --title "[${{ env.VERSION }}] Update version to ${{ env.VERSION }}" \ |
| 54 | + --body "This PR updates the version in PrintVersion.swift to ${{ env.VERSION }}. |
| 55 | +
|
| 56 | + Automatically created when release branch ${{ env.RELEASE_BRANCH }} was created." \ |
| 57 | + --draft |
0 commit comments