-
Notifications
You must be signed in to change notification settings - Fork 1
186 lines (170 loc) · 5.78 KB
/
Copy pathci-server-reusable.yml
File metadata and controls
186 lines (170 loc) · 5.78 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
name: Server CI Reusable
on:
workflow_call:
inputs:
should_run:
required: false
default: true
type: boolean
job_name:
required: true
type: string
build_script:
required: true
type: string
test_script:
required: true
type: string
test_working_directory:
required: true
type: string
run_integration_tests:
required: false
default: false
type: boolean
integration_test_script:
required: false
default: ""
type: string
integration_test_working_directory:
required: false
default: ""
type: string
dockerfile:
required: true
type: string
image_ref:
required: true
type: string
trivy_results_file:
required: true
type: string
trivy_sarif_file:
required: true
type: string
trivy_scan_label:
required: true
type: string
sarif_category:
required: true
type: string
jobs:
server:
name: ${{ inputs.job_name }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
if: inputs.should_run
uses: actions/checkout@v4
- name: Use Node.js 24.x
if: inputs.should_run
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: npm
cache-dependency-path: package-lock.json
- name: Install dependencies (monorepo)
if: inputs.should_run
run: npm ci --workspaces
- name: Build shared package
if: inputs.should_run
run: npm run build:shared
- name: Build target server
if: inputs.should_run
run: ${{ inputs.build_script }}
- name: Run tests
if: inputs.should_run
run: ${{ inputs.test_script }}
working-directory: ${{ inputs.test_working_directory }}
- name: Run integration tests
if: inputs.should_run && inputs.run_integration_tests
run: ${{ inputs.integration_test_script }}
working-directory: ${{ inputs.integration_test_working_directory }}
env:
TRUVERA_RUN_LIVE_TESTS: ${{ vars.TRUVERA_RUN_LIVE_TESTS }}
TRUVERA_API_ENDPOINT: ${{ vars.TRUVERA_API_ENDPOINT }}
TRUVERA_API_KEY: ${{ secrets.TRUVERA_API_KEY }}
- name: Set up Docker Buildx
if: inputs.should_run
uses: docker/setup-buildx-action@v3
- name: Build image for scanning
if: inputs.should_run
uses: docker/build-push-action@v6
with:
context: .
file: ${{ inputs.dockerfile }}
load: true
tags: ${{ inputs.image_ref }}
build-args: |
BUILD_NUMBER=${{ github.run_number }}
- name: Scan image for HIGH and CRITICAL vulnerabilities
id: trivy_scan
if: inputs.should_run
continue-on-error: true
uses: aquasecurity/trivy-action@v0.35.0
env:
# Not exposed as a trivy-action input; Trivy reads it directly.
# Suppresses the "Report Summary" table (one row per scanned
# package.json, almost all showing 0 vulnerabilities in a project
# this size) so the output only shows targets with actual findings.
# Must not be set on the SARIF step below — Trivy errors if
# table-mode is set with a non-table format.
TRIVY_TABLE_MODE: detailed
with:
image-ref: ${{ inputs.image_ref }}
format: table
output: ${{ inputs.trivy_results_file }}
ignore-unfixed: true
severity: HIGH,CRITICAL
exit-code: '1'
trivyignores: .trivyignore
- name: Add Trivy report to job summary
if: always() && inputs.should_run
run: |
{
echo "## ${{ inputs.trivy_scan_label }}"
echo
if [ "${{ steps.trivy_scan.outcome }}" = "failure" ]; then
echo "**Status:** FAILED (HIGH/CRITICAL vulnerabilities found)"
else
echo "**Status:** PASSED (no HIGH/CRITICAL vulnerabilities found)"
fi
echo
echo "<details><summary>Full Trivy output</summary>"
echo
echo '```text'
cat "${{ inputs.trivy_results_file }}"
echo '```'
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
- name: Generate Trivy SARIF report
if: always() && inputs.should_run
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: ${{ inputs.image_ref }}
format: sarif
output: ${{ inputs.trivy_sarif_file }}
ignore-unfixed: true
severity: HIGH,CRITICAL
exit-code: '0'
trivyignores: .trivyignore
- name: Upload Trivy SARIF to GitHub Security
id: trivy_sarif_upload
continue-on-error: true
if: always() && inputs.should_run
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: ${{ inputs.trivy_sarif_file }}
category: ${{ inputs.sarif_category }}
- name: Add SARIF upload status to job summary
if: always() && inputs.should_run && steps.trivy_sarif_upload.outcome == 'failure'
run: |
echo >> "$GITHUB_STEP_SUMMARY"
echo "## SARIF Upload" >> "$GITHUB_STEP_SUMMARY"
echo >> "$GITHUB_STEP_SUMMARY"
echo "SARIF upload was skipped or failed. GitHub code scanning may not be enabled for this repository." >> "$GITHUB_STEP_SUMMARY"
- name: Fail job if Trivy found HIGH/CRITICAL issues
if: inputs.should_run && steps.trivy_scan.outcome == 'failure'
run: |
echo "Trivy detected HIGH/CRITICAL vulnerabilities. See job summary and Security tab for details."
exit 1