Skip to content

Commit e92476c

Browse files
authored
chore: use reusable workflows (#304)
* feat: reintroduce OpenAPI schema workflow with bundling and deployment steps Signed-off-by: Bailin He <bahe@equinix.com> * feat: refactor Docker build process to use reusable workflow and streamline artifact handling Signed-off-by: Bailin He <bahe@equinix.com> * fix: reorder job dependencies for build-go and build-docker Signed-off-by: Bailin He <bahe@equinix.com> * fix(deps): update action versions in main workflow to v0.0.1 Signed-off-by: Bailin He <bahe@equinix.com> --------- Signed-off-by: Bailin He <bahe@equinix.com>
1 parent 75106d5 commit e92476c

File tree

2 files changed

+32
-95
lines changed

2 files changed

+32
-95
lines changed

.github/workflows/main.yaml

Lines changed: 25 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ jobs:
1111
name: ⚙️ setup
1212
runs-on: ubuntu-latest
1313
outputs:
14-
image_tag: ${{ steps.vars.outputs.image-tag }}
14+
image_tag: ${{ github.run_number }}-${{ steps.shortsha.outputs.short-sha }}
15+
image_repo: ${{ env.IMAGE_REPO }}
16+
app_name: ${{ env.APP_NAME }}
1517
steps:
16-
- id: vars
17-
run: |
18-
SHORT_SHA="${GITHUB_SHA:0:8}"
19-
echo "image-tag=${{ github.run_number }}-${SHORT_SHA}" >> $GITHUB_OUTPUT
18+
- id: shortsha
19+
uses: metal-toolbox/ci-toolbox/actions/short-sha@v0.0.1
2020

2121
lint:
2222
name: 📎 lint
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26-
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
27-
with:
28-
go-version-file: 'go.mod'
29-
- uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 #v9.2.0
25+
- uses: metal-toolbox/ci-toolbox/actions/golangci-lint@v0.0.1
3026

3127
test:
3228
name: 🧪 test
@@ -56,117 +52,51 @@ jobs:
5652
build-go:
5753
name: 🏗️ build go
5854
runs-on: ubuntu-latest
59-
needs:
60-
- lint
61-
- test
6255
env:
6356
CGO_ENABLED: 0
6457
GOOS: linux
6558
steps:
66-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
67-
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
68-
with:
69-
go-version-file: 'go.mod'
59+
- uses: metal-toolbox/ci-toolbox/actions/setup-go@v0.0.1
7060
- name: build
7161
run: go build -buildvcs=false -mod=mod -a -o bin/${{ env.APP_NAME }}
7262
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
7363
with:
7464
name: ${{ env.APP_NAME }}-bin
7565
path: bin/${{ env.APP_NAME }}
66+
outputs:
67+
artifact-name: ${{ env.APP_NAME }}-bin
7668

7769
build-docker:
7870
name: 🐳 build and publish docker image
79-
runs-on: ubuntu-latest
8071
needs:
72+
- lint
73+
- test
8174
- build-go
8275
- setup
8376
permissions:
8477
contents: write
8578
id-token: write
8679
packages: write
87-
steps:
88-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
89-
- uses: sigstore/cosign-installer@v4.0.0
90-
- uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
91-
id: meta
92-
with:
93-
images: ${{ env.IMAGE_REPO }}
94-
- name: login GHCR
95-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
96-
with:
97-
registry: ghcr.io
98-
username: ${{ github.actor }}
99-
password: ${{ secrets.GITHUB_TOKEN }}
100-
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
101-
with:
102-
name: ${{ env.APP_NAME }}-bin
103-
path: bin
104-
- name: build and push
105-
id: build-push
106-
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
107-
with:
108-
context: .
109-
push: ${{ github.ref == 'refs/heads/main' }}
110-
load: true
111-
file: Dockerfile
112-
build-args: BIN=bin/${{ env.APP_NAME }}
113-
labels: ${{ steps.meta.outputs.labels }}
114-
tags: |
115-
${{ steps.meta.outputs.tags }}
116-
${{ env.IMAGE_REPO }}:${{ needs.setup.outputs.image_tag }}
117-
- name: Save image as tar for scanning
118-
run: docker save ${{ env.IMAGE_REPO }}:${{ needs.setup.outputs.image_tag }} -o image.tar
119-
- name: Upload image artifact
120-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
121-
with:
122-
name: docker-image
123-
path: image.tar
124-
retention-days: 1
125-
- name: sign image
126-
if: github.ref == 'refs/heads/main'
127-
run: cosign sign --yes ${{ env.IMAGE_REPO }}@${{ steps.build-push.outputs.digest }}
80+
uses: metal-toolbox/ci-toolbox/.github/workflows/build-docker.yaml@v0.0.1
81+
with:
82+
artifact-name: ${{ needs.build-go.outputs.artifact-name }}
83+
artifact-path: bin
84+
user: ${{ github.actor }}
85+
image-repo: ${{ needs.setup.outputs.image_repo }}
86+
image-tag: ${{ needs.setup.outputs.image_tag }}
87+
build-args: |
88+
BIN=bin/${{ needs.setup.outputs.app_name }}
89+
secrets: inherit
12890

12991
trivy-scan:
13092
name: 🔍 scan image
131-
runs-on: ubuntu-latest
13293
needs:
13394
- build-docker
13495
- setup
13596
permissions:
13697
contents: read
13798
security-events: write
138-
steps:
139-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
140-
- name: Download image artifact
141-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
142-
with:
143-
name: docker-image
144-
path: .
145-
- name: full scan with Trivy
146-
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
147-
env:
148-
TRIVY_DEBUG: true
149-
with:
150-
input: 'image.tar'
151-
format: 'sarif'
152-
output: 'trivy-results.sarif'
153-
exit-code: '0'
154-
- name: fail with high critical
155-
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
156-
with:
157-
input: 'image.tar'
158-
format: 'table'
159-
severity: 'HIGH,CRITICAL'
160-
output: 'trivy-high-results.txt'
161-
exit-code: '1'
162-
- name: job summary
163-
run: |
164-
# step summary
165-
echo '```' >> $GITHUB_STEP_SUMMARY
166-
cat trivy-high-results.txt >> $GITHUB_STEP_SUMMARY
167-
echo '```' >> $GITHUB_STEP_SUMMARY
168-
- name: Upload Trivy results to Security tab
169-
if: always()
170-
uses: github/codeql-action/upload-sarif@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
171-
with:
172-
sarif_file: 'trivy-results.sarif'
99+
uses: metal-toolbox/ci-toolbox/.github/workflows/trivy.yaml@v0.0.1
100+
with:
101+
scan-type: image
102+
image-ref: ${{ needs.setup.outputs.image_repo }}:${{ needs.setup.outputs.image_tag }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ jobs:
2020
- name: Bundle OpenAPI Spec
2121
run: |
2222
redocly bundle openapi/v1alpha1/openapi.yaml -o _site/openapi-bundle.yaml
23+
redocly bundle openapi/v1alpha1/openapi.yaml -o _site/openapi-bundle.json
2324
redocly build-docs openapi/v1alpha1/openapi.yaml --title "Governor API" -o _site/index.html
2425
- name: Upload OpenAPI Bundle
2526
uses: actions/upload-pages-artifact@v4
2627
with:
2728
retention-days: 1
29+
- name: Upload to Release
30+
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
31+
with:
32+
files: |
33+
_site/openapi-bundle.json
34+
_site/openapi-bundle.yaml
2835
2936
publish-pages:
3037
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)