Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 0 additions & 14 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,6 @@ function configureSDK($sdk, $overrides = []) {
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
|_| |_| ");
// Generated formulas start with placeholder checksums. The generated CLI
// publish workflow rewrites them after the native release binaries exist.
foreach ([
'APPWRITE_CLI_HOMEBREW_MAC_ARM64_SHA256' => 'homebrewMacArm64Sha256',
'APPWRITE_CLI_HOMEBREW_MAC_X64_SHA256' => 'homebrewMacX64Sha256',
'APPWRITE_CLI_HOMEBREW_LINUX_ARM64_SHA256' => 'homebrewLinuxArm64Sha256',
'APPWRITE_CLI_HOMEBREW_LINUX_X64_SHA256' => 'homebrewLinuxX64Sha256',
] as $envKey => $paramKey) {
$sha256 = getenv($envKey);

if ($sha256 !== false && $sha256 !== '') {
$language->setHomebrewSha256($paramKey, $sha256);
}
}

$sdk = new SDK($language, new Swagger2($spec));
$sdk->setTest(false);
Expand Down
30 changes: 13 additions & 17 deletions src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ class CLI extends Node
'executableName' => 'executable',
'logo' => '',
'logoUnescaped' => '',
'homebrewMacArm64Sha256' => '0000000000000000000000000000000000000000000000000000000000000000',
'homebrewMacX64Sha256' => '0000000000000000000000000000000000000000000000000000000000000000',
'homebrewLinuxArm64Sha256' => '0000000000000000000000000000000000000000000000000000000000000000',
'homebrewLinuxX64Sha256' => '0000000000000000000000000000000000000000000000000000000000000000',
// Homebrew tap that hosts the CLI formula. The tap lives at
// `github.com/<homebrewTapOwner>/homebrew-<homebrewTapName>` and users
// install the formula via `brew install <owner>/<name>/<executable>`.
'homebrewTapOwner' => 'appwrite',
'homebrewTapName' => 'appwrite',
];

/**
Expand Down Expand Up @@ -155,16 +156,18 @@ public function setLogoUnescaped(string $logo): self
}

/**
* Override a generated Homebrew formula checksum placeholder when a release
* build already knows the target binary SHA256.
* Configure the Homebrew tap that hosts the CLI formula.
* The tap is addressed as `<owner>/<name>` in Homebrew and resolves to the
* repository `github.com/<owner>/homebrew-<name>`.
*
* @param string $key
* @param string $sha256
* @param string $owner GitHub organization or user (e.g. "appwrite")
* @param string $name Tap short name without `homebrew-` prefix (e.g. "appwrite")
* @return $this
*/
public function setHomebrewSha256(string $key, string $sha256): self
public function setHomebrewTap(string $owner, string $name): self
{
$this->setParam($key, $sha256);
$this->setParam('homebrewTapOwner', $owner);
$this->setParam('homebrewTapName', $name);

return $this;
}
Expand Down Expand Up @@ -301,13 +304,6 @@ public function getFiles(): array
'template' => 'cli/docs/example.md.twig',
],

// Distribution - Formula (Homebrew)
[
'scope' => 'method',
'destination' => 'Formula/{{ language.params.executableName }}.rb',
'template' => 'cli/Formula/formula.rb.twig',
],

// Distribution - Scoop (Windows)
[
'scope' => 'default',
Expand Down
96 changes: 71 additions & 25 deletions templates/cli/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,51 @@ jobs:
GHR_REPLACE: false
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Update Homebrew formula checksums
# The Homebrew formula lives in the dedicated tap repo appwrite/homebrew-appwrite.
# On every release we compute the native binary checksums, update the formula in
# the tap, and open a pull request back to the tap so maintainers (or automation)
# can publish the new version.
- name: Compute native binary checksums
id: checksums
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
TARGET_COMMITISH: ${{ github.event.release.target_commitish }}
EXECUTABLE_NAME: appwrite
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
run: |
set -euo pipefail
{
echo "executable=${EXECUTABLE_NAME}"
echo "mac_arm64=$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-arm64" | awk '{print $1}')"
echo "mac_x64=$(sha256sum "build/${EXECUTABLE_NAME}-cli-darwin-x64" | awk '{print $1}')"
echo "linux_arm64=$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-arm64" | awk '{print $1}')"
echo "linux_x64=$(sha256sum "build/${EXECUTABLE_NAME}-cli-linux-x64" | awk '{print $1}')"
} >> "$GITHUB_OUTPUT"

- name: Check out homebrew-appwrite tap
uses: actions/checkout@v4
with:
repository: appwrite/homebrew-appwrite
token: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }}
path: homebrew-appwrite
fetch-depth: 0

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"
- name: Update Homebrew formula in tap
working-directory: homebrew-appwrite
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
EXECUTABLE_NAME: ${{ steps.checksums.outputs.executable }}
MAC_ARM64_SHA256: ${{ steps.checksums.outputs.mac_arm64 }}
MAC_X64_SHA256: ${{ steps.checksums.outputs.mac_x64 }}
LINUX_ARM64_SHA256: ${{ steps.checksums.outputs.linux_arm64 }}
LINUX_X64_SHA256: ${{ steps.checksums.outputs.linux_x64 }}
run: |
set -euo pipefail

FORMULA_PATH="$(find Formula -maxdepth 1 -name '*.rb' | head -n 1)"
if [ -z "$FORMULA_PATH" ]; then
echo "Formula file not found"
FORMULA_PATH="Formula/${EXECUTABLE_NAME}.rb"
if [ ! -f "$FORMULA_PATH" ]; then
echo "Formula not found at $FORMULA_PATH in homebrew-appwrite"
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
ruby <<'RUBY'
formula_path = ENV.fetch("FORMULA_PATH")
executable = ENV.fetch("EXECUTABLE_NAME")
Expand Down Expand Up @@ -132,13 +149,42 @@ jobs:

ruby -c "$FORMULA_PATH"

- name: Open pull request on homebrew-appwrite
working-directory: homebrew-appwrite
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
EXECUTABLE_NAME: ${{ steps.checksums.outputs.executable }}
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GH_TOKEN }}
run: |
set -euo pipefail

FORMULA_PATH="Formula/${EXECUTABLE_NAME}.rb"
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"

PR_TITLE="${EXECUTABLE_NAME} ${RELEASE_TAG}"
PR_BODY=$(printf 'Automated formula update for the `%s` CLI release [`%s`](https://github.com/appwrite/sdk-for-cli/releases/tag/%s).\n\nOpened automatically by the `sdk-for-cli` publish workflow after release binaries were uploaded.' "$EXECUTABLE_NAME" "$RELEASE_TAG" "$RELEASE_TAG")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated

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 templates/cli/Formula/formula.rb.twig

This file was deleted.

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

### MacOS via [Homebrew](https://brew.sh)
### MacOS / Linux via [Homebrew](https://brew.sh)
```bash
$ brew install {{ language.params.executableName }}
$ brew install {{ language.params.homebrewTapOwner }}/{{ language.params.homebrewTapName }}/{{ language.params.executableName }}
```

Homebrew installs the native binary for your platform.
The formula lives in the [`{{ language.params.homebrewTapOwner }}/homebrew-{{ language.params.homebrewTapName }}`](https://github.com/{{ language.params.homebrewTapOwner }}/homebrew-{{ language.params.homebrewTapName }}) tap and Homebrew will download the native binary that matches your platform.

### Windows
Via Powershell
Expand Down
15 changes: 10 additions & 5 deletions templates/cli/lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import {
EXECUTABLE_NAME,
GITHUB_RELEASES_URL,
HOMEBREW_FORMULA,
HOMEBREW_TAP,
NPM_PACKAGE_NAME,
SDK_TITLE,
} from "../constants.js";
Expand Down Expand Up @@ -164,10 +166,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 +179,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 +262,8 @@ 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(` # (first time: brew tap ${HOMEBREW_TAP})`);
console.log("");

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

// Homebrew — fully-qualified `<owner>/<tap>/<formula>` reference so self-update
// lookups resolve to the Appwrite tap even if another formula ever shares the name.
export const HOMEBREW_TAP = '{{ language.params.homebrewTapOwner }}/{{ language.params.homebrewTapName }}';
export const HOMEBREW_FORMULA = `${HOMEBREW_TAP}/{{ language.params.executableName|caseLower }}`;

// NPM
export const NPM_PACKAGE_NAME = '{{ language.params.npmPackage|caseDash }}';
export const NPM_REGISTRY_URL = `https://registry.npmjs.org/${NPM_PACKAGE_NAME}/latest`;
Expand Down
5 changes: 4 additions & 1 deletion templates/cli/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,9 @@ type HomebrewInfoResponse = {
};

const WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
const HOMEBREW_FORMULA_NAME = EXECUTABLE_NAME.toLowerCase();
// Prefer the fully-qualified `<tap>/<formula>` reference so `brew info` resolves
// to the Appwrite tap even if another tap ever registers the `appwrite` name.
const HOMEBREW_FORMULA_NAME = HOMEBREW_FORMULA;

const getExecutablePaths = (): {
execPath: string;
Expand Down
Loading