Repository navigation
139 lines (119 loc) · 4.39 KB
/
Copy pathuniversity-web-redeploy.yml
File metadata and controls
139 lines (119 loc) · 4.39 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
name: Redeploy University Web
on:
workflow_dispatch:
inputs:
reason:
description: "Reason for rebuilding university SSG pages"
required: false
default: "University API data updated"
type: string
repository_dispatch:
types: [university-data-updated]
permissions:
contents: read
concurrency:
group: university-web-production-redeploy
cancel-in-progress: false
jobs:
redeploy:
name: Redeploy university web production
runs-on: ubuntu-latest
timeout-minutes: 20
environment:
name: Production – solid-connect-university-web
url: ${{ steps.deploy.outputs.deployment_url }}
env:
VERCEL_PROJECT_NAME: solid-connect-university-web
VERCEL_RELEASE_BRANCH: release-university
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_TOKEN_UNIV: ${{ secrets.VERCEL_TOKEN_UNIV }}
REDEPLOY_REASON: ${{ github.event.inputs.reason || github.event.client_payload.reason || 'University API data updated' }}
steps:
- name: Checkout university release branch
uses: actions/checkout@v4
with:
ref: release-university
fetch-depth: 1
- name: Validate Vercel credentials
run: |
set -euo pipefail
if [ -z "$VERCEL_ORG_ID" ] || [ -z "$VERCEL_TOKEN_UNIV" ]; then
echo "VERCEL_ORG_ID and VERCEL_TOKEN_UNIV secrets are required." >&2
exit 1
fi
- name: Trigger fresh production deployment
id: deploy
env:
REPOSITORY_ID: ${{ github.event.repository.id }}
run: |
set -euo pipefail
RELEASE_SHA=$(git rev-parse HEAD)
REQUEST_BODY=$(jq -n \
--arg name "$VERCEL_PROJECT_NAME" \
--arg ref "$VERCEL_RELEASE_BRANCH" \
--arg sha "$RELEASE_SHA" \
--argjson repoId "$REPOSITORY_ID" \
'{
name: $name,
gitSource: {
type: "github",
repoId: $repoId,
ref: $ref,
sha: $sha
},
target: "production"
}')
HTTP_STATUS=$(curl --silent --show-error \
--output deployment.json \
--write-out "%{http_code}" \
--request POST \
--header "Authorization: Bearer $VERCEL_TOKEN_UNIV" \
--header "Content-Type: application/json" \
--data "$REQUEST_BODY" \
"https://api.vercel.com/v13/deployments?teamId=$VERCEL_ORG_ID&forceNew=1")
if [[ ! "$HTTP_STATUS" =~ ^2 ]]; then
jq -r '.error.message // "Vercel deployment request failed."' deployment.json >&2
exit 1
fi
DEPLOYMENT_ID=$(jq -r '.id // empty' deployment.json)
DEPLOYMENT_HOST=$(jq -r '.url // empty' deployment.json)
if [ -z "$DEPLOYMENT_ID" ] || [ -z "$DEPLOYMENT_HOST" ]; then
echo "Vercel response did not include a deployment ID and URL." >&2
exit 1
fi
{
echo "deployment_id=$DEPLOYMENT_ID"
echo "deployment_url=https://$DEPLOYMENT_HOST"
} >> "$GITHUB_OUTPUT"
{
echo "## University Web redeploy"
echo "- Reason: $REDEPLOY_REASON"
echo "- Source branch: $VERCEL_RELEASE_BRANCH"
echo "- Source commit: $RELEASE_SHA"
echo "- Deployment: https://$DEPLOYMENT_HOST"
} >> "$GITHUB_STEP_SUMMARY"
- name: Wait for deployment
env:
DEPLOYMENT_ID: ${{ steps.deploy.outputs.deployment_id }}
run: |
set -euo pipefail
for attempt in $(seq 1 90); do
RESPONSE=$(curl --fail-with-body --silent --show-error \
--header "Authorization: Bearer $VERCEL_TOKEN_UNIV" \
"https://api.vercel.com/v13/deployments/$DEPLOYMENT_ID?teamId=$VERCEL_ORG_ID")
STATE=$(jq -r '.readyState // "UNKNOWN"' <<< "$RESPONSE")
echo "Deployment state: $STATE"
case "$STATE" in
READY)
echo "- Result: READY" >> "$GITHUB_STEP_SUMMARY"
exit 0
;;
ERROR|CANCELED)
echo "- Result: $STATE" >> "$GITHUB_STEP_SUMMARY"
exit 1
;;
esac
sleep 10
done
echo "Vercel deployment did not finish within 15 minutes." >&2
exit 1