-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (137 loc) · 6.14 KB
/
Copy pathdeploy-dev.yml
File metadata and controls
160 lines (137 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Deploy Dev
on:
push:
branches: [dev]
workflow_dispatch:
inputs:
dry_run:
description: Dry run - validate without deploying
required: false
default: false
type: boolean
concurrency:
group: deploy-dev
cancel-in-progress: false
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '22'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Build
run: pnpm build
- name: Check links
run: pnpm check-links
deploy-preview:
name: Deploy Preview
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 15
if: inputs.dry_run != true
outputs:
preview_url: ${{ steps.deploy.outputs.preview_url }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '22'
cache: 'pnpm'
- run: npm install --global vercel@53
- run: vercel pull --yes --environment=preview --token=$VERCEL_TOKEN
- run: vercel build --token=$VERCEL_TOKEN
- name: Deploy to Vercel Preview
id: deploy
run: |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --token=$VERCEL_TOKEN)
echo "preview_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
echo "Deployed to: $DEPLOYMENT_URL"
echo "## Preview Deployment" >> $GITHUB_STEP_SUMMARY
echo "**URL**: $DEPLOYMENT_URL" >> $GITHUB_STEP_SUMMARY
- name: Notify on failure
if: failure()
env:
PAPERCLIP_API_URL: ${{ secrets.PAPERCLIP_API_URL }}
PAPERCLIP_API_KEY: ${{ secrets.PAPERCLIP_API_KEY }}
run: |
echo "::error::Deployment to dev preview failed. Check the logs above for details."
# Extract Paperclip issue identifier from branch name or commit message
COMMIT_MSG=$(git log -1 --format=%s ${{ github.sha }})
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'SHA-\d+' | head -1)
# If no issue in commit message, check the merge branch name
if [ -z "$ISSUE_ID" ]; then
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'paperclip/(SHA-\d+)' | head -1 | sed 's|paperclip/||')
fi
if [ -n "$ISSUE_ID" ] && [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
# Comment on the existing issue
COMMENT="## CI Deploy Failed\n\n**Workflow**: ${{ github.workflow }}\n**Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n**Commit**: \`${{ github.sha }}\`\n\nThe deploy to prod failed. Check the CI logs and fix the issue. Do NOT mark this issue as done until a successful deploy is verified."
curl -sf -X PATCH "$PAPERCLIP_API_URL/issues/$ISSUE_ID" \
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg status "blocked" --arg comment "$COMMENT" '{status: $status, comment: $comment}')" || true
echo "Commented on Paperclip issue $ISSUE_ID"
elif [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
# No issue found — create one assigned to Coordinator for triage
curl -sf -X POST "$PAPERCLIP_API_URL/companies/953ff6b0-4d1b-4007-9859-8cb0a53629f6/issues" \
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg title "CI Failed: docs.sharpapi.io (${{ github.ref_name }})" \
--arg desc "GitHub Actions workflow **${{ github.workflow }}** failed.\n\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\nCommit: \`$(git log -1 --format='%h %s' ${{ github.sha }})\`\n\nInvestigate and fix." \
'{title: $title, description: $desc, status: "todo", priority: "critical", assigneeAgentId: "3a976364-1186-4c30-a136-bba410c2209c"}')" || true
echo "Created Paperclip issue for deploy failure"
fi
health-check:
name: Health Check
needs: deploy-preview
runs-on: ubuntu-latest
timeout-minutes: 5
if: inputs.dry_run != true
steps:
- name: Wait and check health
run: |
sleep 30
PREVIEW_URL="${{ needs.deploy-preview.outputs.preview_url }}"
for i in 1 2 3 4 5; do
HTTP_STATUS=$(curl -sL -o /dev/null -w "%{http_code}" "$PREVIEW_URL" --max-time 30)
if [ "$HTTP_STATUS" = "200" ]; then
echo "Health check passed (HTTP $HTTP_STATUS)"
echo "## Health Check" >> $GITHUB_STEP_SUMMARY
echo "**Status**: Passed" >> $GITHUB_STEP_SUMMARY
exit 0
fi
echo "Attempt $i: HTTP $HTTP_STATUS, retrying..."
sleep 10
done
echo "Health check FAILED"
exit 1
dry-run-summary:
name: Dry Run Summary
needs: validate
runs-on: ubuntu-latest
if: inputs.dry_run == true
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 10
- run: |
echo "=== DRY RUN MODE ==="
echo "Would deploy dev branch to Vercel Preview"
echo "## Dry Run Summary" >> $GITHUB_STEP_SUMMARY
echo "Validation passed. Would deploy to Vercel Preview." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Recent commits:" >> $GITHUB_STEP_SUMMARY
git log --oneline -10 >> $GITHUB_STEP_SUMMARY