-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (174 loc) · 7.23 KB
/
.reusable-ci.yml
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: ci
permissions: {}
on:
workflow_call:
inputs:
skip_build:
description: "Want to skip running certain build jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_compliance_checks:
description: "Want to skip running certain compliance jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_unit_tests:
description: "Want to skip running certain unit test jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_sast:
description: "Want to skip running certain sast jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_sca:
description: "Want to skip running certain sca jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_docs:
description: "Want to skip running certain docs jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
skip_integration_tests:
description: "Want to skip running certain integration test jobs 'none', 'non-required', 'all'?"
type: string
default: "all"
required: false
output_type:
description: 'Output either "sarif" (GITHUB_TOKEN with security-events:write) or print results as "table" and fail on error'
type: string
default: 'sarif'
required: false
defaults:
run:
shell: bash
jobs:
conditionals:
runs-on: ubuntu-latest
outputs:
skip_build: ${{ steps.conditionals.outputs.skip_build }}
skip_compliance_checks: ${{ steps.conditionals.outputs.skip_compliance_checks }}
skip_unit_tests: ${{ steps.conditionals.outputs.skip_unit_tests }}
skip_sast: ${{ steps.conditionals.outputs.skip_sast }}
skip_sca: ${{ steps.conditionals.outputs.skip_sca }}
skip_docs: ${{ steps.conditionals.outputs.skip_docs }}
skip_integration_tests: ${{ steps.conditionals.outputs.skip_integration_tests }}
output_type: ${{ steps.conditionals.outputs.output_type }}
steps:
- name: CI conditionals
id: conditionals
run: |
echo "skip_build=${{ inputs.skip_build }}" >> ${GITHUB_OUTPUT}
echo "skip_compliance_checks=${{ inputs.skip_compliance_checks }}" >> ${GITHUB_OUTPUT}
echo "skip_unit_tests=${{ inputs.skip_unit_tests }}" >> ${GITHUB_OUTPUT}
echo "skip_sast=${{ inputs.skip_sast }}" >> ${GITHUB_OUTPUT}
echo "skip_sca=${{ inputs.skip_sca }}" >> ${GITHUB_OUTPUT}
echo "skip_docs=${{ inputs.skip_docs }}" >> ${GITHUB_OUTPUT}
echo "skip_integration_tests=${{ inputs.skip_integration_tests }}" >> ${GITHUB_OUTPUT}
echo "output_type=${{ inputs.output_type }}" >> ${GITHUB_OUTPUT}
- name: Show conditionals
id: show_conditionals
run: |
get_output() { case "$1" in "none") echo ":heavy_check_mark:";; "non-required") echo ":warning:";; "all") echo ":x:";; *) echo "Unknown value";; esac; }
echo "# :pencil: CI Settings" >> ${GITHUB_STEP_SUMMARY}
echo "<table>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><th>Setting</th><th>Value</th></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run Docs</td><td>$(get_output ${{ steps.conditionals.outputs.skip_docs }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run Build</td><td>$(get_output ${{ steps.conditionals.outputs.skip_build }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run Compliance</td><td>$(get_output ${{ steps.conditionals.outputs.skip_compliance_checks }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run Unit Tests</td><td>$(get_output ${{ steps.conditionals.outputs.skip_unit_tests }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run SAST</td><td>$(get_output ${{ steps.conditionals.outputs.skip_sast }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run SCA</td><td>$(get_output ${{ steps.conditionals.outputs.skip_sca }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Run Integration Tests</td><td>$(get_output ${{ steps.conditionals.outputs.skip_integration_tests }})</td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "<tr><td>Report type</td><td><code>${{ steps.conditionals.outputs.output_type }}</code></td></tr>" >> ${GITHUB_STEP_SUMMARY}
echo "</table>" >> ${GITHUB_STEP_SUMMARY}
echo "( $(get_output 'none') - run all jobs, $(get_output 'non-required') - run important/required jobs only, $(get_output 'all') - skip jobs)" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
build:
uses: ./.github/workflows/.reusable-build.yml
needs: [conditionals]
permissions:
id-token: write
packages: write
secrets: inherit
with:
skip: ${{ needs.conditionals.outputs.skip_build }}
compliance:
uses: ./.github/workflows/.reusable-compliance.yml
needs: [conditionals]
permissions:
actions: read
attestations: read
checks: read
contents: write
deployments: read
discussions: read
id-token: write
issues: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: write
statuses: read
secrets: inherit
with:
skip: ${{ needs.conditionals.outputs.skip_compliance_checks }}
unit-test:
uses: ./.github/workflows/.reusable-unit-test.yml
needs: [conditionals]
permissions:
checks: write
pull-requests: write
with:
skip: ${{ needs.conditionals.outputs.skip_unit_tests }}
sast:
uses: ./.github/workflows/.reusable-sast.yml
needs: [conditionals]
permissions:
pull-requests: read
security-events: write
with:
skip: ${{ needs.conditionals.outputs.skip_sast }}
output: ${{ needs.conditionals.outputs.output_type }}
semgrep:
uses: ./.github/workflows/semgrep.yml
needs: [compliance]
secrets: inherit
sca:
uses: ./.github/workflows/.reusable-sca.yml
needs: [conditionals, build]
permissions:
contents: write
packages: read
security-events: write
secrets: inherit
with:
registry: ${{ needs.build.outputs.build_registry }}
repo_owner: ${{ github.repository_owner }}
image: ${{ needs.build.outputs.build_image }}
skip: ${{ needs.conditionals.outputs.skip_sca }}
output: ${{ needs.conditionals.outputs.output_type }}
docs:
uses: ./.github/workflows/.reusable-docs.yml
needs: [conditionals]
permissions:
contents: write
with:
skip: ${{ needs.conditionals.outputs.skip_docs }}
integration-test:
uses: ./.github/workflows/.reusable-integration-test.yml
needs: [conditionals, build]
permissions:
packages: read
secrets: inherit
with:
build_registry: ${{ needs.build.outputs.build_registry }}
repo_owner: ${{ github.repository_owner }}
build_image_repository: ${{ needs.build.outputs.build_registry }}/${{ needs.build.outputs.build_repo }}
build_tag: ${{ needs.build.outputs.build_tag }}
skip: ${{ needs.conditionals.outputs.skip_integration_tests }}