PR - Publish #4
This file contains 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
# Based on default workflows that are added when creating a new tap | |
# brew tap-new USER/REPOSITORY | |
# https://brew.sh/2020/11/18/homebrew-tap-with-bottles-uploaded-to-github-releases/ | |
name: PR - Publish | |
on: | |
pull_request: | |
types: | |
- closed | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: 'PR Number' | |
required: true | |
type: number | |
jobs: | |
publish: | |
if: ${{ github.event.pull_request.merged || github.event_name == 'workflow_dispatch' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
env: | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} | |
steps: | |
- name: Set up Homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Set up git | |
uses: Homebrew/actions/git-user-config@master | |
- name: Download bottles | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
temp_dir=$(mktemp -d download -p /tmp) | |
cd "$temp_dir" | |
# Get the branch name from the pull request number | |
branch=$( | |
gh pr view "$PULL_REQUEST_NUMBER" \ | |
--json headRefName \ | |
--jq '.headRefName' | |
) | |
# Get the pr-build-bottle.yml run id from the branch name | |
run_id=$( | |
gh run list \ | |
--branch "$branch" \ | |
--workflow pr-build-bottle.yml \ | |
--json databaseId \ | |
--jq 'first.databaseId' | |
) | |
# Download the artifacts from the run | |
gh run download "$run_id" | |
# Move the bottle contents to the current folder | |
mv bottles_*/* . | |
rm -r bottles_* | |
- name: Upload bottles | |
env: | |
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }} | |
run: | | |
brew pr-upload \ | |
--debug \ | |
--tap "$GITHUB_REPOSITORY" \ | |
--workflows pr-build-bottle.yml \ | |
"$PULL_REQUEST_NUMBER" | |
- name: Push commits | |
uses: Homebrew/actions/git-try-push@master | |
with: | |
token: ${{ github.token }} | |
branch: main |