Skip to content

Commit ebc8c5b

Browse files
committed
Update API to work with subdirectories
1 parent a903122 commit ebc8c5b

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

README.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,49 @@
22

33
This Action wraps the [Sanity CLI](https://github.com/sanity-io/sanity) for usage inside workflows.
44

5+
## Breaking change in `v0.3`
6+
7+
Prior to `v0.3`, all `args` would be appended to the `sanity` command in entrypoint.sh (meaning one or more `args` was required).
8+
9+
As of `v0.3`, entrypoint.sh requires at least two `args`. The first is used to specify the current directory (`.`) or a subdirectory (e.g., `studio`, as with a monorepo). All subsequent `args` are appended to the `sanity` command.
10+
11+
### Sample deployment snippet
12+
13+
Example snippet to run `sanity deploy`, where the studio is installed in a `studio` subdirectory (see below for full example):
14+
15+
```yaml
16+
# deploy-sanity-studio.yml
17+
18+
# ... other workflow commands ...
19+
20+
with:
21+
args: studio deploy
22+
```
23+
24+
This is _not_ running a command called `studio deploy`. Rather, it is running `cd studio` followed by `sanity deploy`.
25+
26+
---
27+
28+
### Sample backup snippet
29+
30+
Example snippet to run `sanity dataset export production backups/backup.tar.gz`, where the studio is installed at the root of the repository (see below for full example):
31+
32+
```yaml
33+
# sanity-backup.yml
34+
35+
# ... other workflow commands ...
36+
37+
with:
38+
args: . dataset export production backups/backup.tar.gz
39+
```
40+
41+
This will run `cd .` (remaining at the root of the repository) followed by `sanity dataset export production backups/backup.tar.gz`.
42+
543
## Usage
644

745
Below are two examples of usage. Do you use this GitHub Action for a different purpose? Submit a pull request!
846

9-
Depending on your use case, you will need to [generate a read or write token](https://www.sanity.io/docs/http-auth#robot-tokens-4c21d7b829fe) from your project's management console and then [add it as a secret](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository) in the Studio GitHub repository. In the examples below, the secret was named `SANITY_AUTH_TOKEN`.
47+
Depending on your use case, you will need to [generate a read or write token](https://www.sanity.io/docs/http-auth#4c21d7b829fe) from your project's management console and then [add it as a secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) in the Studio GitHub repository. In the examples below, the secret was named `SANITY_AUTH_TOKEN`.
1048

1149
### Studio deployment on push requests
1250

@@ -23,18 +61,20 @@ jobs:
2361
name: Deploy Sanity
2462
steps:
2563
- uses: actions/checkout@v2
26-
- uses: sanity-io/github-action-sanity@v0.2-alpha
64+
- uses: sanity-io/github-action-sanity@v0.3
2765
env:
2866
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
2967
with:
30-
args: deploy
68+
args: . deploy
3169
```
3270

71+
If your studio is in a subdirectory, replace `.` in `args` with the name of your subdirectory (e.g., `args: studio deploy`)
72+
3373
### Backup routine
3474

35-
Thanks to [scheduled events](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#schedule) and [artifacts](https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts), you can set up a simple backup routine.
75+
Thanks to [scheduled events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule) and [artifacts](https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts), you can set up a simple backup routine.
3676

37-
Backup files will appear as downloadable artifacts in the workflow summary. Keep in mind that artifacts are automatically deleted [after a certain period of time](https://docs.github.com/en/free-pro-team@latest/actions/reference/usage-limits-billing-and-administration#artifact-and-log-retention-policy) (after 90 days for public repositories).
77+
Backup files will appear as downloadable artifacts in the workflow summary. Keep in mind that artifacts are automatically deleted [after a certain period of time](https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#artifact-and-log-retention-policy) (after 90 days by default for public repositories).
3878

3979
_This workflow requires a read token._
4080

@@ -51,11 +91,11 @@ jobs:
5191
steps:
5292
- uses: actions/checkout@v2
5393
- name: Export dataset
54-
uses: sanity-io/github-action-sanity@v0.2-alpha
94+
uses: sanity-io/github-action-sanity@v0.3
5595
env:
5696
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
5797
with:
58-
args: dataset export production backups/backup.tar.gz
98+
args: . dataset export production backups/backup.tar.gz
5999
- name: Upload backup.tar.gz
60100
uses: actions/upload-artifact@v2
61101
with:

entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -e
44

5-
sh -c "sanity install && SANITY_AUTH_TOKEN=$SANITY_AUTH_TOKEN sanity $*"
5+
sh -c "cd $1 && sanity install && SANITY_AUTH_TOKEN=$SANITY_AUTH_TOKEN sanity ${@:2:99}"

0 commit comments

Comments
 (0)