-
Notifications
You must be signed in to change notification settings - Fork 23
269 lines (221 loc) · 8.63 KB
/
Copy pathci-cd.yml
File metadata and controls
269 lines (221 loc) · 8.63 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
name: CI/CD Pipeline
on:
push:
branches:
- main
- master
- 'release/**'
- 'poc/**'
pull_request:
branches:
- main
- master
# 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:
test-portal-generator:
name: 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: 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
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: 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 | Host=${AKAMAI_HOST} User=${AKAMAI_USERNAME}"
lftp -u "${AKAMAI_USERNAME},${AKAMAI_PASSWORD}" "ftp://${AKAMAI_HOST}" -e "set ftp:ssl-allow no; mirror -R --overwrite --no-perms --verbose portal/ /564243/api-portal.mulesoft.com/test; quit"
env:
AKAMAI_HOST: 564243.ftp.upload.akamai.com
AKAMAI_USERNAME: API_Portal_Team
AKAMAI_PASSWORD: ${{ secrets.AKAMAI_PASSWORD }}
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: 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 }}'
env:
BRANCH_NAME: ${{ github.ref_name }}
GIT_COMMIT: ${{ github.sha }}
- name: Deploy to Akamai POC
run: |
echo "Deploying portal to POC environment | Host=${AKAMAI_HOST} User=${AKAMAI_USERNAME} POC=${POC_NAME}"
lftp -u "${AKAMAI_USERNAME},${AKAMAI_PASSWORD}" "ftp://${AKAMAI_HOST}" -e "set ftp:ssl-allow no; mirror -R --overwrite --no-perms --verbose portal/ /564243/api-portal.mulesoft.com/test/pocs/${POC_NAME}; quit"
env:
AKAMAI_HOST: 564243.ftp.upload.akamai.com
AKAMAI_USERNAME: API_Portal_Team
AKAMAI_PASSWORD: ${{ secrets.AKAMAI_PASSWORD }}
POC_NAME: ${{ steps.poc.outputs.name }}
deploy-to-production:
name: Deploy to Production
needs: validate-specs
runs-on: ubuntu-latest
# Only run on release branches (release/*)
if: startsWith(github.ref, 'refs/heads/release/')
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: 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 | Host=${AKAMAI_HOST} User=${AKAMAI_USERNAME}"
lftp -u "${AKAMAI_USERNAME},${AKAMAI_PASSWORD}" "ftp://${AKAMAI_HOST}" -e "set ftp:ssl-allow no; mirror -R --overwrite --no-perms --verbose portal/ /564243/api-portal.mulesoft.com/prod; quit"
env:
AKAMAI_HOST: 564243.ftp.upload.akamai.com
AKAMAI_USERNAME: API_Portal_Team
AKAMAI_PASSWORD: ${{ secrets.AKAMAI_PASSWORD }}
notify-on-failure:
name: Notify on Failure
needs: [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/heads/release/'))
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 }}"}'