|
17 | 17 | # them on launch (oven-sh/bun#29120). Unpin once a Bun release includes the |
18 | 18 | # upstream fix (oven-sh/bun#29122). |
19 | 19 | CLI_BUN_VERSION: '1.3.11' |
| 20 | + HOMEBREW_TAP_REPO: appwrite/homebrew-appwrite |
20 | 21 | steps: |
21 | 22 | - uses: actions/checkout@v4 |
22 | 23 | with: |
@@ -75,33 +76,34 @@ jobs: |
75 | 76 | GHR_REPLACE: false |
76 | 77 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
77 | 78 |
|
78 | | - - name: Update Homebrew formula checksums |
| 79 | + - name: Check out Homebrew tap |
| 80 | + uses: actions/checkout@v4 |
| 81 | + with: |
| 82 | + repository: ${{ env.HOMEBREW_TAP_REPO }} |
| 83 | + token: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }} |
| 84 | + path: homebrew-tap |
| 85 | + fetch-depth: 0 |
| 86 | + |
| 87 | + - name: Update Homebrew formula in tap |
| 88 | + id: tap |
| 89 | + working-directory: homebrew-tap |
79 | 90 | env: |
80 | 91 | RELEASE_TAG: ${{ github.event.release.tag_name }} |
81 | | - TARGET_COMMITISH: ${{ github.event.release.target_commitish }} |
82 | 92 | run: | |
83 | 93 | set -euo pipefail |
84 | 94 |
|
85 | | - TARGET_BRANCH="$TARGET_COMMITISH" |
86 | | - if ! git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null 2>&1; then |
87 | | - TARGET_BRANCH="master" |
88 | | - fi |
89 | | -
|
90 | | - git fetch origin "$TARGET_BRANCH" |
91 | | - git switch -C "$TARGET_BRANCH" "origin/$TARGET_BRANCH" |
92 | | -
|
93 | 95 | FORMULA_PATH="$(find Formula -maxdepth 1 -name '*.rb' | head -n 1)" |
94 | 96 | if [ -z "$FORMULA_PATH" ]; then |
95 | | - echo "Formula file not found" |
| 97 | + echo "No formula found in Homebrew tap" |
96 | 98 | exit 1 |
97 | 99 | fi |
98 | | -
|
99 | 100 | EXECUTABLE_NAME="$(basename "$FORMULA_PATH" .rb)" |
100 | | - export FORMULA_PATH RELEASE_TAG EXECUTABLE_NAME |
101 | | - export MAC_ARM64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-arm64" | awk '{print $1}')" |
102 | | - export MAC_X64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-x64" | awk '{print $1}')" |
103 | | - export LINUX_ARM64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-arm64" | awk '{print $1}')" |
104 | | - export LINUX_X64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-x64" | awk '{print $1}')" |
| 101 | +
|
| 102 | + export FORMULA_PATH EXECUTABLE_NAME |
| 103 | + export MAC_ARM64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-darwin-arm64" | awk '{print $1}')" |
| 104 | + export MAC_X64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-darwin-x64" | awk '{print $1}')" |
| 105 | + export LINUX_ARM64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-linux-arm64" | awk '{print $1}')" |
| 106 | + export LINUX_X64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-linux-x64" | awk '{print $1}')" |
105 | 107 |
|
106 | 108 | ruby <<'RUBY' |
107 | 109 | formula_path = ENV.fetch("FORMULA_PATH") |
@@ -132,13 +134,49 @@ jobs: |
132 | 134 |
|
133 | 135 | ruby -c "$FORMULA_PATH" |
134 | 136 |
|
| 137 | + { |
| 138 | + echo "executable=${EXECUTABLE_NAME}" |
| 139 | + echo "formula_path=${FORMULA_PATH}" |
| 140 | + } >> "$GITHUB_OUTPUT" |
| 141 | +
|
| 142 | + - name: Open pull request on Homebrew tap |
| 143 | + working-directory: homebrew-tap |
| 144 | + env: |
| 145 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 146 | + EXECUTABLE_NAME: ${{ steps.tap.outputs.executable }} |
| 147 | + FORMULA_PATH: ${{ steps.tap.outputs.formula_path }} |
| 148 | + SOURCE_REPO: ${{ github.repository }} |
| 149 | + SERVER_URL: ${{ github.server_url }} |
| 150 | + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }} |
| 151 | + run: | |
| 152 | + set -euo pipefail |
| 153 | +
|
135 | 154 | if git diff --quiet -- "$FORMULA_PATH"; then |
136 | | - echo "Homebrew formula already up to date" |
| 155 | + echo "Homebrew formula already up to date for ${RELEASE_TAG}" |
137 | 156 | exit 0 |
138 | 157 | fi |
139 | 158 |
|
140 | | - git config user.name "github-actions[bot]" |
141 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 159 | + BASE_BRANCH="$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')" |
| 160 | + BRANCH="release/${EXECUTABLE_NAME}-${RELEASE_TAG}" |
| 161 | +
|
| 162 | + git config user.name "appwrite-bot" |
| 163 | + git config user.email "bot@appwrite.io" |
| 164 | +
|
| 165 | + git checkout -B "$BRANCH" |
142 | 166 | git add "$FORMULA_PATH" |
143 | | - git commit -m "chore: update Homebrew formula for ${RELEASE_TAG}" |
144 | | - git push origin "$TARGET_BRANCH" |
| 167 | + git commit -m "${EXECUTABLE_NAME} ${RELEASE_TAG}" |
| 168 | + git push -f -u origin "$BRANCH" |
| 169 | +
|
| 170 | + PR_TITLE="${EXECUTABLE_NAME} ${RELEASE_TAG}" |
| 171 | + PR_BODY=$(printf 'Automated formula update for the `%s` CLI release [`%s`](%s/%s/releases/tag/%s).\n\nOpened automatically by the `%s` publish workflow after release binaries were uploaded.' "$EXECUTABLE_NAME" "$RELEASE_TAG" "$SERVER_URL" "$SOURCE_REPO" "$RELEASE_TAG" "${SOURCE_REPO#*/}") |
| 172 | +
|
| 173 | + EXISTING_PR="$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number' || true)" |
| 174 | + if [ -n "$EXISTING_PR" ]; then |
| 175 | + gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY" |
| 176 | + else |
| 177 | + gh pr create \ |
| 178 | + --title "$PR_TITLE" \ |
| 179 | + --body "$PR_BODY" \ |
| 180 | + --base "$BASE_BRANCH" \ |
| 181 | + --head "$BRANCH" |
| 182 | + fi |
0 commit comments