Files
setup-cli/action.yml
Julien Goux 4c16bf7a1f Honor workspace npm config for CLI installs (#443)
## Summary
- Run npm commands from the caller workspace so npm remains the source
of truth for `.npmrc` parsing, auth, delegated config files, env
expansion, quoting, and precedence.
- Keep the CLI install isolated with `--prefix`, while explicitly
overriding action-owned npm policy such as `offline=false`,
`bin-links=true`, and no package lock.
- Treat existing `node` and `npm` commands on musl as sufficient only
when they actually run, probing Alpine `/usr/bin` binaries with
`/usr/bin` first on PATH.
- Prefer Alpine `/usr/bin` runtime binaries when an earlier PATH entry
shadows them, and keep apk installation for missing runtime libraries or
missing commands.

## Validation
- `bun run ci`
- Real npm sanity check for workspace `.npmrc` with quoted/env delegated
config, `globalconfig`, relative `cafile`, mTLS path keys,
`offline=true`, `bin-links=false`, and package-lock policy
- Fixture workflow:
https://github.com/jgoux/setup-cli-testing/actions/runs/28663875606

Addresses
https://github.com/supabase/setup-cli/pull/442#discussion_r3519786253
Addresses
https://github.com/supabase/setup-cli/pull/442#discussion_r3519786255
2026-07-07 12:11:42 +01:00

182 lines
6.3 KiB
YAML

name: Supabase CLI Action
description: Setup Supabase CLI, supabase, on GitHub Actions runners
author: Supabase
inputs:
version:
description: Supabase CLI version to install. Supports latest, beta, or a fixed version published to npm. If omitted, detect from the root lockfile and otherwise use latest.
required: false
outputs:
version:
description: Version of installed Supabase CLI
value: ${{ steps.setup-cli.outputs.version }}
runs:
using: composite
steps:
- id: bun-download
name: Resolve Bun Download URL
shell: sh
working-directory: ${{ github.action_path }}
run: |
set -eu
is_musl=false
if [ "${RUNNER_OS}" = "Linux" ]; then
# setup-bun does not detect Linux musl yet, so Alpine-like containers need the musl asset explicitly.
if [ -f /etc/alpine-release ]; then
is_musl=true
elif command -v ldd >/dev/null 2>&1 && ldd --version 2>&1 | grep -qi musl; then
is_musl=true
fi
fi
echo "is-musl=${is_musl}" >> "$GITHUB_OUTPUT"
if [ "${is_musl}" != "true" ]; then
exit 0
fi
version="$(cat .bun-version)"
case "$(uname -m)" in
x86_64) arch="x64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
echo "Unsupported Linux musl architecture: $(uname -m)" >&2
exit 1
;;
esac
echo "url=https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-${arch}-musl.zip" >> "$GITHUB_OUTPUT"
- name: Install Alpine Runtime Dependencies
shell: sh
run: |
set -eu
if [ "${{ steps.bun-download.outputs.is-musl }}" != "true" ]; then
exit 0
fi
# Alpine/musl containers need runtime packages for Bun and the npm CLI shim.
# actions/setup-node uses glibc Node builds, so install Alpine's Node/npm instead.
if command -v apk >/dev/null 2>&1; then
missing_packages=""
prefer_apk_bin=false
for package in libstdc++ libgcc; do
if ! apk info -e "${package}" >/dev/null 2>&1; then
missing_packages="${missing_packages} ${package}"
fi
done
if ! command -v node >/dev/null 2>&1 || ! node -p 'process.versions.node' >/dev/null 2>&1; then
if [ -x /usr/bin/node ] && PATH="/usr/bin:${PATH}" /usr/bin/node -p 'process.versions.node' >/dev/null 2>&1; then
prefer_apk_bin=true
else
missing_packages="${missing_packages} nodejs"
fi
fi
if ! command -v npm >/dev/null 2>&1 || ! npm --version >/dev/null 2>&1; then
if [ -x /usr/bin/npm ] && PATH="/usr/bin:${PATH}" /usr/bin/npm --version >/dev/null 2>&1; then
prefer_apk_bin=true
else
missing_packages="${missing_packages} npm"
fi
fi
if [ "${prefer_apk_bin}" = "true" ]; then
echo "/usr/bin" >> "$GITHUB_PATH"
fi
if [ -z "${missing_packages}" ]; then
exit 0
fi
if [ "$(id -u)" != "0" ]; then
echo "::error::Alpine/musl containers need${missing_packages} to run Supabase CLI. Add 'apk add --no-cache${missing_packages}' before supabase/setup-cli, or run this job container as root."
exit 1
fi
apk add --no-cache ${missing_packages}
if echo " ${missing_packages} " | grep -Eq ' (nodejs|npm) '; then
echo "/usr/bin" >> "$GITHUB_PATH"
fi
exit 0
fi
echo "::error::Linux musl containers need libstdc++, libgcc, nodejs, and npm to run Supabase CLI. Install them before supabase/setup-cli."
exit 1
- id: node-runtime
name: Resolve Node Runtime
shell: sh
run: |
set -eu
node_version=""
node_major=""
has_npm=false
if command -v node >/dev/null 2>&1; then
node_version="$(node -p 'process.versions.node' 2>/dev/null || true)"
node_major="${node_version%%.*}"
fi
if command -v npm >/dev/null 2>&1; then
has_npm=true
fi
if [ -n "${node_version}" ] && [ "${has_npm}" = "true" ]; then
case "${node_major}" in
''|*[!0-9]*)
echo "::error::Could not determine Node.js version from '${node_version}'. Supabase CLI npm installs require Node.js 20 or newer."
exit 1
;;
esac
if [ "${node_major}" -lt 20 ]; then
echo "::error::Supabase CLI npm installs require Node.js 20 or newer, but found Node.js ${node_version}. Set up Node.js 20+ before supabase/setup-cli, or use a runner image with Node.js 20+ and npm."
exit 1
fi
echo "setup-node=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ steps.bun-download.outputs.is-musl }}" = "true" ]; then
echo "::error::Linux musl containers need Node.js 20 or newer and npm from musl-compatible packages. Install libstdc++, libgcc, nodejs, and npm before supabase/setup-cli, or run this job container as root so the action can install them."
exit 1
fi
if [ -n "${node_version}" ] || [ "${has_npm}" = "true" ]; then
echo "::error::Supabase CLI npm installs need both Node.js 20+ and npm. Found Node.js '${node_version:-missing}' and npm '${has_npm}'. Configure both before supabase/setup-cli."
exit 1
fi
echo "setup-node=true" >> "$GITHUB_OUTPUT"
- name: Setup Node
if: ${{ steps.node-runtime.outputs.setup-node == 'true' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: ${{ github.action_path }}/.bun-version
bun-download-url: ${{ steps.bun-download.outputs.url }}
- name: Install Action Dependencies
shell: sh
working-directory: ${{ github.action_path }}
run: bun install --frozen-lockfile --production
- id: setup-cli
name: Setup Supabase CLI
shell: sh
working-directory: ${{ github.action_path }}
env:
INPUT_VERSION: ${{ inputs.version }}
run: bun src/main.ts