ci(publish): fix authentication for push #22
Workflow file for this run
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: brew pr-pull | |
| on: | |
| pull_request: # TODO: change back to pull_request_target before merge | |
| types: | |
| - labeled | |
| jobs: | |
| pr-pull: | |
| if: contains(github.event.pull_request.labels.*.name, 'pr-pull') | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| actions: read | |
| checks: read | |
| contents: write | |
| issues: read | |
| packages: write | |
| pull-requests: write | |
| steps: | |
| - name: Comment on PR | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.GH_BOT_TOKEN }} | |
| script: | | |
| const runUrl = [ | |
| 'https://github.com', | |
| context.repo.owner, | |
| context.repo.repo, | |
| 'actions', | |
| 'runs', | |
| context.runId, | |
| ].join('/'); | |
| const bodyLines = [ | |
| '⚠️ **Important**: This PR is being processed to add bottles.', | |
| '', | |
| 'Please **do not push any changes** to this PR branch as it may', | |
| 'cause conflicts or issues with the bottle publishing process.', | |
| '', | |
| 'If you need to make changes:', | |
| '1. Mark this PR as draft', | |
| `2. Wait for the [publish workflow](${runUrl}) to complete`, | |
| '3. Make your changes after the bottles have been added' | |
| ]; | |
| const body = bodyLines.join('\n'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| body | |
| }); | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| stable: true | |
| - name: Set up git | |
| uses: Homebrew/actions/git-user-config@main | |
| with: | |
| username: ${{ secrets.GH_BOT_NAME }} | |
| - name: Get PR data | |
| id: pr-data | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const pr = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number | |
| }); | |
| const data = pr.data; | |
| const branch = data.head.ref; | |
| const remoteBranch = branch; | |
| const remote = data.head.repo.clone_url; | |
| const headRepoOwner = data.head.repo.owner.login; | |
| const isFork = data.head.repo.fork; | |
| const finalBranch = isFork ? `${headRepoOwner}-${branch}` : branch; | |
| core.setOutput('branch', finalBranch); | |
| core.setOutput('remote_branch', remoteBranch); | |
| core.setOutput('remote', remote); | |
| - name: Checkout PR branch | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PULL_REQUEST: ${{ github.event.pull_request.number }} | |
| run: gh pr checkout "${PULL_REQUEST}" --repo "${GITHUB_REPOSITORY}" | |
| - name: Pull bottles | |
| env: | |
| HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.repository_owner }} | |
| PULL_REQUEST: ${{ github.event.pull_request.number }} | |
| run: | | |
| brew pr-pull \ | |
| --branch-okay \ | |
| --committer="${{ secrets.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>" \ | |
| --debug \ | |
| --no-cherry-pick \ | |
| --tap="${GITHUB_REPOSITORY}" \ | |
| "${PULL_REQUEST}" | |
| - name: Push commits to PR branch | |
| uses: Homebrew/actions/git-try-push@main | |
| with: | |
| token: ${{ secrets.GH_BOT_TOKEN }} | |
| directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| remote: ${{ steps.pr-data.outputs.remote }} | |
| branch: ${{ steps.pr-data.outputs.branch }} | |
| remote_branch: ${{ steps.pr-data.outputs.remote_branch }} | |
| force: true | |
| env: | |
| GIT_COMMITTER_NAME: ${{ secrets.GH_BOT_NAME }} | |
| GIT_COMMITTER_EMAIL: ${{ secrets.GH_BOT_EMAIL }} |