@marktiderman/genesis-cli 1.22.1 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -2
- package/dist/cli.js +382 -45
- package/dist/cli.js.map +1 -1
- package/dist/{config-HOmiOLQc.d.ts → config-DRHg7V3Z.d.ts} +17 -0
- package/dist/doctor.d.ts +73 -6
- package/dist/doctor.js +309 -12
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +20 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +11 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +229 -17
- package/dist/index.js.map +1 -1
- package/dist/starter/.eas/workflows/deploy-production.yml +41 -38
- package/dist/starter/.eas/workflows/rollout.yml +3 -2
- package/dist/starter/README.md +2 -2
- package/dist/templates/ci/claude-review.yml +26 -0
- package/dist/templates/eas/workflows/deploy-production.yml +41 -38
- package/dist/templates/eas/workflows/rollout.yml +3 -2
- package/dist/templates/vercel/ignore-build.sh +131 -0
- package/dist/templates/vercel/vercel.json +4 -0
- package/dist/vite.js +221 -9
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
# Deploy to production
|
|
2
|
-
#
|
|
3
|
-
# the same change. The version isn't part of the fingerprint, so a bump on its own starts no
|
|
4
|
-
# build, and a native change without one uploads the old version string again.
|
|
1
|
+
# Deploy to production on every merge to main. main is protected (pull requests only, and only the
|
|
2
|
+
# people allowed to merge into it), so that merge is the release's approval.
|
|
5
3
|
#
|
|
6
4
|
# 1. Fingerprint the native project as the production variant builds it.
|
|
7
5
|
# 2. Per platform, look for a production build with that fingerprint.
|
|
8
|
-
# -
|
|
9
|
-
#
|
|
10
|
-
# -
|
|
11
|
-
#
|
|
6
|
+
# - One exists (JavaScript only): publish an over-the-air update to the `production` channel, to
|
|
7
|
+
# every install.
|
|
8
|
+
# - None (native code changed): build one and submit it in the same run. Installs can't take an
|
|
9
|
+
# update across a native change, so the new code reaches phones through the new build.
|
|
10
|
+
#
|
|
11
|
+
# A merge that changes native code is a new store version once it's released: bump `version` in
|
|
12
|
+
# app.config.ts in the same change when you mean to release it. The build number goes up by itself
|
|
13
|
+
# (eas.json autoIncrement).
|
|
12
14
|
#
|
|
13
15
|
# Safety:
|
|
14
|
-
# - A
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# -
|
|
18
|
-
#
|
|
19
|
-
#
|
|
16
|
+
# - A push to main is the only trigger, so a run always builds a commit in git, never a local
|
|
17
|
+
# folder. `eas workflow:run` can start it anyway (and without `--ref` uploads the working
|
|
18
|
+
# directory), so the first job runs only for a push to main and a manual run does nothing.
|
|
19
|
+
# - Runs are serialized (`concurrency`): two quick merges never publish out of order.
|
|
20
|
+
# - Updates go to every install, not a staged share: EAS refuses a second rollout on the same
|
|
21
|
+
# channel, platform and runtime while one is in progress, so a staged update would make the next
|
|
22
|
+
# merge's update fail. To take one back, republish the update before it
|
|
23
|
+
# (`eas update:republish --group <id>`); rollout.yml does that for a staged one.
|
|
24
|
+
# - A build is submitted in the same run that made it, so an update never goes to a production
|
|
25
|
+
# build that nobody has. If a submit fails, submit that build by hand before the next merge
|
|
26
|
+
# (`eas submit --platform ios --id <build id> --profile production`).
|
|
20
27
|
# - Builds go to TestFlight and to the Play internal track as a draft (eas.json `submit`);
|
|
21
28
|
# releasing to the stores stays a person's step in App Store Connect and Play Console.
|
|
22
|
-
# -
|
|
23
|
-
# in progress, so a new update can't silently replace a staged one (finish it with rollout.yml).
|
|
24
|
-
# - Each platform's update is its own update group; promote or roll back each with rollout.yml.
|
|
25
|
-
# - A production build whose approval was rejected (or whose submit failed) still matches its
|
|
26
|
-
# fingerprint: a later JavaScript-only tag sends an update to a binary nobody has. Submit that
|
|
27
|
-
# build by hand first (`eas submit --platform ios --id <build id> --profile production`).
|
|
29
|
+
# - Each platform's build or update is its own: a failure on one doesn't hold the other back.
|
|
28
30
|
#
|
|
29
31
|
# Genesis template (templates/eas/workflows/deploy-production.yml). Edit the copy in your app; see
|
|
30
32
|
# docs/NATIVE-RELEASE.md in the Genesis repository.
|
|
@@ -32,11 +34,19 @@ name: Deploy production
|
|
|
32
34
|
|
|
33
35
|
on:
|
|
34
36
|
push:
|
|
35
|
-
|
|
37
|
+
branches: [main]
|
|
38
|
+
|
|
39
|
+
# One deploy at a time. The running one always finishes (no cancel_in_progress); the newest merge
|
|
40
|
+
# waits for it and EAS drops the runs in between, so an older merge never publishes last.
|
|
41
|
+
concurrency:
|
|
42
|
+
group: ${{ workflow.filename }}-${{ github.ref }}
|
|
36
43
|
|
|
37
44
|
jobs:
|
|
38
45
|
fingerprint:
|
|
39
46
|
name: Fingerprint
|
|
47
|
+
# Only a push to main. `eas workflow:run` starts any workflow whatever its `on` says, and
|
|
48
|
+
# without --ref it uploads a local folder; skipping here skips every job after it.
|
|
49
|
+
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
|
|
40
50
|
type: fingerprint
|
|
41
51
|
environment: production
|
|
42
52
|
env:
|
|
@@ -83,18 +93,9 @@ jobs:
|
|
|
83
93
|
platform: android
|
|
84
94
|
profile: production
|
|
85
95
|
|
|
86
|
-
approve_release:
|
|
87
|
-
name: Approve submitting the builds and publishing the updates
|
|
88
|
-
# Both lookups must have succeeded (needs) and neither build failed (after): a failure on one
|
|
89
|
-
# platform never leaves the other to ship alone.
|
|
90
|
-
needs: [get_ios_build, get_android_build]
|
|
91
|
-
after: [build_ios, build_android]
|
|
92
|
-
if: ${{ after.build_ios.status != 'failure' && after.build_android.status != 'failure' }}
|
|
93
|
-
type: require-approval
|
|
94
|
-
|
|
95
96
|
submit_ios:
|
|
96
97
|
name: Submit iOS to TestFlight
|
|
97
|
-
needs: [build_ios
|
|
98
|
+
needs: [build_ios]
|
|
98
99
|
if: ${{ needs.build_ios.outputs.build_id }}
|
|
99
100
|
type: submit
|
|
100
101
|
environment: production
|
|
@@ -104,7 +105,7 @@ jobs:
|
|
|
104
105
|
|
|
105
106
|
submit_android:
|
|
106
107
|
name: Submit Android to the internal track (draft)
|
|
107
|
-
needs: [build_android
|
|
108
|
+
needs: [build_android]
|
|
108
109
|
if: ${{ needs.build_android.outputs.build_id }}
|
|
109
110
|
type: submit
|
|
110
111
|
environment: production
|
|
@@ -113,8 +114,8 @@ jobs:
|
|
|
113
114
|
profile: production
|
|
114
115
|
|
|
115
116
|
update_ios:
|
|
116
|
-
name: Update iOS (
|
|
117
|
-
needs: [get_ios_build
|
|
117
|
+
name: Update iOS (every production install)
|
|
118
|
+
needs: [get_ios_build]
|
|
118
119
|
if: ${{ needs.get_ios_build.outputs.build_id }}
|
|
119
120
|
type: update
|
|
120
121
|
environment: production
|
|
@@ -124,15 +125,16 @@ jobs:
|
|
|
124
125
|
params:
|
|
125
126
|
channel: production
|
|
126
127
|
platform: ios
|
|
127
|
-
rollout_percentage:
|
|
128
|
+
# No rollout_percentage: unset, the update goes to every install. Set to 100, EAS published
|
|
129
|
+
# it as a rollout and a consumer app's update job failed ("GraphQL request failed").
|
|
128
130
|
# Explicit: unset, EAS tries a Sentry source map upload whenever @sentry/react-native is
|
|
129
131
|
# installed and only logs a failure. Set true once the Sentry plugin is on in app.config.ts
|
|
130
132
|
# (with SENTRY_AUTH_TOKEN), so a failed upload fails the job.
|
|
131
133
|
upload_sentry_sourcemaps: false
|
|
132
134
|
|
|
133
135
|
update_android:
|
|
134
|
-
name: Update Android (
|
|
135
|
-
needs: [get_android_build
|
|
136
|
+
name: Update Android (every production install)
|
|
137
|
+
needs: [get_android_build]
|
|
136
138
|
if: ${{ needs.get_android_build.outputs.build_id }}
|
|
137
139
|
type: update
|
|
138
140
|
environment: production
|
|
@@ -142,7 +144,8 @@ jobs:
|
|
|
142
144
|
params:
|
|
143
145
|
channel: production
|
|
144
146
|
platform: android
|
|
145
|
-
rollout_percentage:
|
|
147
|
+
# No rollout_percentage: unset, the update goes to every install. Set to 100, EAS published
|
|
148
|
+
# it as a rollout and a consumer app's update job failed ("GraphQL request failed").
|
|
146
149
|
# Explicit: unset, EAS tries a Sentry source map upload whenever @sentry/react-native is
|
|
147
150
|
# installed and only logs a failure. Set true once the Sentry plugin is on in app.config.ts
|
|
148
151
|
# (with SENTRY_AUTH_TOKEN), so a failed upload fails the job.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
# Promote or roll back a staged production update
|
|
1
|
+
# Promote or roll back a staged production update: one published by hand with `--rollout-percentage`
|
|
2
|
+
# (deploy-production.yml sends every merge's update to every install).
|
|
2
3
|
#
|
|
3
4
|
# Run it by hand, from git:
|
|
4
5
|
#
|
|
@@ -40,7 +41,7 @@ on:
|
|
|
40
41
|
update_group_id:
|
|
41
42
|
type: string
|
|
42
43
|
required: true
|
|
43
|
-
description: One platform's update group
|
|
44
|
+
description: One platform's update group you published by hand with `--rollout-percentage` (`eas update:list --branch production`). deploy-production.yml publishes at 100%, which has no rollout to promote or roll back.
|
|
44
45
|
action:
|
|
45
46
|
type: choice
|
|
46
47
|
required: true
|
package/dist/starter/README.md
CHANGED
|
@@ -239,8 +239,8 @@ flows; [docs/NATIVE-RELEASE.md](../../docs/NATIVE-RELEASE.md) has the setup and
|
|
|
239
239
|
| --- | --- | --- |
|
|
240
240
|
| `pr-preview.yml` | a pull request into `main` that changes the app, or one labeled `Preview` | Repack a preview build with the same fingerprint (or build one), publish an update to `pr-<number>`, comment the install link and QR code. iOS once `PREVIEW_IOS=true`. |
|
|
241
241
|
| `e2e.yml` | by hand (Maestro needs a paid EAS plan) | The Maestro flows on an iOS simulator build. |
|
|
242
|
-
| `deploy-production.yml` |
|
|
243
|
-
| `rollout.yml` | by hand | Promote
|
|
242
|
+
| `deploy-production.yml` | every merge to `main` | A store build (submitted in the same run) where native code changed, else an update to every `production` install. |
|
|
243
|
+
| `rollout.yml` | by hand | Promote an update you staged by hand after a failed-launch check, or roll it back. |
|
|
244
244
|
|
|
245
245
|
Profiles: `development`, `preview` and `production` build the `APP_VARIANT` of the same name on
|
|
246
246
|
the channel of the same name; `e2e` is a development build for the simulator. Store ids in
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copy to .github/workflows/claude-review.yml. Replace GENESIS_SHA with the commit of the
|
|
2
|
+
# Genesis release you run (docs/APP-CI.md in marktiderman/genesis says how).
|
|
3
|
+
# Claude reviews each pull request against this app's CLAUDE.md and AGENTS.md (run
|
|
4
|
+
# `genesis agents` so they hold the Genesis guide). Needs the Claude GitHub app and the
|
|
5
|
+
# CLAUDE_CODE_OAUTH_TOKEN secret.
|
|
6
|
+
name: Claude Code Review
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
pull_request:
|
|
10
|
+
types: [opened, ready_for_review, reopened] # add synchronize to review every push (each run is billed)
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: claude-review-${{ github.event.pull_request.number }}
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
permissions: {}
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
review:
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
pull-requests: write
|
|
23
|
+
issues: write
|
|
24
|
+
id-token: write
|
|
25
|
+
uses: marktiderman/genesis/.github/workflows/claude-review.yml@GENESIS_SHA # @marktiderman/genesis@X.Y.Z
|
|
26
|
+
secrets: inherit
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
# Deploy to production
|
|
2
|
-
#
|
|
3
|
-
# the same change. The version isn't part of the fingerprint, so a bump on its own starts no
|
|
4
|
-
# build, and a native change without one uploads the old version string again.
|
|
1
|
+
# Deploy to production on every merge to main. main is protected (pull requests only, and only the
|
|
2
|
+
# people allowed to merge into it), so that merge is the release's approval.
|
|
5
3
|
#
|
|
6
4
|
# 1. Fingerprint the native project as the production variant builds it.
|
|
7
5
|
# 2. Per platform, look for a production build with that fingerprint.
|
|
8
|
-
# -
|
|
9
|
-
#
|
|
10
|
-
# -
|
|
11
|
-
#
|
|
6
|
+
# - One exists (JavaScript only): publish an over-the-air update to the `production` channel, to
|
|
7
|
+
# every install.
|
|
8
|
+
# - None (native code changed): build one and submit it in the same run. Installs can't take an
|
|
9
|
+
# update across a native change, so the new code reaches phones through the new build.
|
|
10
|
+
#
|
|
11
|
+
# A merge that changes native code is a new store version once it's released: bump `version` in
|
|
12
|
+
# app.config.ts in the same change when you mean to release it. The build number goes up by itself
|
|
13
|
+
# (eas.json autoIncrement).
|
|
12
14
|
#
|
|
13
15
|
# Safety:
|
|
14
|
-
# - A
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# -
|
|
18
|
-
#
|
|
19
|
-
#
|
|
16
|
+
# - A push to main is the only trigger, so a run always builds a commit in git, never a local
|
|
17
|
+
# folder. `eas workflow:run` can start it anyway (and without `--ref` uploads the working
|
|
18
|
+
# directory), so the first job runs only for a push to main and a manual run does nothing.
|
|
19
|
+
# - Runs are serialized (`concurrency`): two quick merges never publish out of order.
|
|
20
|
+
# - Updates go to every install, not a staged share: EAS refuses a second rollout on the same
|
|
21
|
+
# channel, platform and runtime while one is in progress, so a staged update would make the next
|
|
22
|
+
# merge's update fail. To take one back, republish the update before it
|
|
23
|
+
# (`eas update:republish --group <id>`); rollout.yml does that for a staged one.
|
|
24
|
+
# - A build is submitted in the same run that made it, so an update never goes to a production
|
|
25
|
+
# build that nobody has. If a submit fails, submit that build by hand before the next merge
|
|
26
|
+
# (`eas submit --platform ios --id <build id> --profile production`).
|
|
20
27
|
# - Builds go to TestFlight and to the Play internal track as a draft (eas.json `submit`);
|
|
21
28
|
# releasing to the stores stays a person's step in App Store Connect and Play Console.
|
|
22
|
-
# -
|
|
23
|
-
# in progress, so a new update can't silently replace a staged one (finish it with rollout.yml).
|
|
24
|
-
# - Each platform's update is its own update group; promote or roll back each with rollout.yml.
|
|
25
|
-
# - A production build whose approval was rejected (or whose submit failed) still matches its
|
|
26
|
-
# fingerprint: a later JavaScript-only tag sends an update to a binary nobody has. Submit that
|
|
27
|
-
# build by hand first (`eas submit --platform ios --id <build id> --profile production`).
|
|
29
|
+
# - Each platform's build or update is its own: a failure on one doesn't hold the other back.
|
|
28
30
|
#
|
|
29
31
|
# Genesis template (templates/eas/workflows/deploy-production.yml). Edit the copy in your app; see
|
|
30
32
|
# docs/NATIVE-RELEASE.md in the Genesis repository.
|
|
@@ -32,11 +34,19 @@ name: Deploy production
|
|
|
32
34
|
|
|
33
35
|
on:
|
|
34
36
|
push:
|
|
35
|
-
|
|
37
|
+
branches: [main]
|
|
38
|
+
|
|
39
|
+
# One deploy at a time. The running one always finishes (no cancel_in_progress); the newest merge
|
|
40
|
+
# waits for it and EAS drops the runs in between, so an older merge never publishes last.
|
|
41
|
+
concurrency:
|
|
42
|
+
group: ${{ workflow.filename }}-${{ github.ref }}
|
|
36
43
|
|
|
37
44
|
jobs:
|
|
38
45
|
fingerprint:
|
|
39
46
|
name: Fingerprint
|
|
47
|
+
# Only a push to main. `eas workflow:run` starts any workflow whatever its `on` says, and
|
|
48
|
+
# without --ref it uploads a local folder; skipping here skips every job after it.
|
|
49
|
+
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
|
|
40
50
|
type: fingerprint
|
|
41
51
|
environment: production
|
|
42
52
|
env:
|
|
@@ -83,18 +93,9 @@ jobs:
|
|
|
83
93
|
platform: android
|
|
84
94
|
profile: production
|
|
85
95
|
|
|
86
|
-
approve_release:
|
|
87
|
-
name: Approve submitting the builds and publishing the updates
|
|
88
|
-
# Both lookups must have succeeded (needs) and neither build failed (after): a failure on one
|
|
89
|
-
# platform never leaves the other to ship alone.
|
|
90
|
-
needs: [get_ios_build, get_android_build]
|
|
91
|
-
after: [build_ios, build_android]
|
|
92
|
-
if: ${{ after.build_ios.status != 'failure' && after.build_android.status != 'failure' }}
|
|
93
|
-
type: require-approval
|
|
94
|
-
|
|
95
96
|
submit_ios:
|
|
96
97
|
name: Submit iOS to TestFlight
|
|
97
|
-
needs: [build_ios
|
|
98
|
+
needs: [build_ios]
|
|
98
99
|
if: ${{ needs.build_ios.outputs.build_id }}
|
|
99
100
|
type: submit
|
|
100
101
|
environment: production
|
|
@@ -104,7 +105,7 @@ jobs:
|
|
|
104
105
|
|
|
105
106
|
submit_android:
|
|
106
107
|
name: Submit Android to the internal track (draft)
|
|
107
|
-
needs: [build_android
|
|
108
|
+
needs: [build_android]
|
|
108
109
|
if: ${{ needs.build_android.outputs.build_id }}
|
|
109
110
|
type: submit
|
|
110
111
|
environment: production
|
|
@@ -113,8 +114,8 @@ jobs:
|
|
|
113
114
|
profile: production
|
|
114
115
|
|
|
115
116
|
update_ios:
|
|
116
|
-
name: Update iOS (
|
|
117
|
-
needs: [get_ios_build
|
|
117
|
+
name: Update iOS (every production install)
|
|
118
|
+
needs: [get_ios_build]
|
|
118
119
|
if: ${{ needs.get_ios_build.outputs.build_id }}
|
|
119
120
|
type: update
|
|
120
121
|
environment: production
|
|
@@ -124,15 +125,16 @@ jobs:
|
|
|
124
125
|
params:
|
|
125
126
|
channel: production
|
|
126
127
|
platform: ios
|
|
127
|
-
rollout_percentage:
|
|
128
|
+
# No rollout_percentage: unset, the update goes to every install. Set to 100, EAS published
|
|
129
|
+
# it as a rollout and a consumer app's update job failed ("GraphQL request failed").
|
|
128
130
|
# Explicit: unset, EAS tries a Sentry source map upload whenever @sentry/react-native is
|
|
129
131
|
# installed and only logs a failure. Set true once the Sentry plugin is on in app.config.ts
|
|
130
132
|
# (with SENTRY_AUTH_TOKEN), so a failed upload fails the job.
|
|
131
133
|
upload_sentry_sourcemaps: false
|
|
132
134
|
|
|
133
135
|
update_android:
|
|
134
|
-
name: Update Android (
|
|
135
|
-
needs: [get_android_build
|
|
136
|
+
name: Update Android (every production install)
|
|
137
|
+
needs: [get_android_build]
|
|
136
138
|
if: ${{ needs.get_android_build.outputs.build_id }}
|
|
137
139
|
type: update
|
|
138
140
|
environment: production
|
|
@@ -142,7 +144,8 @@ jobs:
|
|
|
142
144
|
params:
|
|
143
145
|
channel: production
|
|
144
146
|
platform: android
|
|
145
|
-
rollout_percentage:
|
|
147
|
+
# No rollout_percentage: unset, the update goes to every install. Set to 100, EAS published
|
|
148
|
+
# it as a rollout and a consumer app's update job failed ("GraphQL request failed").
|
|
146
149
|
# Explicit: unset, EAS tries a Sentry source map upload whenever @sentry/react-native is
|
|
147
150
|
# installed and only logs a failure. Set true once the Sentry plugin is on in app.config.ts
|
|
148
151
|
# (with SENTRY_AUTH_TOKEN), so a failed upload fails the job.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
# Promote or roll back a staged production update
|
|
1
|
+
# Promote or roll back a staged production update: one published by hand with `--rollout-percentage`
|
|
2
|
+
# (deploy-production.yml sends every merge's update to every install).
|
|
2
3
|
#
|
|
3
4
|
# Run it by hand, from git:
|
|
4
5
|
#
|
|
@@ -40,7 +41,7 @@ on:
|
|
|
40
41
|
update_group_id:
|
|
41
42
|
type: string
|
|
42
43
|
required: true
|
|
43
|
-
description: One platform's update group
|
|
44
|
+
description: One platform's update group you published by hand with `--rollout-percentage` (`eas update:list --branch production`). deploy-production.yml publishes at 100%, which has no rollout to promote or roll back.
|
|
44
45
|
action:
|
|
45
46
|
type: choice
|
|
46
47
|
required: true
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Vercel "Ignored Build Step": production always builds; a preview builds only when someone asks.
|
|
3
|
+
#
|
|
4
|
+
# Copy to scripts/vercel-ignore-build.sh in the app and point vercel.json at it (the vercel.json
|
|
5
|
+
# beside this file). Replace GENESIS_SHA below with the commit of the Genesis release you copied it
|
|
6
|
+
# from (docs/APP-CI.md, "Which ref to call", says how to find it), so the next upgrade can tell
|
|
7
|
+
# whether your copy is behind. Edit the copy, not the defaults: set the variables below in the
|
|
8
|
+
# Vercel project instead.
|
|
9
|
+
#
|
|
10
|
+
# Genesis template templates/vercel/ignore-build.sh @ GENESIS_SHA # @marktiderman/genesis@X.Y.Z
|
|
11
|
+
#
|
|
12
|
+
# Vercel runs this before every build: exit 0 skips the build, exit 1 builds.
|
|
13
|
+
#
|
|
14
|
+
# 1. Production (VERCEL_ENV=production, the production branch) always builds. So does a deploy
|
|
15
|
+
# with VERCEL_ENV unset (system variables not exposed: production can't be told from a preview,
|
|
16
|
+
# and production must never be skipped) and a custom environment (VERCEL_TARGET_ENV set to
|
|
17
|
+
# something other than preview, such as staging).
|
|
18
|
+
# 2. GENESIS_PREVIEWS=off: no preview builds. GENESIS_PREVIEWS=every-pr: every preview builds.
|
|
19
|
+
# 3. GENESIS_PREVIEWS=on-demand (the default) builds a preview only when one of these asks:
|
|
20
|
+
# - the branch starts with GENESIS_PREVIEW_BRANCH_PREFIX (default `preview/`);
|
|
21
|
+
# - the commit message has `[preview]` in it (the commit being deployed, not earlier ones);
|
|
22
|
+
# - the pull request has the label GENESIS_PREVIEW_LABEL (default `preview`, any case), read
|
|
23
|
+
# from the GitHub API with GENESIS_PREVIEW_GITHUB_TOKEN (a fine-grained token with read access
|
|
24
|
+
# to pull requests on this repository). No token, a failed request or a non-GitHub repository
|
|
25
|
+
# skips: an error never starts a build.
|
|
26
|
+
# Everything else skips.
|
|
27
|
+
#
|
|
28
|
+
# Vercel doesn't redeploy when a label is added: push a commit (or redeploy the latest one) after
|
|
29
|
+
# labelling. Vercel passes VERCEL_GIT_* only with "Automatically expose System Environment
|
|
30
|
+
# Variables" on in the project's Environment Variables settings.
|
|
31
|
+
|
|
32
|
+
# The app's own defaults can live in genesis.config.json's "environments" block:
|
|
33
|
+
# { "environments": { "previews": "every-pr", "label": "preview", "branchPrefix": "preview/" } }
|
|
34
|
+
# A variable set in the Vercel project wins over the file; the file wins over the defaults here.
|
|
35
|
+
config() { # prints the value, __EMPTY__ for "", nothing when unset or unreadable
|
|
36
|
+
[ -f genesis.config.json ] && command -v node > /dev/null 2>&1 || return 0
|
|
37
|
+
node -e 'try { const v = ((JSON.parse(require("fs").readFileSync("genesis.config.json", "utf8")) || {}).environments || {})[process.argv[1]]; if (typeof v === "string") process.stdout.write(v === "" ? "__EMPTY__" : v) } catch {}' "$1" 2> /dev/null || true
|
|
38
|
+
}
|
|
39
|
+
setting() { # $1 variable name, $2 config key, $3 default
|
|
40
|
+
if [ -n "${!1+set}" ]; then printf '%s' "${!1}"; return; fi
|
|
41
|
+
local v
|
|
42
|
+
v="$(config "$2")"
|
|
43
|
+
[ "$v" = "__EMPTY__" ] && return
|
|
44
|
+
printf '%s' "${v:-$3}"
|
|
45
|
+
}
|
|
46
|
+
previews="$(setting GENESIS_PREVIEWS previews on-demand)"
|
|
47
|
+
[ -n "$previews" ] || previews=on-demand
|
|
48
|
+
label="$(setting GENESIS_PREVIEW_LABEL label preview)" # set but empty: no label check
|
|
49
|
+
prefix="$(setting GENESIS_PREVIEW_BRANCH_PREFIX branchPrefix preview/)" # set but empty: no branch check
|
|
50
|
+
token="${GENESIS_PREVIEW_GITHUB_TOKEN:-}"
|
|
51
|
+
api="${GENESIS_GITHUB_API_URL:-https://api.github.com}"
|
|
52
|
+
|
|
53
|
+
ref="${VERCEL_GIT_COMMIT_REF:-}"
|
|
54
|
+
message="${VERCEL_GIT_COMMIT_MESSAGE:-}"
|
|
55
|
+
pr="${VERCEL_GIT_PULL_REQUEST_ID:-}"
|
|
56
|
+
|
|
57
|
+
build() {
|
|
58
|
+
echo "genesis previews: build ($1)"
|
|
59
|
+
exit 1
|
|
60
|
+
}
|
|
61
|
+
skip() {
|
|
62
|
+
echo "genesis previews: skip ($1)"
|
|
63
|
+
exit 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[ "${VERCEL_ENV:-}" = "production" ] && build "production"
|
|
67
|
+
[ -z "${VERCEL_ENV:-}" ] && build "VERCEL_ENV unset: expose System Environment Variables to build previews on demand"
|
|
68
|
+
case "${VERCEL_TARGET_ENV:-preview}" in
|
|
69
|
+
preview | production | development) ;;
|
|
70
|
+
*) build "custom environment ${VERCEL_TARGET_ENV}" ;;
|
|
71
|
+
esac
|
|
72
|
+
|
|
73
|
+
case "$previews" in
|
|
74
|
+
off) skip "GENESIS_PREVIEWS=off" ;;
|
|
75
|
+
every-pr) build "GENESIS_PREVIEWS=every-pr" ;;
|
|
76
|
+
on-demand) ;;
|
|
77
|
+
*) echo "genesis previews: unknown GENESIS_PREVIEWS=\"$previews\" (on-demand, every-pr or off); using on-demand" ;;
|
|
78
|
+
esac
|
|
79
|
+
|
|
80
|
+
if [ -n "$prefix" ] && [ -n "$ref" ]; then
|
|
81
|
+
case "$ref" in
|
|
82
|
+
"$prefix"*) build "branch $ref starts with $prefix" ;;
|
|
83
|
+
esac
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
|
|
87
|
+
|
|
88
|
+
case "$(lower "$message")" in
|
|
89
|
+
*"[preview]"*) build "[preview] in the commit message" ;;
|
|
90
|
+
esac
|
|
91
|
+
|
|
92
|
+
[ -n "$label" ] || skip "no opt-in (GENESIS_PREVIEW_LABEL is empty)"
|
|
93
|
+
[ "${VERCEL_GIT_PROVIDER:-github}" = "github" ] || skip "no opt-in (label check needs GitHub, not ${VERCEL_GIT_PROVIDER})"
|
|
94
|
+
[ -n "$token" ] || skip "no opt-in (no GENESIS_PREVIEW_GITHUB_TOKEN to read the \"$label\" label)"
|
|
95
|
+
owner="${VERCEL_GIT_REPO_OWNER:-}"
|
|
96
|
+
repo="${VERCEL_GIT_REPO_SLUG:-}"
|
|
97
|
+
[ -n "$owner" ] && [ -n "$repo" ] || skip "no opt-in (VERCEL_GIT_REPO_OWNER or VERCEL_GIT_REPO_SLUG is unset)"
|
|
98
|
+
|
|
99
|
+
# The pull request (by number, or the open one for this branch when Vercel has no number yet).
|
|
100
|
+
if [ -n "$pr" ]; then
|
|
101
|
+
case "$pr" in
|
|
102
|
+
*[!0-9]*) skip "no opt-in (VERCEL_GIT_PULL_REQUEST_ID \"$pr\" isn't a number)" ;;
|
|
103
|
+
esac
|
|
104
|
+
body="$(curl -fsS --max-time 10 \
|
|
105
|
+
-H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
|
|
106
|
+
"$api/repos/$owner/$repo/pulls/$pr" 2>/dev/null)" || skip "no opt-in (couldn't read pull request #$pr from GitHub)"
|
|
107
|
+
else
|
|
108
|
+
[ -n "$ref" ] || skip "no opt-in (no branch or pull request to read a label from)"
|
|
109
|
+
body="$(curl -fsS --max-time 10 --get \
|
|
110
|
+
-H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
|
|
111
|
+
--data-urlencode "state=open" --data-urlencode "head=$owner:$ref" \
|
|
112
|
+
"$api/repos/$owner/$repo/pulls" 2>/dev/null)" || skip "no opt-in (couldn't read the pull requests for $ref from GitHub)"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# The labels' names, one per line, read with Node (which every Vercel build image has). A pull
|
|
116
|
+
# request list (no number) is every open pull request for this branch: a label on any of them counts.
|
|
117
|
+
command -v node >/dev/null 2>&1 || skip "no opt-in (no node to read GitHub's answer)"
|
|
118
|
+
names="$(printf '%s' "$body" | node -e '
|
|
119
|
+
let s = "";
|
|
120
|
+
process.stdin.on("data", (d) => (s += d)).on("end", () => {
|
|
121
|
+
const j = JSON.parse(s);
|
|
122
|
+
for (const pr of Array.isArray(j) ? j : [j]) for (const l of pr?.labels ?? []) console.log(String(l.name ?? ""));
|
|
123
|
+
});
|
|
124
|
+
' 2>/dev/null)" || skip "no opt-in (GitHub's answer wasn't the JSON expected)"
|
|
125
|
+
want="$(lower "$label")"
|
|
126
|
+
while IFS= read -r name; do
|
|
127
|
+
[ "$(lower "$name")" = "$want" ] && build "the pull request has the \"$label\" label"
|
|
128
|
+
done <<EOF_NAMES
|
|
129
|
+
$names
|
|
130
|
+
EOF_NAMES
|
|
131
|
+
skip "no opt-in (no $prefix branch, [preview] commit or \"$label\" label)"
|