-
Notifications
You must be signed in to change notification settings - Fork 0
481 lines (416 loc) · 13.9 KB
/
02-powerpipe-release.yaml
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
name: "02 - Powerpipe: Release"
on:
workflow_dispatch:
inputs:
version:
description: "The version to release (must be prefixed with 'v')"
required: true
env:
PROJECT_ID: steampipe
ORG: turbot
CORE_REPO: us-docker.pkg.dev/steampipe/steampipe
ASSET_IMAGE_NAME: assets
POWERPIPE_UPDATE_CHECK: false
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
VERSION: ${{ github.event.inputs.version }}
jobs:
verify_input:
name: Verify Inputs
runs-on: ubuntu-latest
steps:
- name: Trim asset version prefix and Validate
run: |-
echo $VERSION
trim=${VERSION#"v"}
echo $trim
if [[ $trim =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "Version OK: $trim"
else
echo "Invalid version: $trim"
exit 1
fi
echo "VERSION=${trim}" >> $GITHUB_ENV
- name: Validate Branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.ref }}
goreleaser:
needs: verify_input
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: powerpipe
ref: ${{ github.event.ref }}
- name: Checkout Pipe Fittings Components repository
uses: actions/checkout@v4
with:
repository: turbot/pipe-fittings
path: pipe-fittings
# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704
- name: Build
run: |-
cd powerpipe
make release-dry-run
- name: Move build artifacts
run: |
ls -al $GITHUB_WORKSPACE/powerpipe
sudo chown -R runner:docker $GITHUB_WORKSPACE/powerpipe/dist
mkdir ~/artifacts
mv $GITHUB_WORKSPACE/powerpipe/dist/powerpipe.linux.amd64.tar.gz ~/artifacts/linux.tar.gz
mv $GITHUB_WORKSPACE/powerpipe/dist/powerpipe.darwin.amd64.tar.gz ~/artifacts/darwin.tar.gz
- name: List Build Artifacts
run: ls -l ~/artifacts
- name: Save Linux Build Artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact-linux
path: ~/artifacts/linux.tar.gz
if-no-files-found: error
- name: Save MacOS Build Artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact-darwin
path: ~/artifacts/darwin.tar.gz
if-no-files-found: error
acceptance_test:
name: Test
needs: goreleaser
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest]
test_block:
- "check"
- "resource_show_outputs"
- "dashboard"
- "mod_install"
- "sp_files"
- "mod_vars"
- "snapshot"
- "dashboard_parsing_validation"
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
path: powerpipe
ref: ${{ github.event.ref }}
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: false
- name: Prepare for downloads
id: prepare-for-downloads
run: |
mkdir ~/artifacts
- name: Download Linux Build Artifacts
uses: actions/download-artifact@v3
if: ${{ matrix.platform == 'ubuntu-latest' }}
with:
name: build-artifact-linux
path: ~/artifacts
- name: Download Darwin Build Artifacts
uses: actions/download-artifact@v3
if: ${{ matrix.platform == 'macos-latest' }}
with:
name: build-artifact-darwin
path: ~/artifacts
- name: Extract Darwin Artifacts and Install Binary
if: ${{ matrix.platform == 'macos-latest' }}
run: |
mkdir ~/build
tar -xf ~/artifacts/darwin.tar.gz -C ~/build
- name: Extract Ubuntu Artifacts and Install Binary
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: |
mkdir ~/build
tar -xf ~/artifacts/linux.tar.gz -C ~/build
- name: Install Steampipe(Darwin)
if: ${{ matrix.platform == 'macos-latest' }}
run: |
brew install turbot/tap/steampipe
steampipe -v
- name: Install Steampipe(Linux)
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: |
sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)"
steampipe -v
- name: Set PATH
run: |
echo "PATH=$PATH:$HOME/build:$GTIHUB_WORKSPACE/powerpipe/tests/acceptance/lib/bats-core/libexec" >> $GITHUB_ENV
- name: Go install jd
run: |
go install github.com/josephburnett/jd@latest
- name: Start steamipipe service
run: |
steampipe service start
- name: Run Test Suite
id: run-test-suite
timeout-minutes: 15
continue-on-error: true
run: |
chmod +x $GITHUB_WORKSPACE/powerpipe/tests/acceptance/run.sh
$GITHUB_WORKSPACE/powerpipe/tests/acceptance/run.sh ${{ matrix.test_block }}.bats
echo "exit_code=$(echo $?)" >> $GITHUB_OUTPUT
echo ">> here"
# This job checks whether the test suite has passed or not.
# Since the exit_code is set only when the bats test suite pass,
# we have added the if-conditional block
- name: Check Test Passed/Failed
if: ${{ success() }}
continue-on-error: false
run: |
if [ ${{ steps.run-test-suite.outputs.exit_code }} -eq 0 ]; then
exit 0
else
exit 1
fi
- name: Stop steampipe service
run: |
steampipe service stop
build_assets:
name: Build and Release Dashboard Assets
needs: [acceptance_test]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: powerpipe
ref: ${{ github.event.ref }}
- name: Set VERSION as output
run: echo "::set-output name=version::$VERSION"
id: set_version
- name: Trim asset version prefix and Validate
run: |-
echo $VERSION
trim=${VERSION#"v"}
echo $trim
if [[ $trim =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "Version OK: $trim"
else
echo "Invalid version: $trim"
exit 1
fi
echo "VERSION=${trim}" >> $GITHUB_ENV
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ">=18.12.0"
- name: Setup Yarn
working-directory: ./powerpipe/ui/dashboard
run: |-
rm -rf ./build
# Cache node modules to speed up builds
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: YARN Install
working-directory: ./powerpipe/ui/dashboard
run: |-
unset CI
yarn install
- name: Generate dashboard UI icons
working-directory: ./powerpipe/ui/dashboard
run: |-
make setup-icons
- name: Run Unit Tests
working-directory: ./powerpipe/ui/dashboard
run: |
yarn install
CI=true yarn test
- name: YARN Build
working-directory: ./powerpipe/ui/dashboard
run: |-
unset CI
yarn build
env:
REACT_APP_HEAP_ID: ${{ secrets.HEAP_ANALYTICS_PRODUCTION_ID }}
REACT_APP_VERSION: ${{ env.VERSION }}
- name: Move Build Assets
run: |-
mkdir -p dashboard_ui_build
mv ./powerpipe/ui/dashboard/build/* dashboard_ui_build/
ls -la dashboard_ui_build
- name: Create a version file
run: |-
JSON_STRING=$( jq -n \
--arg version "$VERSION" \
'{
"version":$version,
}' )
echo $JSON_STRING > ./dashboard_ui_build/version.json
- name: Archive built dashboard assets
run: |
cd dashboard_ui_build
tar -czvf ../dashboard_ui_assets.tar.gz *
- name: Upload dashboard assets artifact
uses: actions/upload-artifact@v4
with:
name: dashboard-ui-assets-archive
path: dashboard_ui_assets.tar.gz
ensure_branch_in_homebrew:
name: Ensure branch exists in homebrew-tap
needs: [build_assets]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: turbot/homebrew-tap
token: ${{ secrets.GH_ACCESS_TOKEN }}
ref: main
- name: Delete base branch if exists
run: |
git fetch --all
git push origin --delete powerpipe-brew
git push origin --delete $VERSION
continue-on-error: true
- name: Create base branch
run: |
git checkout -b powerpipe-brew
git push --set-upstream origin powerpipe-brew
build_and_release:
name: Build and Release Powerpipe
needs: [build_assets]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.build_assets.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: powerpipe
ref: ${{ github.event.ref }}
- name: Checkout Pipe Fittings Components repository
uses: actions/checkout@v4
with:
repository: turbot/pipe-fittings
path: pipe-fittings
- name: Tag Release
run: |
cd powerpipe
git config user.name "Powerpipe GitHub Actions Bot"
git config user.email [email protected]
git tag $VERSION
git push origin $VERSION
# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: "1.21"
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704
- name: Download Dashboard UI Assets Artifact
uses: actions/download-artifact@v4
with:
name: dashboard-ui-assets-archive
path: powerpipe/internal/dashboardassets
- name: Check assets location
run: |
ls -la powerpipe/internal/dashboardassets
mv powerpipe/internal/dashboardassets/dashboard_ui_assets.tar.gz powerpipe/internal/dashboardassets/assets.tar.gz
ls -la powerpipe/internal/dashboardassets
- name: Setup release environment
run: |-
cd powerpipe
echo 'GITHUB_TOKEN=${{secrets.GH_ACCESS_TOKEN}}' > .release-env
- name: Release publish
run: |-
cd powerpipe
make release
create_pr_in_homebrew:
name: Create PR in homebrew-tap
needs: [ensure_branch_in_homebrew, build_and_release]
runs-on: ubuntu-latest
env:
Version: ${{ github.event.inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: turbot/homebrew-tap
token: ${{ secrets.GH_ACCESS_TOKEN }}
ref: main
- name: Create a new branch off the base branch
run: |
git fetch --all
git checkout powerpipe-brew
git checkout -b $VERSION
git push --set-upstream origin $VERSION
- name: Close pull request if already exists
run: |
gh pr close $VERSION
continue-on-error: true
- name: Create pull request
run: |
gh pr create --base main --head $VERSION --title "$Version" --body "Update formula"
update_pr_for_versioning:
name: Update PR
needs: [create_pr_in_homebrew]
runs-on: ubuntu-latest
env:
Version: ${{ github.event.inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: turbot/homebrew-tap
token: ${{ secrets.GH_ACCESS_TOKEN }}
ref: ${{ github.event.inputs.version }}
- name: Update live version
run: |
scripts/formula_versioning_powerpipe.sh
git config --global user.email "[email protected]"
git config --global user.name "Powerpipe GitHub Actions Bot"
git add .
git commit -m "Versioning brew formulas"
git push origin $VERSION
update_homebrew_tap:
name: Update homebrew-tap formula
needs: [update_pr_for_versioning]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: turbot/homebrew-tap
token: ${{ secrets.GH_ACCESS_TOKEN }}
ref: main
- name: Get pull request title
id: pr_title
run: >-
echo "PR_TITLE=$(
gh pr view $VERSION --json title | jq .title | tr -d '"'
)" >> $GITHUB_OUTPUT
- name: Output
run: |
echo ${{ steps.pr_title.outputs.PR_TITLE }}
echo ${{ env.VERSION }}
- name: Fail if PR title does not match with version
run: |
if ${{ (steps.pr_title.outputs.PR_TITLE == env.VERSION) }} == 'true';then
echo "Correct version"
else
echo "Incorrect version"
exit 1
fi
- name: Merge pull request to update brew formula
run: |
git fetch --all
gh pr merge $VERSION --squash --delete-branch
git push origin --delete powerpipe-brew