Skip to content

Commit c3acec2

Browse files
committed
refactor(workflows/pr-test): avoid pull_request_target
1 parent b539dae commit c3acec2

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

.github/workflows/pr-review-companion.yml

+25-4
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,48 @@
99

1010
name: PR review companion
1111

12-
on: workflow_call
12+
on:
13+
workflow_run:
14+
workflows:
15+
- "PR Test"
16+
types:
17+
- completed
1318

1419
jobs:
1520
review:
1621
runs-on: ubuntu-latest
22+
if: github.event.workflow_run.conclusion == 'success'
1723
steps:
1824
- name: "Download artifact"
1925
uses: actions/download-artifact@v4
2026
with:
21-
name: build
27+
pattern: build
2228
path: build
29+
merge-multiple: true
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
run-id: ${{ github.event.workflow_run.id }}
32+
33+
- name: Check for artifacts
34+
if: hashFiles('build/') != ''
35+
run: |
36+
echo "HAS_ARTIFACT=true" >> "$GITHUB_ENV"
2337
2438
- uses: actions/checkout@v4
39+
if: env.HAS_ARTIFACT
2540
with:
2641
repository: mdn/yari
2742
path: yari
2843

2944
- name: Install Python
45+
if: env.HAS_ARTIFACT
3046
id: setup-python
3147
uses: actions/setup-python@v5
3248
with:
3349
python-version: "3.10"
3450

3551
# See https://www.peterbe.com/plog/install-python-poetry-github-actions-faster
3652
- name: Load cached ~/.local
53+
if: env.HAS_ARTIFACT
3754
uses: actions/cache@v4
3855
with:
3956
path: ~/.local
@@ -42,12 +59,14 @@ jobs:
4259
key: dotlocal-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-0
4360

4461
- name: Install Python poetry
45-
uses: snok/install-poetry@v1
62+
if: env.HAS_ARTIFACT
63+
uses: snok/[email protected]
4664
with:
4765
virtualenvs-create: true
4866
virtualenvs-in-project: true
4967

5068
- name: Load cached venv
69+
if: env.HAS_ARTIFACT
5170
id: cached-poetry-dependencies
5271
uses: actions/cache@v4
5372
with:
@@ -57,17 +76,19 @@ jobs:
5776
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ steps.setup-python.outputs.python-version }}-0
5877

5978
- name: Install poetry dependencies
60-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
79+
if: env.HAS_ARTIFACT && steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
6180
run: |
6281
cd yari/deployer
6382
poetry install --no-interaction --no-root
6483
6584
- name: Install Deployer
85+
if: env.HAS_ARTIFACT
6686
run: |
6787
cd yari/deployer
6888
poetry install --no-interaction
6989
7090
- name: Deploy and analyze built content
91+
if: env.HAS_ARTIFACT
7192
env:
7293
BUILD_OUT_ROOT: ${{ github.workspace }}/build
7394

.github/workflows/pr-test.yml

+7-21
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
name: PR Test
88

99
on:
10-
# The `GITHUB_TOKEN` in workflows triggered by the `pull_request_target` event
11-
# is granted read/write repository access.
12-
# Please pay attention to limit the permissions of each job!
13-
# https://docs.github.com/actions/using-jobs/assigning-permissions-to-jobs
14-
pull_request_target:
10+
pull_request:
1511
branches:
1612
- main
1713

@@ -112,14 +108,14 @@ jobs:
112108

113109
working-directory: ${{ github.workspace }}/mdn/content
114110
run: |
115-
mkdir -p ${BUILD_OUT_ROOT}
111+
mkdir -p $BUILD_OUT_ROOT
116112
117113
# Don't use `yarn build` (from mdn/content) because that one hardcodes
118114
# the BUILD_OUT_ROOT and CONTENT_ROOT env vars.
119115
node node_modules/@mdn/yari/build/cli.js ${GIT_DIFF_CONTENT}
120116
121117
echo "Disk usage size of build"
122-
du -sh ${BUILD_OUT_ROOT}
118+
du -sh $BUILD_OUT_ROOT
123119
124120
# Save the PR number into the build
125121
echo ${{ github.event.number }} > ${BUILD_OUT_ROOT}/NR
@@ -139,7 +135,7 @@ jobs:
139135
# Exclude the .map files, as they're used for debugging JS and CSS.
140136
rsync -a --exclude "*.map" ${{ github.workspace }}/mdn/content/node_modules/@mdn/yari/client/build/ ${BUILD_OUT_ROOT}
141137
# Show the final disk usage size of the build.
142-
du -sh ${BUILD_OUT_ROOT}
138+
du -sh $BUILD_OUT_ROOT
143139
144140
- uses: actions/upload-artifact@v4
145141
if: env.GIT_DIFF_CONTENT
@@ -154,16 +150,6 @@ jobs:
154150
CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
155151
working-directory: ${{ github.workspace }}/mdn/content
156152
run: |
157-
echo ${GIT_DIFF_FILES}
158-
159-
yarn filecheck ${GIT_DIFF_FILES}
160-
161-
review:
162-
needs: tests
163-
if: needs.tests.outputs.has_assets
164-
# write permissions are required to create a comment in the corresponding PR
165-
permissions: write-all
166-
uses: ./.github/workflows/pr-review-companion.yml
167-
# inherit the secrets from the parent workflow
168-
# https://docs.github.com/actions/using-workflows/reusing-workflows#using-inputs-and-secrets-in-a-reusable-workflow
169-
secrets: inherit
153+
echo $GIT_DIFF_FILES
154+
155+
yarn filecheck $GIT_DIFF_FILES

0 commit comments

Comments
 (0)