-
Notifications
You must be signed in to change notification settings - Fork 385
273 lines (258 loc) · 8.97 KB
/
ci-pr-only.yml
File metadata and controls
273 lines (258 loc) · 8.97 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
name: CI PR Only
# Jobs that run on PRs, but no other pipelines
on:
workflow_call:
inputs:
commit-sha:
description: The commit sha to run the CI on
required: true
type: string
base-ref:
description: The base branch of the PR
required: false
default: ${{ github.event.pull_request.base.ref }}
type: string
pr-number:
description: 'The PR number'
required: false
default: ${{ github.event.pull_request.number }}
type: string
env:
CI_PROJECT_DIR: ${{ github.workspace }}
ORG: ${{ github.repository_owner }}
jobs:
# Run didc compatibility checks against the merge base
didc_checks:
name: Candid compatibility checks
if: ${{ !contains(github.event.pull_request.labels.*.name, 'CI_OVERRIDE_DIDC_CHECK') }}
runs-on: &dind-small-setup
labels: dind-small
container: &container-setup
image: ghcr.io/dfinity/ic-build@sha256:ea590bb4afc6c513a93f3cdd4e1a370babe068fea9650033dcea03859eb95afe
options: >-
-e NODE_NAME --mount type=tmpfs,target="/home/buildifier/.local/share/containers"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Ensures we fetch the merge-base, which we compare against
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || inputs.commit-sha }}
- name: Run candid compatibility checks
uses: ./.github/actions/bazel
with:
run: |
export DID_CHECK_REV="$(git merge-base HEAD 'origin/${{ inputs.base-ref }}')"
echo "DID_CHECK_REV=$DID_CHECK_REV"
bazel test //... \
--build_tag_filters="didc" \
--test_tag_filters="didc"
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
# Runs linters and formatters on code to automatically fix issues
autofix:
name: Autofix
runs-on: *dind-small-setup
container: *container-setup
timeout-minutes: 30
steps:
- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_CREATION_BOT_APP_ID }}
private-key: ${{ secrets.PR_CREATION_BOT_PRIVATE_KEY }}
- &checkout-with-token
name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || inputs.commit-sha }}
token: ${{ steps.app-token.outputs.token }}
- name: Run Linter
id: linter
uses: ./.github/actions/bazel
with:
run: |
set -euo pipefail
EXIT_STATUS=0
bazel run :buildifier
bazel run :shfmt-format
bazel run :ruff-format
bazel run :rustfmt
bazel run :gazelle
git add --all
git status
if ! git diff --cached --quiet; then
# There are some changes staged
git config --global user.email "infra+github-automation@dfinity.org"
git config --global user.name "IDX GitHub Automation"
git commit -m "Automatically fixing code for linting and formatting issues"
git push
# Because the buildifier made changes, fail the PR
EXIT_STATUS=1
fi
exit "${EXIT_STATUS}"
bazel-build-fuzzers-archives:
name: Bazel Build Fuzzers Archives
runs-on: &dind-large-setup
labels: dind-large
container: *container-setup
timeout-minutes: 90
steps:
- &checkout
name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.commit-sha }}
- name: Filter Relevant Files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
id: filter
with:
ref: ${{ inputs.commit-sha }}
filters: |
fuzzers:
- '.github/workflows/ci-pr-only.yml'
- 'bin/fuzzing/build-all-fuzzers.sh'
- 'bazel/fuzz_testing.bzl'
- name: Run Bazel Build Fuzzers Archives
id: bazel-build-fuzzers-archives
if: steps.filter.outputs.fuzzers == 'true'
shell: bash
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"/bin/fuzzing/
./build-all-fuzzers.sh --zip
lock-generate:
name: Lock Generate
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_CREATION_BOT_APP_ID }}
private-key: ${{ secrets.PR_CREATION_BOT_PRIVATE_KEY }}
- *checkout-with-token
- name: Filter Relevant Files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
id: filter
with:
ref: ${{ inputs.commit-sha }}
filters: |
lock-generate:
- '.github/workflows/ci-pr-only.yml'
- '.bazelrc'
- '.bazelversion'
- '**/*.bazel'
- '**/*.bzl'
- '**/*.lock'
- '**/*.rs'
- '**/*.toml'
- name: Run Lock Generate
id: lock-generate
if: steps.filter.outputs.lock-generate == 'true'
run: ./ci/scripts/lock-generate.sh
generate-config-fixtures:
name: Generate Config Fixtures
runs-on: ubuntu-latest
container: *container-setup
timeout-minutes: 30
steps:
- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_CREATION_BOT_APP_ID }}
private-key: ${{ secrets.PR_CREATION_BOT_PRIVATE_KEY }}
- *checkout-with-token
- name: Filter Relevant Files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
id: filter
with:
ref: ${{ inputs.commit-sha }}
filters: |
generate-config-fixtures:
- '.github/workflows/ci-pr-only.yml'
- 'rs/ic_os/config_types/**'
- name: Run Generate Config Fixtures
id: generate-config-fixtures
if: steps.filter.outputs.generate-config-fixtures == 'true'
run: ./ci/scripts/generate-config-fixtures.sh
dependencies-check:
name: Dependency Scan for PR
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
pull-requests: write
env:
SHELL_WRAPPER: "/usr/bin/time"
CARGO_AUDIT_VERSION: "0.22.0"
CI_MERGE_REQUEST_IID: ${{ inputs.pr-number }}
CI_PROJECT_PATH: ${{ github.repository }}
CI_PIPELINE_ID: ${{ github.run_id }}
CI_COMMIT_SHA: ${{ inputs.commit-sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
SLACK_PSEC_BOT_OAUTH_TOKEN: ${{ secrets.SLACK_PSEC_BOT_OAUTH_TOKEN }}
REPO_NAME: ${{ github.repository }}
steps:
- *checkout
- name: Filter Relevant Files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
id: filter
with:
ref: ${{ inputs.commit-sha }}
filters: |
depcheck:
- '.github/workflows/ci-pr-only.yml'
- 'bazel/rust.MODULE.bazel'
- '**/*.lock'
- '**/*.toml'
- name: Set up Python
uses: actions/setup-python@v5
if: steps.filter.outputs.depcheck == 'true'
with:
python-version: "3.12"
- name: Setup environment deps
id: setup-environment-deps
if: steps.filter.outputs.depcheck == 'true'
shell: bash
run: |
# Ignore externally-managed-environment pip error, install packages system-wide.
PIP_BREAK_SYSTEM_PACKAGES=1 pip3 install --ignore-installed -r requirements.txt
cargo install cargo-audit --version "${CARGO_AUDIT_VERSION}"
- name: Dependency Scan for Pull Request
id: dependencies-check
if: steps.filter.outputs.depcheck == 'true'
shell: bash
run: |
set -euo pipefail
export PYTHONPATH=$PWD/ci/src:$PWD/ci/src/dependencies
cd ci/src/dependencies/
$SHELL_WRAPPER python3 job/bazel_rust_ic_scanner_merge_job.py
# CI job is also executed in Schedule Hourly
bazel-test-coverage:
name: Bazel Test Coverage
runs-on: *dind-large-setup
container: *container-setup
timeout-minutes: 90
if: contains(github.event.pull_request.labels.*.name, 'CI_COVERAGE')
permissions:
contents: read
pull-requests: read
steps:
- *checkout
- name: Run Bazel Test Coverage
shell: bash
run: |
./ci/scripts/bazel-coverage.sh
- name: Upload bazel-coverage
uses: actions/upload-artifact@v4
with:
name: bazel-coverage
retention-days: 1
if-no-files-found: ignore
compression-level: 9
path: |
cov_html.zip