mirror of
https://github.com/supabase/setup-cli.git
synced 2025-12-08 08:06:29 +00:00
Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a11fac2fe | ||
|
|
562d4d41dd | ||
|
|
5adad8121b | ||
|
|
81c1c5e51a | ||
|
|
a6e566c41f | ||
|
|
c0861c6efb | ||
|
|
cffb91a288 | ||
|
|
2bed722236 | ||
|
|
4e837d3e47 | ||
|
|
5b1cff838c | ||
|
|
20f0b4acc4 | ||
|
|
1529494aca | ||
|
|
ca64e55875 | ||
|
|
fcb5c378bf | ||
|
|
84a6f3b4aa | ||
|
|
b58d116558 | ||
|
|
4d1610fc08 | ||
|
|
c6c238ee33 | ||
|
|
f4e7a0a9c1 | ||
|
|
69852d2722 | ||
|
|
be22cd65de | ||
|
|
316f9d360a | ||
|
|
3dbdd67b65 | ||
|
|
63ebbbea57 | ||
|
|
2b30741fa4 | ||
|
|
4aeb6760b2 | ||
|
|
e54fb6d417 | ||
|
|
3d526af019 | ||
|
|
5a61b297ed | ||
|
|
319fcbc9fa | ||
|
|
16a4638a2d | ||
|
|
9d958279c7 | ||
|
|
5f72883819 | ||
|
|
800591067e | ||
|
|
d5b89739ea | ||
|
|
51bce609b0 | ||
|
|
8c367f4e1e | ||
|
|
6333c3ad34 | ||
|
|
8b3b75ec99 | ||
|
|
8063edec5e | ||
|
|
d1164a571c | ||
|
|
f7a48658a9 | ||
|
|
013774d7d3 | ||
|
|
0f5e0d0baa | ||
|
|
ceb5052778 | ||
|
|
c8cd7a03b4 | ||
|
|
57c56478ca | ||
|
|
5d9fef7ab8 | ||
|
|
3da7e3232b | ||
|
|
a3322b63a7 | ||
|
|
218a5451ba | ||
|
|
e990a6e26d | ||
|
|
73c42f5dba | ||
|
|
3a4bba5a28 | ||
|
|
0e780eb864 | ||
|
|
f81d675039 | ||
|
|
6718044ec1 | ||
|
|
7d56f2db9d | ||
|
|
d7efa72006 | ||
|
|
ee5499d01d | ||
|
|
9f63332370 | ||
|
|
a62fb52b38 | ||
|
|
cd1e126b6f | ||
|
|
10ad2f1d23 | ||
|
|
3d32144eb9 | ||
|
|
a1b47ce810 | ||
|
|
f048ce30f1 | ||
|
|
1b71a28a2c | ||
|
|
ea547232eb | ||
|
|
0862b396ee | ||
|
|
13f2fdc1d3 | ||
|
|
bf3ce30bf7 | ||
|
|
26598ee1fd | ||
|
|
108ac2dc5f | ||
|
|
e0fe0493e6 |
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3.6.0
|
||||
uses: actions/setup-node@v3.7.0
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: npm
|
||||
|
||||
2
.github/workflows/dependabot.yml
vendored
2
.github/workflows/dependabot.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
# will not occur.
|
||||
- name: Dependabot metadata
|
||||
id: dependabot-metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
uses: dependabot/fetch-metadata@v1.6.0
|
||||
with:
|
||||
github-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
|
||||
|
||||
@@ -117,10 +117,11 @@ Actions are run from GitHub repos so we will checkin the packed dist folder.
|
||||
Then run [ncc](https://github.com/zeit/ncc) and push the results:
|
||||
|
||||
```bash
|
||||
$ npm run package
|
||||
$ npm run all
|
||||
$ git add dist
|
||||
$ git commit -a -m "Update dependencies"
|
||||
$ git push origin releases/v1
|
||||
$ git tag -f v1
|
||||
$ git push -f --tags
|
||||
```
|
||||
|
||||
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
|
||||
|
||||
@@ -6,6 +6,9 @@ inputs:
|
||||
description: Version of Supabase CLI to install
|
||||
required: false
|
||||
default: 1.28.3
|
||||
outputs:
|
||||
version:
|
||||
description: Version of installed Supabase CLI
|
||||
runs:
|
||||
using: node16
|
||||
main: dist/index.js
|
||||
|
||||
17
dist/index.js
generated
vendored
17
dist/index.js
generated
vendored
@@ -60,6 +60,9 @@ function run() {
|
||||
const pathToCLI = yield tc.extractTar(pathToTarball);
|
||||
// Expose the tool by adding it to the PATH
|
||||
core.addPath(pathToCLI);
|
||||
// Expose installed tool version
|
||||
const determinedVersion = yield (0, utils_1.determineInstalledVersion)();
|
||||
core.setOutput('version', determinedVersion);
|
||||
// Use GHCR mirror by default
|
||||
if (version.toLowerCase() === 'latest' || (0, gte_1.default)(version, '1.28.0')) {
|
||||
core.exportVariable(exports.CLI_CONFIG_REGISTRY, 'ghcr.io');
|
||||
@@ -94,9 +97,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getDownloadUrl = void 0;
|
||||
exports.determineInstalledVersion = exports.getDownloadUrl = void 0;
|
||||
const child_process_1 = __nccwpck_require__(2081);
|
||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||
const lt_1 = __importDefault(__nccwpck_require__(194));
|
||||
const util_1 = __nccwpck_require__(3837);
|
||||
const doExec = (0, util_1.promisify)(child_process_1.exec);
|
||||
// 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) => {
|
||||
@@ -126,6 +132,15 @@ const getDownloadUrl = (version) => __awaiter(void 0, void 0, void 0, function*
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}`;
|
||||
});
|
||||
exports.getDownloadUrl = getDownloadUrl;
|
||||
const determineInstalledVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { stdout } = yield doExec('supabase --version');
|
||||
const version = stdout.trim();
|
||||
if (!version) {
|
||||
throw new Error('Could not determine installed Supabase CLI version');
|
||||
}
|
||||
return version;
|
||||
});
|
||||
exports.determineInstalledVersion = determineInstalledVersion;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
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
83
docs/backups.md
Normal file
83
docs/backups.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# Backup your database
|
||||
|
||||
You can use the Supabase CLI to backup your Postgres database. The steps involve running a series of commands to dump roles, schema, and data separately.
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `backup.yml`. Copy the following snippet inside the file, and the action will run whenever a new PR is created.
|
||||
|
||||
!!! note
|
||||
|
||||
Never backup your data to a public repository.
|
||||
|
||||
## Backup action
|
||||
|
||||
```yaml
|
||||
name: 'backup-database'
|
||||
on:
|
||||
pull_request:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # For example: postgresql://postgres:[YOUR-PASSWORD]@db.<ref>.supabase.co:5432/postgres
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- name: Backup roles
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f roles.sql --role-only
|
||||
- name: Backup schema
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f schema.sql
|
||||
- name: Backup data
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f data.sql --data-only --use-copy
|
||||
```
|
||||
## Periodic Backups Workflow
|
||||
|
||||
You can use the GitHub Action to run periodic backups of your database. In this example, the Action workflow is triggered by `push` and `pull_request` events on the `main` branch, manually via `workflow_dispatch`, and automatically at midnight every day due to the `schedule` event with a `cron` expression.
|
||||
The workflow runs on the latest Ubuntu runner and requires write permissions to the repository's contents. It uses the Supabase CLI to dump the roles, schema, and data from your Supabase database, utilizing the `SUPABASE_DB_URL` environment variable that is securely stored in the GitHub secrets.
|
||||
After the backup is complete, it auto-commits the changes to the repository using the `git-auto-commit-action`. This ensures that the latest backup is always available in your repository. The commit message for these automated commits is "Supabase backup".
|
||||
This workflow provides an automated solution for maintaining regular backups of your Supabase database. It helps keep your data safe and enables easy restoration in case of any accidental data loss or corruption.
|
||||
|
||||
!!! note
|
||||
|
||||
Never backup your data to a public repository.
|
||||
|
||||
```yaml
|
||||
name: Supa-backup
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 0 * * *' # Runs every day at midnight
|
||||
jobs:
|
||||
run_db_backup:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }} # For example: postgresql://postgres:[YOUR-PASSWORD]@db.<ref>.supabase.co:5432/postgres
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- name: Backup roles
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f roles.sql --role-only
|
||||
- name: Backup schema
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f schema.sql
|
||||
- name: Backup data
|
||||
run: supabase db dump --db-url "$supabase_db_url" -f data.sql --data-only --use-copy
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: Supabase backup
|
||||
```
|
||||
|
||||
## More resources
|
||||
|
||||
- Backing up and migrating your project: [Migrating and Upgrading](https://supabase.com/docs/guides/platform/migrating-and-upgrading-projects)
|
||||
36
docs/generating-types.md
Normal file
36
docs/generating-types.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generating Types
|
||||
|
||||
You can use the Supabase CLI to automatically generate Typescript definitions from your Postgres database. You can then pass these definitions to your `supabase-js` client and get end-to-end type safety across client, server, and database.
|
||||
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `generate-types.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||
|
||||
## Verify types
|
||||
|
||||
```yaml
|
||||
name: 'generate-types'
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
- name: Verify generated types match Postgres schema
|
||||
run: |
|
||||
supabase gen types typescript --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
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
|
||||
## More resources
|
||||
|
||||
- Using supabase-js with type definitions: [Typescript Support](https://supabase.com/docs/reference/javascript/typescript-support)
|
||||
35
docs/index.md
Normal file
35
docs/index.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# `supabase-github-action`
|
||||
|
||||
The Supabase GitHub Action provides an easy way to use the Supabase CLI on GitHub's hosted Actions runners.
|
||||
|
||||
The action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners, and will install and expose a specified version of the Supabase CLI on the runner environment.
|
||||
|
||||
## Quick start
|
||||
|
||||
This example shows how you can use the Supabase GitHub Action to test your migrations on every Pull Request.
|
||||
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `test-migrations.yml`.
|
||||
|
||||
Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||
|
||||
```yaml
|
||||
name: 'test-migrations'
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
```
|
||||
|
||||
|
||||
## Resources
|
||||
|
||||
- **Source Code**: <a href="https://github.com/supabase/supabase-github-action" target="_blank">github.com/supabase/supabase-github-action</a>
|
||||
- **CLI Documentation**: <a href="https://supabase.com/docs/guides/cli" target="_blank">supabase.com/docs/guides/cli</a>
|
||||
25
docs/migrations.md
Normal file
25
docs/migrations.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Managing database migrations
|
||||
|
||||
Migrations are programmatic changes to your database. They are usually checked into Git.
|
||||
|
||||
## Testing your migrations
|
||||
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `test-migrations.yml`.
|
||||
|
||||
Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||
|
||||
```yaml
|
||||
name: 'test-migrations'
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
```
|
||||
59
docs/testing.md
Normal file
59
docs/testing.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Automated testing
|
||||
|
||||
You can use the Supabase CLI to run automated tests.
|
||||
|
||||
## Testing your database
|
||||
|
||||
After you have [created unit tests](https://supabase.com/docs/guides/database/testing) for your database, you can use the GitHub Action to run the tests.
|
||||
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `database-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||
|
||||
```yaml
|
||||
name: 'database-tests'
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase db start
|
||||
- run: supabase test db
|
||||
|
||||
```
|
||||
|
||||
## Testing your Edge Functions
|
||||
|
||||
After you have [created unit tests](https://supabase.com/docs/guides/functions/unit-test) for your Edge Functions, you can use the GitHub Action to run the tests.
|
||||
|
||||
Inside your repository, create a new file inside the `.github/workflows` folder called `functions-tests.yml`. Copy this snippet inside the file, and the action will run whenever a new PR is created:
|
||||
|
||||
```yaml
|
||||
name: 'functions-tests'
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: latest
|
||||
- uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: latest
|
||||
- run: supabase start
|
||||
- run: deno test --allow-all deno-test.ts --env-file .env.local
|
||||
|
||||
```
|
||||
|
||||
## More resources
|
||||
|
||||
- Learn more about the [pgTAP extension](https://supabase.com/docs/guides/database/extensions/pgtap) for database testing.
|
||||
- Official pgTAP Documentation: [pgtap.org](https://pgtap.org/)
|
||||
34
mkdocs.yaml
Normal file
34
mkdocs.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
site_name: supabase-github-action
|
||||
site_url: https://supabase.github.io/supabase-github-action
|
||||
site_description: A GitHub action for interacting with your Supabase projects using the CLI.
|
||||
|
||||
repo_name: supabase/supabase-github-action
|
||||
repo_url: https://github.com/supabase/supabase-github-action
|
||||
|
||||
nav:
|
||||
- Welcome: 'index.md'
|
||||
- Quickstart: 'migrations.md'
|
||||
|
||||
theme:
|
||||
name: 'material'
|
||||
features:
|
||||
- navigation.expand
|
||||
favicon: 'assets/favicon.ico'
|
||||
logo: 'assets/favicon.ico'
|
||||
homepage: https://supabase.github.io/supabase-github-action
|
||||
palette:
|
||||
primary: black
|
||||
accent: light green
|
||||
|
||||
markdown_extensions:
|
||||
- pymdownx.highlight:
|
||||
linenums: true
|
||||
guess_lang: false
|
||||
use_pygments: true
|
||||
pygments_style: default
|
||||
- pymdownx.superfences
|
||||
- pymdownx.tabbed:
|
||||
alternate_style: true
|
||||
- pymdownx.snippets
|
||||
- pymdownx.tasklist
|
||||
- admonition
|
||||
1693
package-lock.json
generated
1693
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -27,20 +27,20 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"semver": "^7.3.8"
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/node": "^16.11.47",
|
||||
"@types/semver": "^7.3.13",
|
||||
"@typescript-eslint/parser": "^5.49.0",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-plugin-github": "^4.6.0",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-plugin-github": "^4.9.0",
|
||||
"eslint-plugin-jest": "^27.2.3",
|
||||
"jest": "^28.1.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "2.8.3",
|
||||
"prettier": "2.8.8",
|
||||
"ts-jest": "^28.0.8",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import gte from 'semver/functions/gte'
|
||||
import {getDownloadUrl} from './utils'
|
||||
import {getDownloadUrl, determineInstalledVersion} from './utils'
|
||||
|
||||
export const CLI_CONFIG_REGISTRY = 'SUPABASE_INTERNAL_IMAGE_REGISTRY'
|
||||
|
||||
@@ -20,6 +20,10 @@ async function run(): Promise<void> {
|
||||
// Expose the tool by adding it to the PATH
|
||||
core.addPath(pathToCLI)
|
||||
|
||||
// Expose installed tool version
|
||||
const determinedVersion = await determineInstalledVersion()
|
||||
core.setOutput('version', determinedVersion)
|
||||
|
||||
// Use GHCR mirror by default
|
||||
if (version.toLowerCase() === 'latest' || gte(version, '1.28.0')) {
|
||||
core.exportVariable(CLI_CONFIG_REGISTRY, 'ghcr.io')
|
||||
|
||||
15
src/utils.ts
15
src/utils.ts
@@ -1,5 +1,9 @@
|
||||
import {exec} from 'child_process'
|
||||
import os from 'os'
|
||||
import lt from 'semver/functions/lt'
|
||||
import {promisify} from 'util'
|
||||
|
||||
const doExec = promisify(exec)
|
||||
|
||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||
// return value in [amd64, arm64, arm]
|
||||
@@ -31,3 +35,14 @@ export const getDownloadUrl = async (version: string): Promise<string> => {
|
||||
}
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}`
|
||||
}
|
||||
|
||||
export const determineInstalledVersion = async (): Promise<string> => {
|
||||
const {stdout} = await doExec('supabase --version')
|
||||
|
||||
const version = stdout.trim()
|
||||
if (!version) {
|
||||
throw new Error('Could not determine installed Supabase CLI version')
|
||||
}
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user