Skip to content

Commit ab4cb19

Browse files
committed
Modify API to work with subdirectories
1 parent a903122 commit ab4cb19

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,39 @@
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` script.
10+
11+
Example snippet to run `sanity deploy`, where the studio is installed in a `studio` subdirectory:
12+
13+
```yaml
14+
# Other workflow commands
15+
16+
with:
17+
args: studio deploy
18+
```
19+
20+
This is not running a command called `studio deploy`. Rather, it is running `cd studio` followed by `sanity deploy`.
21+
22+
Example snippet to run `sanity dataset export production backups/backup.tar.gz`, where the studio is installed at the root of the repository:
23+
24+
```yaml
25+
# Other workflow commands
26+
27+
with:
28+
args: . dataset export production backups/backup.tar.gz
29+
```
30+
31+
This will run `cd .` (staying in the current directory) followed by `sanity dataset export production backups/backup.tar.gz`.
32+
533
## Usage
634

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

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`.
37+
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`.
1038

1139
### Studio deployment on push requests
1240

@@ -23,18 +51,20 @@ jobs:
2351
name: Deploy Sanity
2452
steps:
2553
- uses: actions/checkout@v2
26-
- uses: sanity-io/github-action-sanity@v0.2-alpha
54+
- uses: sanity-io/github-action-sanity@v0.3
2755
env:
2856
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
2957
with:
30-
args: deploy
58+
args: . deploy
3159
```
3260

61+
If your studio is in a subdirectory, replace `.` in `args` with the name of your subdirectory (e.g., `args: studio deploy`)
62+
3363
### Backup routine
3464

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.
65+
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.
3666

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).
67+
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).
3868

3969
_This workflow requires a read token._
4070

@@ -51,11 +81,11 @@ jobs:
5181
steps:
5282
- uses: actions/checkout@v2
5383
- name: Export dataset
54-
uses: sanity-io/github-action-sanity@v0.2-alpha
84+
uses: sanity-io/github-action-sanity@v0.3
5585
env:
5686
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
5787
with:
58-
args: dataset export production backups/backup.tar.gz
88+
args: . dataset export production backups/backup.tar.gz
5989
- name: Upload backup.tar.gz
6090
uses: actions/upload-artifact@v2
6191
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)