mirror of
https://github.com/supabase/setup-cli.git
synced 2025-12-09 20:36:26 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a11fac2fe | ||
|
|
562d4d41dd | ||
|
|
5adad8121b | ||
|
|
81c1c5e51a | ||
|
|
a6e566c41f | ||
|
|
c0861c6efb | ||
|
|
cffb91a288 | ||
|
|
2bed722236 | ||
|
|
4e837d3e47 | ||
|
|
5b1cff838c | ||
|
|
20f0b4acc4 | ||
|
|
1529494aca |
10
.github/workflows/check-dist.yml
vendored
10
.github/workflows/check-dist.yml
vendored
@@ -21,12 +21,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 20.x
|
||||
uses: actions/setup-node@v4.0.2
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3.7.0
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 16.x
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
id: diff
|
||||
|
||||
# If index.js was different than expected, upload the expected version as an artifact
|
||||
- uses: actions/upload-artifact@v4
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
with:
|
||||
name: dist
|
||||
|
||||
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
@@ -38,11 +38,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
source-root: src
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -68,4 +68,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
||||
6
.github/workflows/dependabot.yml
vendored
6
.github/workflows/dependabot.yml
vendored
@@ -1,7 +1,7 @@
|
||||
# Adapted from https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enable-auto-merge-on-a-pull-request
|
||||
# Adapted from https://blog.somewhatabstract.com/2021/10/11/setting-up-dependabot-with-github-actions-to-approve-and-merge/
|
||||
name: Dependabot auto-merge
|
||||
|
||||
on: pull_request
|
||||
on: pull_request_target
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
# will not occur.
|
||||
- name: Dependabot metadata
|
||||
id: dependabot-metadata
|
||||
uses: dependabot/fetch-metadata@v2.1.0
|
||||
uses: dependabot/fetch-metadata@v1.6.0
|
||||
with:
|
||||
github-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
|
||||
|
||||
9
.github/workflows/start.yml
vendored
9
.github/workflows/start.yml
vendored
@@ -8,7 +8,6 @@ on:
|
||||
schedule:
|
||||
# * is a special character in YAML so you have to quote this string
|
||||
- cron: '30 1,9 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
defaults:
|
||||
run:
|
||||
@@ -20,16 +19,12 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
version:
|
||||
- 1.178.2
|
||||
- 1.0.0
|
||||
- latest
|
||||
pg_major:
|
||||
- 14
|
||||
- 15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
- run: supabase init
|
||||
- run: sed -i -E "s|^(major_version) .*|\1 = ${{ matrix.pg_major }}|" supabase/config.toml
|
||||
- run: supabase start
|
||||
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
build: # make sure build/ci work properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- run: npm install
|
||||
- run: npm run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
@@ -23,7 +23,7 @@ jobs:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
version: [1.0.0, latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
|
||||
23
README.md
23
README.md
@@ -5,7 +5,7 @@
|
||||
|
||||
## About
|
||||
|
||||
This action sets up the Supabase CLI, [`supabase`](https://github.com/supabase/cli), on GitHub's hosted Actions runners. Other CI runners like [BitBucket](https://bitbucket.org/supabase-cli/setup-cli/src/master/bitbucket-pipelines.yml) and [GitLab](https://gitlab.com/sweatybridge/setup-cli/-/blob/main/.gitlab-ci.yml) are supported via their respective pipelines.
|
||||
This action sets up the Supabase CLI, [`supabase`](https://github.com/supabase/cli), on GitHub's hosted Actions runners.
|
||||
|
||||
This 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.
|
||||
|
||||
@@ -24,7 +24,7 @@ A specific version of the `supabase` CLI can be installed:
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
version: 1.178.2
|
||||
version: 1.28.3
|
||||
```
|
||||
|
||||
Run `supabase db start` to execute all migrations on a fresh database:
|
||||
@@ -44,9 +44,9 @@ Since Supabase CLI relies on Docker Engine API, additional setup may be required
|
||||
|
||||
The actions supports the following inputs:
|
||||
|
||||
| Name | Type | Description | Default | Required |
|
||||
| --------- | ------ | ---------------------------------- | --------- | -------- |
|
||||
| `version` | String | Supabase CLI version (or `latest`) | `1.178.2` | false |
|
||||
| Name | Type | Description | Default | Required |
|
||||
| --------- | ------ | ---------------------------------- | -------- | -------- |
|
||||
| `version` | String | Supabase CLI version (or `latest`) | `1.28.3` | false |
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
@@ -114,8 +114,17 @@ $ npm test
|
||||
|
||||
Actions are run from GitHub repos so we will checkin the packed dist folder.
|
||||
|
||||
1. Create a new GitHub release
|
||||
2. Rebase `v1` branch on `main`
|
||||
Then run [ncc](https://github.com/zeit/ncc) and push the results:
|
||||
|
||||
```bash
|
||||
$ npm run all
|
||||
$ git add dist
|
||||
$ git commit -a -m "Update dependencies"
|
||||
$ 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.
|
||||
|
||||
Your action is now published! :rocket:
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ inputs:
|
||||
version:
|
||||
description: Version of Supabase CLI to install
|
||||
required: false
|
||||
default: 1.178.2
|
||||
default: 1.28.3
|
||||
outputs:
|
||||
version:
|
||||
description: Version of installed Supabase CLI
|
||||
runs:
|
||||
using: node20
|
||||
using: node16
|
||||
main: dist/index.js
|
||||
|
||||
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)
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: supabase/setup-cli@v1
|
||||
with:
|
||||
with:
|
||||
version: latest
|
||||
- run: supabase init
|
||||
- run: supabase db start
|
||||
@@ -32,4 +32,4 @@ jobs:
|
||||
## 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>
|
||||
- **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/)
|
||||
@@ -7,6 +7,7 @@ repo_url: https://github.com/supabase/supabase-github-action
|
||||
|
||||
nav:
|
||||
- Welcome: 'index.md'
|
||||
- Quickstart: 'migrations.md'
|
||||
|
||||
theme:
|
||||
name: 'material'
|
||||
|
||||
809
package-lock.json
generated
809
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -25,19 +25,19 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"semver": "^7.6.2"
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/node": "^16.11.47",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-plugin-github": "^4.9.0",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-jest": "^27.2.3",
|
||||
"jest": "^28.1.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "2.8.8",
|
||||
|
||||
Reference in New Issue
Block a user