@@ -159,35 +159,84 @@ jobs:
159159 with :
160160 node-version : 22
161161 cache : npm
162- # Vercel re-runs the full build on its servers using vercel.json buildCommand.
163162 # Required GitHub secrets (Settings → Secrets and variables → Actions):
164- # VERCEL_TOKEN — vercel.com/account/tokens
165- # VERCEL_ORG_ID — from .vercel/project.json after `vercel link`
166- # VERCEL_PROJECT_ID — website project id
167- # VERCEL_COCKPIT_PROJECT_ID — cockpit project id
163+ # VERCEL_TOKEN — vercel.com/account/tokens
164+ # VERCEL_ORG_ID — Vercel team id
165+ # VERCEL_PROJECT_ID — website project id
166+ # VERCEL_COCKPIT_PROJECT_ID — cockpit project id
168167 - run : npm ci
169168 - run : npx playwright install --with-deps chromium
170- - name : Deploy to Vercel (production)
171- id : deploy
169+ - name : Resolve deploy targets
170+ id : affected
172171 run : |
173- url=$(npx vercel deploy --prod --yes --token=${{ secrets.VERCEL_TOKEN }} | tail -n 1)
172+ base_sha="${{ github.event.before }}"
173+ head_sha="${{ github.sha }}"
174+ if [ -z "$base_sha" ] || [ "$base_sha" = "0000000000000000000000000000000000000000" ]; then
175+ base_sha="$(git rev-parse "$head_sha^")"
176+ fi
177+
178+ affected_projects="$(npx nx show projects --affected --base="$base_sha" --head="$head_sha")"
179+ changed_files="$(git diff --name-only "$base_sha" "$head_sha")"
180+
181+ website_changed=false
182+ cockpit_changed=false
183+
184+ if printf '%s\n' "$affected_projects" | rg -x 'website' >/dev/null; then
185+ website_changed=true
186+ fi
187+
188+ if printf '%s\n' "$affected_projects" | rg -x 'cockpit' >/dev/null; then
189+ cockpit_changed=true
190+ fi
191+
192+ if printf '%s\n' "$changed_files" | rg '^(\.github/workflows/ci\.yml|vercel\.json)$' >/dev/null; then
193+ website_changed=true
194+ fi
195+
196+ if printf '%s\n' "$changed_files" | rg '^(\.github/workflows/ci\.yml|vercel\.cockpit\.json)$' >/dev/null; then
197+ cockpit_changed=true
198+ fi
199+
200+ echo "website=$website_changed" >> "$GITHUB_OUTPUT"
201+ echo "cockpit=$cockpit_changed" >> "$GITHUB_OUTPUT"
202+ - name : Prepare website Vercel project
203+ if : steps.affected.outputs.website == 'true'
204+ run : |
205+ mkdir -p .vercel
206+ cat > .vercel/project.json <<EOF
207+ {"projectId":"${{ secrets.VERCEL_PROJECT_ID }}","orgId":"${{ secrets.VERCEL_ORG_ID }}","projectName":"stream-resource"}
208+ EOF
209+ npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
210+ rm -rf .vercel/output
211+ - name : Build and deploy website to Vercel (production)
212+ if : steps.affected.outputs.website == 'true'
213+ id : deploy_website
214+ run : |
215+ npx vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
216+ url=$(npx vercel deploy --prebuilt --archive=tgz --prod --yes --token=${{ secrets.VERCEL_TOKEN }} | tail -n 1)
174217 echo "deployment_url=$url" >> "$GITHUB_OUTPUT"
175- env :
176- VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
177- VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
178218 - name : Verify deployed website
219+ if : steps.affected.outputs.website == 'true'
179220 run : npx nx e2e website --skip-nx-cache
180221 env :
181222 BASE_URL : https://stream-resource.dev
182- - name : Deploy cockpit to Vercel (production)
223+ - name : Prepare cockpit Vercel project
224+ if : steps.affected.outputs.cockpit == 'true'
225+ run : |
226+ mkdir -p .vercel
227+ cat > .vercel/project.json <<EOF
228+ {"projectId":"${{ secrets.VERCEL_COCKPIT_PROJECT_ID }}","orgId":"${{ secrets.VERCEL_ORG_ID }}","projectName":"cockpit"}
229+ EOF
230+ npx vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
231+ rm -rf .vercel/output
232+ - name : Build and deploy cockpit to Vercel (production)
233+ if : steps.affected.outputs.cockpit == 'true'
183234 id : deploy_cockpit
184235 run : |
185- url=$(npx vercel deploy --prod --yes --local-config=vercel.cockpit.json --token=${{ secrets.VERCEL_TOKEN }} | tail -n 1)
236+ npx vercel build --prod --local-config vercel.cockpit.json --token=${{ secrets.VERCEL_TOKEN }}
237+ url=$(npx vercel deploy --prebuilt --archive=tgz --prod --yes --token=${{ secrets.VERCEL_TOKEN }} | tail -n 1)
186238 echo "deployment_url=$url" >> "$GITHUB_OUTPUT"
187- env :
188- VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
189- VERCEL_PROJECT_ID : ${{ secrets.VERCEL_COCKPIT_PROJECT_ID }}
190239 - name : Verify deployed cockpit
240+ if : steps.affected.outputs.cockpit == 'true'
191241 run : |
192- npx tsx apps/cockpit/scripts/deploy-smoke.ts --url "${{ steps.deploy_cockpit.outputs.deployment_url }}" --retries 10 --retry-delay-ms 2000
193242 npx tsx apps/cockpit/scripts/deploy-smoke.ts --url https://cockpit.stream-resource.dev --retries 20 --retry-delay-ms 5000
0 commit comments