Skip to content

Commit 503fbbf

Browse files
committed
ci: implement prebuilt deploy with GitHub-linked deployments and hidden prod URL
1 parent f1ba6a2 commit 503fbbf

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

.github/workflows/ci-deploy.yml

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI + Deploy (prebuilt)
22

33
on:
44
push:
5-
branches: [ '**' ]
5+
branches: [ '**' ] # prod only for main; others -> preview
66
pull_request:
7-
branches: [ main ]
7+
branches: [ main ] # PRs into main get preview link
88

99
permissions:
1010
contents: read
@@ -23,33 +23,33 @@ jobs:
2323
# Checkout repo
2424
- uses: actions/checkout@v4
2525

26-
# Setup Node + cache
26+
# Node + npm cache
2727
- uses: actions/setup-node@v4
2828
with:
2929
node-version: 18
3030
cache: 'npm'
3131

32-
# Install dependencies (CI preferred)
32+
# Install deps
3333
- name: Install
3434
run: npm ci || npm install
3535

36-
# Lint if exists
36+
# Lint if script exists
3737
- name: Lint
3838
run: npm run -s | grep -qE '(^| )lint( |:)' && npm run lint || echo "No lint script"
3939

40-
# Unit tests if exist
40+
# Unit tests if script exists
4141
- name: Unit tests
4242
run: npm run -s | grep -qE '(^| )test( |:)' && npm test --ci --passWithNoTests=false || echo "No test script"
4343

44-
# E2E tests if exist
44+
# E2E if script exists
4545
- name: E2E tests (optional)
4646
run: npm run -s | grep -qE '(^| )e2e( |:)' && npm run e2e || echo "No e2e script"
4747

4848
# Project build
4949
- name: App build
5050
run: npm run build
5151

52-
# Short summary for PR checks
52+
# Short build note
5353
- name: Build summary
5454
run: echo "Build & tests passed ✅" >> "$GITHUB_STEP_SUMMARY"
5555

@@ -58,20 +58,20 @@ jobs:
5858
if: ${{ success() }}
5959
runs-on: ubuntu-latest
6060
steps:
61-
# Checkout again for deploy context
61+
# Fresh checkout for deploy context
6262
- uses: actions/checkout@v4
6363

64-
# Setup Node for Vercel CLI
64+
# Node for Vercel CLI
6565
- uses: actions/setup-node@v4
6666
with:
6767
node-version: 18
6868
cache: 'npm'
6969

70-
# Install Vercel CLI
70+
# Vercel CLI
7171
- name: Install Vercel CLI
7272
run: npm i -g vercel@latest
7373

74-
# Decide environment target
74+
# Decide env: preview for PR/branches, production for main
7575
- name: Decide target
7676
id: tgt
7777
run: |
@@ -83,22 +83,22 @@ jobs:
8383
echo "target=preview" >> $GITHUB_OUTPUT
8484
fi
8585
86-
# Pull Vercel config + envs
86+
# Pull project settings + envs
8787
- name: Pull Vercel project settings
8888
run: |
8989
vercel pull --yes \
9090
--environment "${{ steps.tgt.outputs.target }}" \
9191
--token "${{ env.VERCEL_TOKEN }}" \
9292
--scope "${{ env.VERCEL_ORG }}"
9393
94-
# Prebuild locally
94+
# Build to .vercel/output (prebuilt)
9595
- name: Vercel prebuild
9696
run: |
9797
vercel build \
9898
--token "${{ env.VERCEL_TOKEN }}" \
9999
--scope "${{ env.VERCEL_ORG }}"
100100
101-
# Deploy prebuilt output (skip build on Vercel)
101+
# Deploy prebuilt (no build on Vercel)
102102
- name: Deploy (prebuilt)
103103
id: deploy
104104
env:
@@ -113,14 +113,18 @@ jobs:
113113
echo "url=$URL" >> "$GITHUB_OUTPUT"
114114
echo "Deployed: $URL"
115115
116-
# Show summary in job checks
116+
# Summary: hide prod URL, show preview URL
117117
- name: Summary
118118
run: |
119119
echo "### Deployment" >> "$GITHUB_STEP_SUMMARY"
120120
echo "- Target: **${{ steps.tgt.outputs.target }}**" >> "$GITHUB_STEP_SUMMARY"
121-
echo "- URL: ${{ steps.deploy.outputs.url }}" >> "$GITHUB_STEP_SUMMARY"
121+
if [ "${{ steps.tgt.outputs.target }}" = "production" ]; then
122+
echo "- URL: (hidden for production)" >> "$GITHUB_STEP_SUMMARY"
123+
else
124+
echo "- URL: ${{ steps.deploy.outputs.url }}" >> "$GITHUB_STEP_SUMMARY"
125+
fi
122126
123-
# Comment preview link for PR reviewers
127+
# PR comment with preview link
124128
- name: Post Preview URL to PR
125129
if: ${{ github.event_name == 'pull_request' && steps.deploy.outputs.url != '' }}
126130
uses: actions/github-script@v7
@@ -132,24 +136,32 @@ jobs:
132136
body: `✅ Preview ready: ${{ steps.deploy.outputs.url }}`
133137
})
134138
135-
# Link deployment to merge commit (appears in PR "merged commit ..." line)
136-
- name: Link deployment to merge commit
139+
# GitHub Deployment card on commit:
140+
# main → production (no URL); others → preview with URL
141+
- name: Link deployment to commit
137142
if: ${{ github.event_name == 'push' && steps.deploy.outputs.url != '' }}
138143
uses: actions/github-script@v7
139144
with:
140145
script: |
141-
const envName = '${{ github.ref_name }}';
146+
const isProd = (context.ref === 'refs/heads/main');
147+
const envName = isProd ? 'production' : context.ref.replace('refs/heads/', '');
148+
142149
const { data: dep } = await github.rest.repos.createDeployment({
143150
...context.repo,
144151
ref: context.sha,
145152
environment: envName,
146153
auto_merge: false,
147154
required_contexts: []
148155
});
149-
await github.rest.repos.createDeploymentStatus({
156+
157+
const status = {
150158
...context.repo,
151159
deployment_id: dep.id,
152160
state: 'success',
153-
environment: envName,
154-
environment_url: '${{ steps.deploy.outputs.url }}'
155-
});
161+
environment: envName
162+
};
163+
if (!isProd) {
164+
status.environment_url = '${{ steps.deploy.outputs.url }}';
165+
}
166+
167+
await github.rest.repos.createDeploymentStatus(status);

0 commit comments

Comments
 (0)