- 
                Notifications
    You must be signed in to change notification settings 
- Fork 253
Add workflow to auto-update PrintVersion on release branch creation #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Update PrintVersion on release branch creation | ||
|  | ||
| on: | ||
| create: | ||
| branches: | ||
| - "release/*" | ||
|  | ||
| jobs: | ||
| update-version: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ github.token }} | ||
|  | ||
| - name: Extract version from branch name | ||
| run: | | ||
| BRANCH_NAME="${GITHUB_REF_NAME}" | ||
| VERSION="${BRANCH_NAME#release/}" | ||
| echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
| echo "RELEASE_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV | ||
| echo "UPDATE_BRANCH=updateversion/$VERSION" >> $GITHUB_ENV | ||
|  | ||
| - name: Create updateversion branch | ||
| run: | | ||
| git checkout -b $UPDATE_BRANCH $RELEASE_BRANCH | ||
|  | ||
| - name: Update PrintVersion.swift | ||
| id: update_version | ||
| run: | | ||
| FILE=Sources/swift-format/PrintVersion.swift | ||
|  | ||
| if grep -q "print(\"$VERSION\")" "$FILE"; then | ||
| echo "Version already $VERSION; skipping update." | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|  | ||
| sed -i "s/print(\".*\")/print(\"$VERSION\")/" "$FILE" | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
|  | ||
| - name: Commit and push changes | ||
| if: steps.update_version.outputs.changed == 'true' | ||
| run: | | ||
| git config user.name "swift-ci" | ||
| git config user.email "swift-ci@users.noreply.github.com" | ||
| git add Sources/swift-format/PrintVersion.swift | ||
| git commit -m "Update version to $VERSION" | ||
| git push origin $UPDATE_BRANCH | ||
|  | ||
| - name: Create Pull Request | ||
| if: steps.update_version.outputs.changed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| gh pr create \ | ||
| --base "${{ env.RELEASE_BRANCH }}" \ | ||
| --head "${{ env.UPDATE_BRANCH }}" \ | ||
| --title "[${{ env.VERSION }}] Update version to ${{ env.VERSION }}" \ | ||
| --body "This PR was automatically opened by a GitHub action on creation of a release branch (\`${{ env.RELEASE_BRANCH }}\`). | ||
| Review the version update and merge if correct, otherwise update the version manually." \ | ||
| --draft | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TTOzzi It seems that this is wrong.
It was triggered on a non-release branch.
The following discussion looks related:
https://github.com/orgs/community/discussions/26286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I hadn’t noticed that 😮 thank you for catching it! I’ll take a look right away.