Skip to content

Commit 7c697db

Browse files
authored
Merge pull request #691 from integer32llc/ci-for-untrusted-repos
2 parents c4ae844 + 8ac62c2 commit 7c697db

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ name: Validate everything
55
push:
66
branches:
77
- master
8-
pull_request:
8+
pull_request_target:
9+
types:
10+
- labeled
911
branches:
1012
- master
1113
env:
1214
DOCKER_HUB_USERNAME: shepmaster
1315
GH_CONTAINER_REGISTRY_USERNAME: shepmaster
14-
AWS_ACCESS_KEY_ID: AKIAWESVHZ3J6US4DSXP
16+
AWS_ACCESS_KEY_ID: AKIAWESVHZ3JQAY5NM5K
1517
jobs:
1618
build_compiler_containers:
1719
name: Build ${{ matrix.channel }} compiler container
@@ -22,11 +24,14 @@ jobs:
2224
- stable
2325
- beta
2426
- nightly
27+
if: 'contains(github.event.pull_request.labels.*.name, ''CI: approved'')'
2528
env:
2629
IMAGE_NAME: ghcr.io/integer32llc/rust-playground-ci-rust-${{ matrix.channel }}
2730
steps:
2831
- name: Checkout code
2932
uses: actions/checkout@v2
33+
with:
34+
ref: "${{ github.event.pull_request.head.sha }}"
3035
- name: Set up Docker Buildx
3136
uses: docker/setup-buildx-action@v1
3237
with:
@@ -124,11 +129,14 @@ jobs:
124129
- clippy
125130
- miri
126131
- rustfmt
132+
if: 'contains(github.event.pull_request.labels.*.name, ''CI: approved'')'
127133
env:
128134
IMAGE_NAME: ghcr.io/integer32llc/rust-playground-ci-tool-${{ matrix.tool }}
129135
steps:
130136
- name: Checkout code
131137
uses: actions/checkout@v2
138+
with:
139+
ref: "${{ github.event.pull_request.head.sha }}"
132140
- name: Set up Docker Buildx
133141
uses: docker/setup-buildx-action@v1
134142
with:
@@ -155,9 +163,12 @@ jobs:
155163
build_backend:
156164
name: Build backend
157165
runs-on: ubuntu-latest
166+
if: 'contains(github.event.pull_request.labels.*.name, ''CI: approved'')'
158167
steps:
159168
- name: Checkout code
160169
uses: actions/checkout@v2
170+
with:
171+
ref: "${{ github.event.pull_request.head.sha }}"
161172
- name: Cache Cargo intermediate products
162173
uses: actions/cache@v2
163174
with:
@@ -182,9 +193,12 @@ jobs:
182193
build_frontend:
183194
name: Build frontend
184195
runs-on: ubuntu-latest
196+
if: 'contains(github.event.pull_request.labels.*.name, ''CI: approved'')'
185197
steps:
186198
- name: Checkout code
187199
uses: actions/checkout@v2
200+
with:
201+
ref: "${{ github.event.pull_request.head.sha }}"
188202
- name: Get yarn cache directory path
189203
id: yarn-cache-dir-path
190204
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -214,6 +228,7 @@ jobs:
214228
run_integration_tests:
215229
name: Running integration tests
216230
runs-on: ubuntu-latest
231+
if: 'contains(github.event.pull_request.labels.*.name, ''CI: approved'')'
217232
needs:
218233
- build_compiler_containers
219234
- build_tool_containers
@@ -225,6 +240,8 @@ jobs:
225240
steps:
226241
- name: Checkout code
227242
uses: actions/checkout@v2
243+
with:
244+
ref: "${{ github.event.pull_request.head.sha }}"
228245
- name: Configure Ruby
229246
uses: actions/setup-ruby@v1
230247
with:

.github/workflows/cron.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
---
33
name: Scheduled rebuild
44
'on':
5-
workflow_dispatch:
5+
workflow_dispatch:
66
schedule:
77
- cron: 7 2 * * *
88
env:
99
DOCKER_HUB_USERNAME: shepmaster
1010
GH_CONTAINER_REGISTRY_USERNAME: shepmaster
11-
AWS_ACCESS_KEY_ID: AKIAWESVHZ3J6US4DSXP
11+
AWS_ACCESS_KEY_ID: AKIAWESVHZ3JQAY5NM5K
1212
jobs:
1313
build_compiler_containers:
1414
name: Build ${{ matrix.channel }} compiler container

ci/workflows.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ components:
33
env:
44
DOCKER_HUB_USERNAME: shepmaster
55
GH_CONTAINER_REGISTRY_USERNAME: shepmaster
6-
AWS_ACCESS_KEY_ID: AKIAWESVHZ3J6US4DSXP
6+
AWS_ACCESS_KEY_ID: AKIAWESVHZ3JQAY5NM5K
77

88
- checkout: &checkout
99
name: "Checkout code"
1010
uses: actions/checkout@v2
1111

12+
# This should only be used when we know that the code being tested
13+
# doesn't make use of our secrets or elevated GitHub token.
14+
- checkout_pr: &checkout_pr
15+
name: "Checkout code"
16+
uses: actions/checkout@v2
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
1220
- docker_buildx: &docker_buildx
1321
name: "Set up Docker Buildx"
1422
uses: docker/setup-buildx-action@v1
@@ -212,7 +220,8 @@ workflows:
212220
push:
213221
branches:
214222
- master
215-
pull_request:
223+
pull_request_target:
224+
types: [labeled]
216225
branches:
217226
- master
218227

@@ -221,11 +230,12 @@ workflows:
221230
jobs:
222231
build_compiler_containers:
223232
<<: *build_compiler_containers_job
233+
if: "contains(github.event.pull_request.labels.*.name, 'CI: approved')"
224234
env:
225235
<<: *build_compiler_containers_job_env
226236

227237
steps:
228-
- *checkout
238+
- *checkout_pr
229239
- *docker_buildx
230240
- *login_ghcr
231241
- *build_compiler_containers_toolchain
@@ -236,21 +246,23 @@ workflows:
236246

237247
build_tool_containers:
238248
<<: *build_tool_containers_job
249+
if: "contains(github.event.pull_request.labels.*.name, 'CI: approved')"
239250
env:
240251
<<: *build_tool_containers_job_env
241252

242253
steps:
243-
- *checkout
254+
- *checkout_pr
244255
- *docker_buildx
245256
- *login_ghcr
246257
- *build_tool_containers_final
247258

248259
build_backend:
249260
name: "Build backend"
250261
runs-on: ubuntu-latest
262+
if: "contains(github.event.pull_request.labels.*.name, 'CI: approved')"
251263

252264
steps:
253-
- *checkout
265+
- *checkout_pr
254266

255267
- name: "Cache Cargo intermediate products"
256268
uses: actions/cache@v2
@@ -290,9 +302,10 @@ workflows:
290302
build_frontend:
291303
name: "Build frontend"
292304
runs-on: ubuntu-latest
305+
if: "contains(github.event.pull_request.labels.*.name, 'CI: approved')"
293306

294307
steps:
295-
- *checkout
308+
- *checkout_pr
296309

297310
- name: "Get yarn cache directory path"
298311
id: yarn-cache-dir-path
@@ -336,6 +349,7 @@ workflows:
336349
run_integration_tests:
337350
name: "Running integration tests"
338351
runs-on: ubuntu-latest
352+
if: "contains(github.event.pull_request.labels.*.name, 'CI: approved')"
339353
needs:
340354
- build_compiler_containers
341355
- build_tool_containers
@@ -347,7 +361,7 @@ workflows:
347361
working-directory: tests
348362

349363
steps:
350-
- *checkout
364+
- *checkout_pr
351365

352366
- name: "Configure Ruby"
353367
uses: actions/setup-ruby@v1

0 commit comments

Comments
 (0)