-
Notifications
You must be signed in to change notification settings - Fork 60
293 lines (287 loc) · 14.4 KB
/
pipeline.yml
File metadata and controls
293 lines (287 loc) · 14.4 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
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
strategy:
# fail-fast: false # run all matrix build and not stop on the first failure
matrix:
os: [ubuntu-latest, windows-2025, macos-latest]
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
# not just the latest version of mac os also amd on Mac
# os: [ubuntu-latest, windows-2025, macos-13, macos-14, macos-14-large, macos-15, macos-latest-large]
node-version: [20.x, 22.x]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- name: Checkout code repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
run_install: |
- args: [--frozen-lockfile]
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ matrix.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ matrix.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Install pnpm modules
run: pnpm install --frozen-lockfile
- name: Run build
run: pnpm run build
env:
NX_CLOUD_ACCESS_TOKEN: ${{ github.event.pull_request.head.repo.full_name == github.repository && secrets.NX_CLOUD_ACCESS_TOKEN || '' }}
- name: Run lint on forks
if: github.event.pull_request.head.repo.full_name != github.repository
run: pnpm run lint
- name: Run unit tests
run: pnpm run test --tuiAutoExit
env:
NX_CLOUD_ACCESS_TOKEN: ${{ github.event.pull_request.head.repo.full_name == github.repository && secrets.NX_CLOUD_ACCESS_TOKEN || '' }}
- name: Check for changeset files
id: check_changeset_files
uses: andstor/file-existence-action@v3
with:
files: '.changeset/[!README]*.md'
fail: false
- name: Validate changeset files if found
if: steps.check_changeset_files.outputs.files_exists == 'true'
run: pnpm changeset status
- name: Cache playwright browsers
id: cache-playwright-browsers
uses: actions/cache@v4
with:
path: |
${{ runner.os == 'Windows' }}:
C:\Users\runneradmin\AppData\Local\ms-playwright
${{ runner.os != 'Windows' }}:
~/.cache/ms-playwright
key: playwright-browsers-os-${{ matrix.os }}-node-version-${{ matrix.node-version }}
- name: Install playwright chrome browsers
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
run: npx playwright install chrome
- name: Run integration tests
run: pnpm run test:integration
env:
NX_CLOUD_ACCESS_TOKEN: ${{ github.event.pull_request.head.repo.full_name == github.repository && secrets.NX_CLOUD_ACCESS_TOKEN || '' }}
- name: Upload playwright reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-reports-os-${{ matrix.os }}-node-version-${{ matrix.node-version }}
path: |
packages/*/playwright-report
!packages/*/node_modules
retention-days: 15
- name: Run SonarCloud scan
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
shell: bash
run: |
echo ${{ github.event.pull_request.number }} >> pr-event.txt
echo ${{ github.event.pull_request.head.ref }} >> pr-event.txt
echo ${{ github.event.pull_request.base.ref }} >> pr-event.txt
- name: 'Prepare output artifact'
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
shell: bash
run: touch output.tar && tar --exclude='./node_modules' --exclude='./dist' --exclude='./**/node_modules/**' --exclude='./**/dist/**' --exclude='./.git' --exclude 'output.tar' -czf output.tar .
- name: 'Upload sonar artifact'
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
uses: actions/upload-artifact@v4
with:
name: sonar-artifact
path: |
pr-event.txt
output.tar
if-no-files-found: error
retention-days: 1
version:
# Run version job only on pushes to the main branch. The job depends on completion of the build job.
if: github.repository == 'SAP/open-ux-tools' && github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build
outputs:
changes: ${{ steps.changesetVersion.outputs.changes }} # map step output to job output
steps:
- name: Checkout code repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.ACCESS_PAT }}
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
run_install: |
- args: [--frozen-lockfile]
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Use Node.js 20.x
uses: actions/setup-node@v6
with:
node-version: 20.x
- name: Install pnpm modules
run: pnpm install --frozen-lockfile
- name: Apply changesets
id: changesetVersion
run: |
echo ::set-output name=changes::$(pnpm ci:version 2>&1 | grep -q 'No unreleased changesets found' && echo 'false' || echo 'true')
git status
- name: Commit and push changes
if: steps.changesetVersion.outputs.changes == 'true'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git status
git add -A
git status
git commit -m "chore: apply latest changesets" --no-verify || echo "No changesets found"
git log --pretty=oneline | head -n 10
git push
release:
# Run release job only on pushes to the main branch. The job depends on completion of the build job.
# This job needs to run after the version job commit has been merged - so check if that step returns 'false'
if: github.repository == 'SAP/open-ux-tools' && github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.version.outputs.changes == 'false'
runs-on: ubuntu-latest
needs: version
steps:
- name: Checkout code repository
uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4.1.0
with:
run_install: |
- args: [--frozen-lockfile]
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Use Node.js 20.x
uses: actions/setup-node@v6
with:
node-version: 20.x
- name: Install pnpm modules
run: pnpm install --frozen-lockfile
- name: Set instrumentation key in fiori-mcp-server
uses: jacobtomlinson/gha-find-replace@v3
with:
include: packages/fiori-mcp-server/src/telemetry/index.ts
find: 'ApplicationInsightsInstrumentationKeyPLACEH0LDER'
replace: ${{ secrets.INSTRUMENTATION_KEY }}
regex: false
- name: Set instrumentation key in generator-odata-downloader
uses: jacobtomlinson/gha-find-replace@v3
with:
include: packages/generator-odata-downloader/src/telemetry/index.ts
find: 'ApplicationInsightsInstrumentationKeyPLACEH0LDER'
replace: ${{ secrets.INSTRUMENTATION_KEY }}
regex: false
- name: Set instrumentation key in sap-systems-ext
uses: jacobtomlinson/gha-find-replace@v3
with:
include: packages/sap-systems-ext/src/utils/telemetryHelper.ts
find: 'ApplicationInsightsInstrumentationKeyPLACEH0LDER'
replace: ${{ secrets.INSTRUMENTATION_KEY }}
regex: false
- name: Run build
run: pnpm run build
- name: Setup npmrc with npmjs.com token
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPMJS_TOKEN }}" > .npmrc
- name: 'Publish to npmjs'
id: changesetPublish
uses: changesets/action@v1.7.0
with:
publish: pnpm ci:publish
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_PAT }}
- name: Detect extension publication
if: steps.changesetPublish.outputs.published == 'true'
run: |
PUBLISHED=$(echo '${{ steps.changesetPublish.outputs.publishedPackages }}' | jq -r '.[].name')
# Extract the first package name matching sap-ux-*-ext
EXT_PKG=$(echo "$PUBLISHED" | grep -E '^sap-ux-.*-ext$' | head -n 1 || true)
if [ -n "$EXT_PKG" ]; then
echo "EXTENSION_UPDATED=true" >> $GITHUB_ENV
echo "EXT_PKG=$EXT_PKG" >> $GITHUB_ENV
# Strip 'sap-ux-' prefix to derive directory name
EXT_DIR_NAME=$(echo "$EXT_PKG" | sed 's/^sap-ux-//')
echo "EXT_DIR=packages/${EXT_DIR_NAME}" >> $GITHUB_ENV
else
echo "EXTENSION_UPDATED=false" >> $GITHUB_ENV
fi
- name: Read extension version
if: env.EXTENSION_UPDATED == 'true'
run: |
EXT_VERSION=$(jq -r '.version' "${{ env.EXT_DIR }}/package.json")
echo "EXT_VERSION=$EXT_VERSION" >> $GITHUB_ENV
- name: Package VSCode extension
if: env.EXTENSION_UPDATED == 'true'
run: pnpm --filter ${{ env.EXT_PKG }} ide-ext:package
- name: Create GitHub Release (extension)
if: env.EXTENSION_UPDATED == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.EXT_PKG }}@${{ env.EXT_VERSION }}
name: ${{ env.EXT_PKG }} v${{ env.EXT_VERSION }}
body: 'Extension release: ${{ env.EXT_PKG }} v${{ env.EXT_VERSION }}'
draft: true
prerelease: false
generate_release_notes: true
files: ${{ env.EXT_DIR }}/*.vsix
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_PAT }}
- name: Prepare Slack notification message (published packages)
if: steps.changesetPublish.outputs.published == 'true'
run: |
# Random delimiter required to support multi-line environment variable value
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "PUBLISHED_PACKAGES_MESSAGE<<$EOF" >> $GITHUB_ENV
# publishedPackages JSON format: '[{"name": "@sap-ux/axios-extension", "version": "1.0.2"}, {"name": "@sap-ux/fiori-freestyle-writer", "version": "0.15.12"}]'
echo "$(echo '${{ steps.changesetPublish.outputs.publishedPackages }}' | jq --raw-output 'map("*" + .name + "*" + " - " + "<https://www.npmjs.com/package/" + .name + "|" + .version + ">") | join("\\n")')" >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV
- name: Prepare Slack notification message (extension release only)
if: env.EXTENSION_UPDATED == 'true'
run: |
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ env.EXT_PKG }}@${{ env.EXT_VERSION }}"
echo "EXT_RELEASE_MESSAGE=:package: Extension *${{ env.EXT_PKG }}* v${{ env.EXT_VERSION }} released - <${RELEASE_URL}|View on GitHub>" >> $GITHUB_ENV
- name: Send Slack notification (published packages)
if: steps.changesetPublish.outputs.published == 'true'
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{"text": ":rocket: The following packages were published to npmjs.com:\n${{ env.PUBLISHED_PACKAGES_MESSAGE }}" }
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send Slack notification (extension release)
if: env.EXTENSION_UPDATED == 'true'
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{"text": "${{ env.EXT_RELEASE_MESSAGE }}" }
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}