-
Notifications
You must be signed in to change notification settings - Fork 23
317 lines (265 loc) · 10.6 KB
/
Copy pathci-cd.yml
File metadata and controls
317 lines (265 loc) · 10.6 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: CI/CD Pipeline
on:
push:
branches:
- main
- master
- 'poc/**'
pull_request:
branches:
- main
- master
workflow_dispatch:
# Disable concurrent builds
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
# Send notifications to Slack on failure (production branches only)
# Note: You'll need to set up a Slack webhook integration
# https://github.com/marketplace/actions/slack-send
jobs:
validate-tag:
name: Validate Release Tag
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check tag matches semver
env:
TAG: ${{ github.ref_name }}
run: |
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?$ ]]; then
echo "Tag '$TAG' is not a valid semver tag (expected vX.Y.Z or vX.Y.Z-suffix)" >&2
exit 1
fi
echo "Tag '$TAG' is valid semver"
test-portal-generator:
name: Test Portal Generator
needs: validate-tag
if: always() && (needs.validate-tag.result == 'success' || needs.validate-tag.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: scripts/package-lock.json
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Install Node.js dependencies
run: cd scripts && npm install --ignore-scripts
- name: Run portal generator tests
run: make test-portal
generate-portal:
name: Generate Portal
needs: test-portal-generator
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Generate portal
run: 'make generate-portal BUILD_LABEL="${{ github.ref_name }}: ${{ github.sha }}"'
env:
BRANCH_NAME: ${{ github.ref_name }}
GIT_COMMIT: ${{ github.sha }}
- name: Upload portal artifacts
uses: actions/upload-artifact@v4
with:
name: portal
path: portal/
retention-days: 30
validate-specs:
name: Validate Specs
needs: generate-portal
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Anypoint CLI
run: |
npm install -g anypoint-cli-v4
anypoint-cli-v4 plugins:install anypoint-cli-api-project-plugin
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Run validation
run: |
make validate-all-governed SKIP_GOVERNED="arm-monitoring-query"
make validate-xorigin
make validate-jtbd
make validate-skills
env:
ANYPOINT_USERNAME: ${{ secrets.ANYPOINT_USERNAME }}
ANYPOINT_PASSWORD: ${{ secrets.ANYPOINT_PASSWORD }}
deploy-to-test:
name: Deploy to Test
needs: validate-specs
runs-on: ubuntu-latest
# Only run on master branch
if: github.ref == 'refs/heads/master'
environment:
name: test
url: https://test-dev-portal.mulesoft.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
printf '%s\n' "${AKAMAI_PRIVATE_SSH_KEY}" > ~/.ssh/akamai_key
chmod 600 ~/.ssh/akamai_key
ssh-keygen -lf ~/.ssh/akamai_key > /dev/null && echo "key parses OK"
env:
AKAMAI_PRIVATE_SSH_KEY: ${{ secrets.AKAMAI_PRIVATE_SSH_KEY }}
- name: Install lftp
run: sudo apt-get update && sudo apt-get install -y lftp
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Generate portal for test
run: 'make generate-portal BUILD_LABEL="${{ github.ref_name }}: ${{ github.sha }}" BASE_URL=https://test-dev-portal.mulesoft.com'
env:
BRANCH_NAME: ${{ github.ref_name }}
GIT_COMMIT: ${{ github.sha }}
- name: Deploy to Akamai test
run: |
echo "Deploying portal to TEST environment"
lftp -u "${AKAMAI_USER},${AKAMAI_PASS}" -e "set sftp:connect-program 'ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i ~/.ssh/akamai_key'; mirror -R --overwrite --no-perms --verbose portal/ ${AKAMAI_BASE_PATH}/test; quit" "sftp://${AKAMAI_HOST}"
env:
AKAMAI_HOST: ${{ secrets.AKAMAI_HOST }}
AKAMAI_USER: ${{ secrets.AKAMAI_USER }}
AKAMAI_PASS: ${{ secrets.AKAMAI_PASS }}
AKAMAI_BASE_PATH: ${{ secrets.AKAMAI_BASE_PATH }}
deploy-to-poc:
name: Deploy to POC
needs: validate-specs
runs-on: ubuntu-latest
# Only run on poc/* branches
if: startsWith(github.ref, 'refs/heads/poc/')
environment:
name: poc
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
printf '%s\n' "${AKAMAI_PRIVATE_SSH_KEY}" > ~/.ssh/akamai_key
chmod 600 ~/.ssh/akamai_key
ssh-keygen -lf ~/.ssh/akamai_key > /dev/null && echo "key parses OK"
env:
AKAMAI_PRIVATE_SSH_KEY: ${{ secrets.AKAMAI_PRIVATE_SSH_KEY }}
- name: Install lftp
run: sudo apt-get update && sudo apt-get install -y lftp
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Derive POC name
id: poc
run: |
raw="${GITHUB_REF_NAME#poc/}"
# Lowercase, replace any non-alphanumeric run with a single hyphen, trim leading/trailing hyphens
sanitized="$(printf '%s' "$raw" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')"
if [ -z "$sanitized" ]; then
echo "Branch '$GITHUB_REF_NAME' produced an empty POC name after sanitization" >&2
exit 1
fi
echo "name=$sanitized" >> "$GITHUB_OUTPUT"
echo "Deploying POC as: $sanitized"
- name: Generate portal for POC
run: 'make generate-portal BUILD_LABEL="${{ github.ref_name }}: ${{ github.sha }}" BASE_URL=https://test-dev-portal.mulesoft.com/pocs/${{ steps.poc.outputs.name }} PROXY_URL=https://test-dev-portal.mulesoft.com/proxy'
env:
BRANCH_NAME: ${{ github.ref_name }}
GIT_COMMIT: ${{ github.sha }}
- name: Deploy to Akamai POC
run: |
echo "Deploying portal to POC environment | POC=${POC_NAME}"
lftp -u "${AKAMAI_USER},${AKAMAI_PASS}" -e "set sftp:connect-program 'ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i ~/.ssh/akamai_key'; mirror -R --overwrite --no-perms --verbose portal/ ${AKAMAI_BASE_PATH}/test/pocs/${POC_NAME}; quit" "sftp://${AKAMAI_HOST}"
env:
AKAMAI_HOST: ${{ secrets.AKAMAI_HOST }}
AKAMAI_USER: ${{ secrets.AKAMAI_USER }}
AKAMAI_PASS: ${{ secrets.AKAMAI_PASS }}
AKAMAI_BASE_PATH: ${{ secrets.AKAMAI_BASE_PATH }}
POC_NAME: ${{ steps.poc.outputs.name }}
deploy-to-production:
name: Deploy to Production
needs: validate-specs
runs-on: ubuntu-latest
# Only run against a release tag (vX.Y.Z), dispatched manually via workflow_dispatch
if: startsWith(github.ref, 'refs/tags/')
environment:
name: production
url: https://dev-portal.mulesoft.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
printf '%s\n' "${AKAMAI_PRIVATE_SSH_KEY}" > ~/.ssh/akamai_key
chmod 600 ~/.ssh/akamai_key
ssh-keygen -lf ~/.ssh/akamai_key > /dev/null && echo "key parses OK"
env:
AKAMAI_PRIVATE_SSH_KEY: ${{ secrets.AKAMAI_PRIVATE_SSH_KEY }}
- name: Install lftp
run: sudo apt-get update && sudo apt-get install -y lftp
- name: Install Python dependencies
run: pip3 install --no-cache-dir -r scripts/requirements.txt
- name: Generate portal for production
run: 'make generate-portal BUILD_LABEL="${{ github.ref_name }}: ${{ github.sha }}" BASE_URL=https://dev-portal.mulesoft.com'
env:
BRANCH_NAME: ${{ github.ref_name }}
GIT_COMMIT: ${{ github.sha }}
- name: Deploy to Akamai production
run: |
echo "Deploying portal to PRODUCTION environment"
lftp -u "${AKAMAI_USER},${AKAMAI_PASS}" -e "set sftp:connect-program 'ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i ~/.ssh/akamai_key'; mirror -R --overwrite --no-perms --verbose portal/ ${AKAMAI_BASE_PATH}/prod; quit" "sftp://${AKAMAI_HOST}"
env:
AKAMAI_HOST: ${{ secrets.AKAMAI_HOST }}
AKAMAI_USER: ${{ secrets.AKAMAI_USER }}
AKAMAI_PASS: ${{ secrets.AKAMAI_PASS }}
AKAMAI_BASE_PATH: ${{ secrets.AKAMAI_BASE_PATH }}
notify-on-failure:
name: Notify on Failure
needs: [validate-tag, test-portal-generator, generate-portal, validate-specs, deploy-to-test, deploy-to-production]
runs-on: ubuntu-latest
if: |
failure() &&
(github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
steps:
- name: Send Slack notification
uses: slackapi/slack-github-action@v1.25.0
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: '{"text":"Pipeline failed: ${{ github.repository }} - Branch: ${{ github.ref_name }} - Commit: ${{ github.sha }} - Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}'