Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 60 additions & 22 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
# them on launch (oven-sh/bun#29120). Unpin once a Bun release includes the
# upstream fix (oven-sh/bun#29122).
CLI_BUN_VERSION: '1.3.11'
HOMEBREW_TAP_REPO: appwrite/homebrew-appwrite
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -75,33 +76,34 @@ jobs:
GHR_REPLACE: false
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Update Homebrew formula checksums
- name: Check out Homebrew tap
uses: actions/checkout@v4
with:
repository: ${{ env.HOMEBREW_TAP_REPO }}
token: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }}
path: homebrew-tap
fetch-depth: 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 fetch-depth: 0 fetches full history unnecessarily

The tap checkout only needs to create a new branch from the default branch HEAD — full history (fetch-depth: 0) isn't required. fetch-depth: 1 is sufficient and avoids cloning the entire tap repo history on every release.

Suggested change
fetch-depth: 0
fetch-depth: 1


- name: Update Homebrew formula in tap
id: tap
working-directory: homebrew-tap
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
TARGET_COMMITISH: ${{ github.event.release.target_commitish }}
run: |
set -euo pipefail

TARGET_BRANCH="$TARGET_COMMITISH"
if ! git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null 2>&1; then
TARGET_BRANCH="master"
fi

git fetch origin "$TARGET_BRANCH"
git switch -C "$TARGET_BRANCH" "origin/$TARGET_BRANCH"

FORMULA_PATH="$(find Formula -maxdepth 1 -name '*.rb' | head -n 1)"
if [ -z "$FORMULA_PATH" ]; then
echo "Formula file not found"
echo "No formula found in Homebrew tap"
exit 1
fi

EXECUTABLE_NAME="$(basename "$FORMULA_PATH" .rb)"
export FORMULA_PATH RELEASE_TAG EXECUTABLE_NAME
export MAC_ARM64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-arm64" | awk '{print $1}')"
export MAC_X64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-x64" | awk '{print $1}')"
export LINUX_ARM64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-arm64" | awk '{print $1}')"
export LINUX_X64_SHA256="$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-x64" | awk '{print $1}')"

export FORMULA_PATH EXECUTABLE_NAME
export MAC_ARM64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-darwin-arm64" | awk '{print $1}')"
export MAC_X64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-darwin-x64" | awk '{print $1}')"
export LINUX_ARM64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-linux-arm64" | awk '{print $1}')"
export LINUX_X64_SHA256="$(sha256sum "../build/${EXECUTABLE_NAME}-cli-linux-x64" | awk '{print $1}')"

ruby <<'RUBY'
formula_path = ENV.fetch("FORMULA_PATH")
Expand Down Expand Up @@ -132,13 +134,49 @@ jobs:

ruby -c "$FORMULA_PATH"

{
echo "executable=${EXECUTABLE_NAME}"
echo "formula_path=${FORMULA_PATH}"
} >> "$GITHUB_OUTPUT"

- name: Open pull request on Homebrew tap
working-directory: homebrew-tap
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
EXECUTABLE_NAME: ${{ steps.tap.outputs.executable }}
FORMULA_PATH: ${{ steps.tap.outputs.formula_path }}
SOURCE_REPO: ${{ github.repository }}
SERVER_URL: ${{ github.server_url }}
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }}
run: |
set -euo pipefail

if git diff --quiet -- "$FORMULA_PATH"; then
echo "Homebrew formula already up to date"
echo "Homebrew formula already up to date for ${RELEASE_TAG}"
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
BASE_BRANCH="$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')"
BRANCH="release/${EXECUTABLE_NAME}-${RELEASE_TAG}"

git config user.name "appwrite-bot"
git config user.email "bot@appwrite.io"

git checkout -B "$BRANCH"
git add "$FORMULA_PATH"
git commit -m "chore: update Homebrew formula for ${RELEASE_TAG}"
git push origin "$TARGET_BRANCH"
git commit -m "${EXECUTABLE_NAME} ${RELEASE_TAG}"
git push -f -u origin "$BRANCH"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Force push dismisses any existing PR reviews

git push -f correctly handles re-runs, but it will also dismiss any "approved" or "changes requested" reviews on an existing open PR in the tap repo. For a fully automated tap this is probably acceptable, but if human reviewers ever approve the formula PR before merging, a re-triggered release would silently reset that approval. Consider adding a note in the workflow or PR body that re-runs will invalidate existing reviews.


PR_TITLE="${EXECUTABLE_NAME} ${RELEASE_TAG}"
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#*/}")

EXISTING_PR="$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number' || true)"
if [ -n "$EXISTING_PR" ]; then
gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY"
else
gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--base "$BASE_BRANCH" \
--head "$BRANCH"
fi
68 changes: 0 additions & 68 deletions Formula/appwrite.rb

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ If you do not have `npm` installed, you can always install the prebuilt binaries
$ wget -q https://appwrite.io/cli/install.sh -O - | /bin/bash
```

### MacOS via [Homebrew](https://brew.sh)
### MacOS / Linux via [Homebrew](https://brew.sh)
```bash
$ brew install appwrite
$ brew install appwrite/appwrite/appwrite
```

Homebrew installs the native binary for your platform.
Homebrew pulls the formula from the [`appwrite/homebrew-appwrite`](https://github.com/appwrite/homebrew-appwrite) tap and downloads the native binary for your platform.

### Windows
Via Powershell
Expand Down
13 changes: 8 additions & 5 deletions lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
EXECUTABLE_NAME,
GITHUB_RELEASES_URL,
HOMEBREW_FORMULA,
NPM_PACKAGE_NAME,
SDK_TITLE,
} from "../constants.js";
Expand Down Expand Up @@ -164,10 +165,10 @@ const updateViaNpm = async (): Promise<void> => {
*/
const updateViaHomebrew = async (): Promise<void> => {
try {
await execCommand("brew", ["upgrade", "appwrite"]);
await execCommand("brew", ["upgrade", HOMEBREW_FORMULA]);
console.log("");
success("Updated to latest version via Homebrew!");
hint("Run 'appwrite --version' to verify the new version.");
hint(`Run '${EXECUTABLE_NAME} --version' to verify the new version.`);
} catch (e: unknown) {
const message = getErrorMessage(e);

Expand All @@ -177,11 +178,13 @@ const updateViaHomebrew = async (): Promise<void> => {
) {
console.log("");
success("Latest version is already installed via Homebrew!");
hint("The CLI is up to date. Run 'appwrite --version' to verify.");
hint(
`The CLI is up to date. Run '${EXECUTABLE_NAME} --version' to verify.`,
);
} else {
console.log("");
error(`Failed to update via Homebrew: ${message}`);
hint("Try running: brew upgrade appwrite");
hint(`Try running: brew upgrade ${HOMEBREW_FORMULA}`);
}
}
};
Expand Down Expand Up @@ -258,7 +261,7 @@ const showManualInstructions = (latestVersion: string): void => {
console.log("");

log(`${chalk.bold("Option 2: Homebrew")}`);
console.log(` brew upgrade appwrite`);
console.log(` brew upgrade ${HOMEBREW_FORMULA}`);
console.log("");

if (process.platform !== "win32") {
Expand Down
4 changes: 4 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const EXECUTABLE_NAME = 'appwrite';
// 1 day
export const UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;

// Homebrew — fully-qualified `<owner>/<tap>/<formula>` reference
export const HOMEBREW_TAP = 'appwrite/appwrite';
export const HOMEBREW_FORMULA = `${HOMEBREW_TAP}/appwrite`;

// NPM
export const NPM_PACKAGE_NAME = 'appwrite-cli';
export const NPM_REGISTRY_URL = `https://registry.npmjs.org/${NPM_PACKAGE_NAME}/latest`;
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
NPM_PACKAGE_NAME,
DEFAULT_ENDPOINT,
EXECUTABLE_NAME,
HOMEBREW_FORMULA,
UPDATE_CHECK_INTERVAL_MS,
} from "./constants.js";

Expand Down Expand Up @@ -102,7 +103,6 @@ type HomebrewInfoResponse = {
};

const WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
const HOMEBREW_FORMULA_NAME = EXECUTABLE_NAME.toLowerCase();

const getExecutablePaths = (): {
execPath: string;
Expand Down Expand Up @@ -227,7 +227,7 @@ const getHomebrewLatestVersion = async (
try {
const output = childProcess.execFileSync(
"brew",
["info", "--json=v2", HOMEBREW_FORMULA_NAME],
["info", "--json=v2", HOMEBREW_FORMULA],
{
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
Expand Down
Loading