mirror of
https://github.com/supabase/setup-cli.git
synced 2026-06-29 10:27:05 +00:00
Compare commits
4 Commits
v1.6.1
...
bump-defau
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a35ea70530 | ||
|
|
d3753c9dbc | ||
|
|
d9e25d90f6 | ||
|
|
dadb6ee5a7 |
11
README.md
11
README.md
@@ -34,7 +34,7 @@ A specific version of the `supabase` CLI can be installed:
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: 2.20.3
|
||||
version: 2.33.0
|
||||
```
|
||||
|
||||
Run `supabase db start` to execute all migrations on a fresh database:
|
||||
@@ -44,8 +44,9 @@ steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
# Optionally connect to the local database using psql
|
||||
- run: psql 'postgres://postgres:postgres@localhost:54322/postgres' -c ''
|
||||
```
|
||||
|
||||
Since Supabase CLI relies on Docker Engine API, additional setup may be required
|
||||
@@ -57,7 +58,7 @@ The actions supports the following inputs:
|
||||
|
||||
| Name | Type | Description | Default | Required |
|
||||
| --------- | ------ | ---------------------------------- | -------- | -------- |
|
||||
| `version` | String | Supabase CLI version (or `latest`) | `2.20.3` | false |
|
||||
| `version` | String | Supabase CLI version (or `latest`) | `2.33.0` | false |
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
@@ -66,11 +67,10 @@ Check generated TypeScript types are up-to-date with Postgres schema:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
- name: Verify generated types match Postgres schema
|
||||
run: |
|
||||
supabase gen types typescript --local > schema.gen.ts
|
||||
supabase gen types --local > schema.gen.ts
|
||||
if ! git diff --ignore-space-at-eol --exit-code --quiet schema.gen.ts; then
|
||||
echo "Detected uncommitted changes after build. See status below:"
|
||||
git diff
|
||||
@@ -83,6 +83,7 @@ Release job to push schema changes to a Supabase project:
|
||||
```yaml
|
||||
env:
|
||||
SUPABASE_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
# Optionally set the postgres password for linking project database
|
||||
SUPABASE_DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
# Retrieve <project-id> from dashboard url: https://app.supabase.com/project/<project-id>
|
||||
PROJECT_ID: <project-id>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDownloadArchive, getDownloadUrl } from '../src/utils'
|
||||
import { getDownloadUrl } from '../src/utils'
|
||||
import { CLI_CONFIG_REGISTRY } from '../src/main'
|
||||
import * as os from 'os'
|
||||
import * as process from 'process'
|
||||
@@ -7,11 +7,7 @@ import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as url from 'url'
|
||||
import { afterEach, expect, jest, test } from '@jest/globals'
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
import { expect, test } from '@jest/globals'
|
||||
|
||||
test('gets download url to binary', async () => {
|
||||
const url = await getDownloadUrl('1.28.0')
|
||||
@@ -35,42 +31,10 @@ test('gets legacy download url to binary', async () => {
|
||||
})
|
||||
|
||||
test('gets download url to latest version', async () => {
|
||||
jest.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify({ tag_name: 'v2.99.0' }), {
|
||||
status: 200,
|
||||
statusText: 'OK'
|
||||
})
|
||||
)
|
||||
|
||||
const url = await getDownloadUrl('latest')
|
||||
expect(url).toContain('/download/v2.99.0/supabase_2.99.0_')
|
||||
expect(url).toMatch(/\.tar\.gz$|\.zip$/)
|
||||
})
|
||||
|
||||
test('gets versioned archive url to binary from Supabase CLI v2.99.0', async () => {
|
||||
const archive = await getDownloadArchive('2.99.0', 'linux', 'x64')
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: 'https://github.com/supabase/cli/releases/download/v2.99.0/supabase_2.99.0_linux_amd64.tar.gz',
|
||||
format: 'tar'
|
||||
})
|
||||
})
|
||||
|
||||
test('gets versioned zip archive url on Windows from Supabase CLI v2.99.0', async () => {
|
||||
const archive = await getDownloadArchive('2.99.0', 'win32', 'x64')
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: 'https://github.com/supabase/cli/releases/download/v2.99.0/supabase_2.99.0_windows_amd64.zip',
|
||||
format: 'zip'
|
||||
})
|
||||
})
|
||||
|
||||
test('keeps unversioned archive url to binary before Supabase CLI v2.99.0', async () => {
|
||||
const url = await getDownloadUrl('2.98.2')
|
||||
|
||||
expect(url).toContain('/download/v2.98.2/supabase_')
|
||||
expect(url).not.toContain('supabase_2.98.2_')
|
||||
expect(url).toMatch(/\.tar\.gz$/)
|
||||
expect(url).toMatch(
|
||||
'https://github.com/supabase/cli/releases/latest/download/'
|
||||
)
|
||||
})
|
||||
|
||||
// shows how the runner will run a javascript action with env / stdout protocol
|
||||
|
||||
@@ -5,7 +5,7 @@ inputs:
|
||||
version:
|
||||
description: Version of Supabase CLI to install
|
||||
required: false
|
||||
default: 2.20.3
|
||||
default: 2.33.0
|
||||
outputs:
|
||||
version:
|
||||
description: Version of installed Supabase CLI
|
||||
|
||||
54
dist/index.js
generated
vendored
54
dist/index.js
generated
vendored
@@ -32518,8 +32518,6 @@ function requireSemver () {
|
||||
var semverExports = requireSemver();
|
||||
|
||||
const doExec = promisify(exec$1);
|
||||
const VERSIONED_ARCHIVE_VERSION = '2.99.0';
|
||||
const LATEST_RELEASE_URL = 'https://api.github.com/repos/supabase/cli/releases/latest';
|
||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||
// return value in [amd64, arm64, arm]
|
||||
const mapArch = (arch) => {
|
||||
@@ -32536,45 +32534,17 @@ const mapOS = (platform) => {
|
||||
};
|
||||
return mappings[platform] || platform;
|
||||
};
|
||||
const normalizeVersion = (version) => version.replace(/^v/i, '');
|
||||
const resolveLatestVersion = async () => {
|
||||
const response = await fetch(LATEST_RELEASE_URL);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to resolve latest Supabase CLI release: ${response.statusText}`);
|
||||
const getDownloadUrl = async (version) => {
|
||||
const platform = mapOS(require$$0.platform());
|
||||
const arch = mapArch(require$$0.arch());
|
||||
const filename = `supabase_${platform}_${arch}.tar.gz`;
|
||||
if (version.toLowerCase() === 'latest') {
|
||||
return `https://github.com/supabase/cli/releases/latest/download/${filename}`;
|
||||
}
|
||||
const release = (await response.json());
|
||||
if (typeof release.tag_name !== 'string') {
|
||||
throw new Error('Failed to resolve latest Supabase CLI release: missing tag name');
|
||||
}
|
||||
return normalizeVersion(release.tag_name);
|
||||
};
|
||||
const getArchiveFormat = (version, platform) => {
|
||||
if (platform === 'win32' && semverExports.gte(version, VERSIONED_ARCHIVE_VERSION)) {
|
||||
return 'zip';
|
||||
}
|
||||
return 'tar';
|
||||
};
|
||||
const getArchiveFilename = (version, platform, arch) => {
|
||||
const archivePlatform = mapOS(platform);
|
||||
const archiveArch = mapArch(arch);
|
||||
if (semverExports.lt(version, '1.28.0')) {
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.tar.gz`;
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/supabase_${version}_${platform}_${arch}.tar.gz`;
|
||||
}
|
||||
if (semverExports.gte(version, VERSIONED_ARCHIVE_VERSION)) {
|
||||
const extension = platform === 'win32' ? 'zip' : 'tar.gz';
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.${extension}`;
|
||||
}
|
||||
return `supabase_${archivePlatform}_${archiveArch}.tar.gz`;
|
||||
};
|
||||
const getDownloadArchive = async (version, platform = require$$0.platform(), arch = require$$0.arch()) => {
|
||||
const resolvedVersion = version.toLowerCase() === 'latest'
|
||||
? await resolveLatestVersion()
|
||||
: normalizeVersion(version);
|
||||
const filename = getArchiveFilename(resolvedVersion, platform, arch);
|
||||
return {
|
||||
url: `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}`,
|
||||
format: getArchiveFormat(resolvedVersion, platform)
|
||||
};
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}`;
|
||||
};
|
||||
const determineInstalledVersion = async () => {
|
||||
const { stdout } = await doExec('supabase --version');
|
||||
@@ -32596,12 +32566,10 @@ async function run() {
|
||||
// Get version of tool to be installed
|
||||
const version = coreExports.getInput('version');
|
||||
// Download the specific version of the tool, e.g. as a tarball/zipball
|
||||
const download = await getDownloadArchive(version);
|
||||
const pathToArchive = await toolCacheExports.downloadTool(download.url);
|
||||
const download = await getDownloadUrl(version);
|
||||
const pathToTarball = await toolCacheExports.downloadTool(download);
|
||||
// Extract the tarball/zipball onto host runner
|
||||
const pathToCLI = download.format === 'zip'
|
||||
? await toolCacheExports.extractZip(pathToArchive)
|
||||
: await toolCacheExports.extractTar(pathToArchive);
|
||||
const pathToCLI = await toolCacheExports.extractTar(pathToTarball);
|
||||
// Expose the tool by adding it to the PATH
|
||||
coreExports.addPath(pathToCLI);
|
||||
// Expose installed tool version
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
11
src/main.ts
11
src/main.ts
@@ -1,7 +1,7 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import { gte } from 'semver'
|
||||
import { getDownloadArchive, determineInstalledVersion } from './utils.js'
|
||||
import { getDownloadUrl, determineInstalledVersion } from './utils.js'
|
||||
|
||||
export const CLI_CONFIG_REGISTRY = 'SUPABASE_INTERNAL_IMAGE_REGISTRY'
|
||||
|
||||
@@ -16,14 +16,11 @@ export async function run(): Promise<void> {
|
||||
const version = core.getInput('version')
|
||||
|
||||
// Download the specific version of the tool, e.g. as a tarball/zipball
|
||||
const download = await getDownloadArchive(version)
|
||||
const pathToArchive = await tc.downloadTool(download.url)
|
||||
const download = await getDownloadUrl(version)
|
||||
const pathToTarball = await tc.downloadTool(download)
|
||||
|
||||
// Extract the tarball/zipball onto host runner
|
||||
const pathToCLI =
|
||||
download.format === 'zip'
|
||||
? await tc.extractZip(pathToArchive)
|
||||
: await tc.extractTar(pathToArchive)
|
||||
const pathToCLI = await tc.extractTar(pathToTarball)
|
||||
|
||||
// Expose the tool by adding it to the PATH
|
||||
core.addPath(pathToCLI)
|
||||
|
||||
88
src/utils.ts
88
src/utils.ts
@@ -1,19 +1,9 @@
|
||||
import { exec } from 'child_process'
|
||||
import os from 'os'
|
||||
import { gte, lt } from 'semver'
|
||||
import { lt } from 'semver'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const doExec = promisify(exec)
|
||||
const VERSIONED_ARCHIVE_VERSION = '2.99.0'
|
||||
const LATEST_RELEASE_URL =
|
||||
'https://api.github.com/repos/supabase/cli/releases/latest'
|
||||
|
||||
export type ArchiveFormat = 'tar' | 'zip'
|
||||
|
||||
export type DownloadArchive = {
|
||||
url: string
|
||||
format: ArchiveFormat
|
||||
}
|
||||
|
||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||
// return value in [amd64, arm64, arm]
|
||||
@@ -33,73 +23,17 @@ const mapOS = (platform: string): string => {
|
||||
return mappings[platform] || platform
|
||||
}
|
||||
|
||||
const normalizeVersion = (version: string): string => version.replace(/^v/i, '')
|
||||
|
||||
const resolveLatestVersion = async (): Promise<string> => {
|
||||
const response = await fetch(LATEST_RELEASE_URL)
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to resolve latest Supabase CLI release: ${response.statusText}`
|
||||
)
|
||||
}
|
||||
|
||||
const release = (await response.json()) as { tag_name?: unknown }
|
||||
if (typeof release.tag_name !== 'string') {
|
||||
throw new Error(
|
||||
'Failed to resolve latest Supabase CLI release: missing tag name'
|
||||
)
|
||||
}
|
||||
|
||||
return normalizeVersion(release.tag_name)
|
||||
}
|
||||
|
||||
const getArchiveFormat = (version: string, platform: string): ArchiveFormat => {
|
||||
if (platform === 'win32' && gte(version, VERSIONED_ARCHIVE_VERSION)) {
|
||||
return 'zip'
|
||||
}
|
||||
|
||||
return 'tar'
|
||||
}
|
||||
|
||||
const getArchiveFilename = (
|
||||
version: string,
|
||||
platform: string,
|
||||
arch: string
|
||||
): string => {
|
||||
const archivePlatform = mapOS(platform)
|
||||
const archiveArch = mapArch(arch)
|
||||
if (lt(version, '1.28.0')) {
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.tar.gz`
|
||||
}
|
||||
|
||||
if (gte(version, VERSIONED_ARCHIVE_VERSION)) {
|
||||
const extension = platform === 'win32' ? 'zip' : 'tar.gz'
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.${extension}`
|
||||
}
|
||||
|
||||
return `supabase_${archivePlatform}_${archiveArch}.tar.gz`
|
||||
}
|
||||
|
||||
export const getDownloadArchive = async (
|
||||
version: string,
|
||||
platform = os.platform(),
|
||||
arch = os.arch()
|
||||
): Promise<DownloadArchive> => {
|
||||
const resolvedVersion =
|
||||
version.toLowerCase() === 'latest'
|
||||
? await resolveLatestVersion()
|
||||
: normalizeVersion(version)
|
||||
const filename = getArchiveFilename(resolvedVersion, platform, arch)
|
||||
|
||||
return {
|
||||
url: `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}`,
|
||||
format: getArchiveFormat(resolvedVersion, platform)
|
||||
}
|
||||
}
|
||||
|
||||
export const getDownloadUrl = async (version: string): Promise<string> => {
|
||||
const archive = await getDownloadArchive(version)
|
||||
return archive.url
|
||||
const platform = mapOS(os.platform())
|
||||
const arch = mapArch(os.arch())
|
||||
const filename = `supabase_${platform}_${arch}.tar.gz`
|
||||
if (version.toLowerCase() === 'latest') {
|
||||
return `https://github.com/supabase/cli/releases/latest/download/${filename}`
|
||||
}
|
||||
if (lt(version, '1.28.0')) {
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/supabase_${version}_${platform}_${arch}.tar.gz`
|
||||
}
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}`
|
||||
}
|
||||
|
||||
export const determineInstalledVersion = async (): Promise<string> => {
|
||||
|
||||
Reference in New Issue
Block a user