|  | 
|  | 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: ${{ 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 | +        id: update_version | 
|  | 35 | +        run: | | 
|  | 36 | +          FILE=Sources/swift-format/PrintVersion.swift | 
|  | 37 | +
 | 
|  | 38 | +          if grep -q "print(\"$VERSION\")" "$FILE"; then | 
|  | 39 | +            echo "Version already $VERSION; skipping update." | 
|  | 40 | +            echo "changed=false" >> "$GITHUB_OUTPUT" | 
|  | 41 | +            exit 0 | 
|  | 42 | +          fi | 
|  | 43 | +
 | 
|  | 44 | +          sed -i "s/print(\".*\")/print(\"$VERSION\")/" "$FILE" | 
|  | 45 | +          echo "changed=true" >> "$GITHUB_OUTPUT" | 
|  | 46 | +
 | 
|  | 47 | +      - name: Commit and push changes | 
|  | 48 | +        if: steps.update_version.outputs.changed == 'true' | 
|  | 49 | +        run: | | 
|  | 50 | +          git config user.name "swift-ci" | 
|  | 51 | +          git config user.email "swift-ci@users.noreply.github.com" | 
|  | 52 | +          git add Sources/swift-format/PrintVersion.swift | 
|  | 53 | +          git commit -m "Update version to $VERSION" | 
|  | 54 | +          git push origin $UPDATE_BRANCH | 
|  | 55 | +
 | 
|  | 56 | +      - name: Create Pull Request | 
|  | 57 | +        if: steps.update_version.outputs.changed == 'true' | 
|  | 58 | +        env: | 
|  | 59 | +          GH_TOKEN: ${{ github.token }} | 
|  | 60 | +        run: | | 
|  | 61 | +          gh pr create \ | 
|  | 62 | +            --base "${{ env.RELEASE_BRANCH }}" \ | 
|  | 63 | +            --head "${{ env.UPDATE_BRANCH }}" \ | 
|  | 64 | +            --title "[${{ env.VERSION }}] Update version to ${{ env.VERSION }}" \ | 
|  | 65 | +            --body "This PR was automatically opened by a GitHub action on creation of a release branch (\`${{ env.RELEASE_BRANCH }}\`). | 
|  | 66 | +            Review the version update and merge if correct, otherwise update the version manually." \ | 
|  | 67 | +            --draft | 
0 commit comments