Skip to content

Commit 6c72534

Browse files
authored
fix(workflows/pr-test): do not use pull_request_target (#25578)
Same approach as in the previous `pr-test` workflow in content: https://github.com/mdn/content/blob/e4a247688d05e26847527ce88434b3f53b47ad3f/.github/workflows/pr-test.yml
1 parent b539dae commit 6c72534

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
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-25
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
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

1814
jobs:
1915
tests:
20-
# do not run on PRs in forks
2116
if: github.repository == 'mdn/translated-content'
2217
runs-on: ubuntu-latest
2318
# Set the permissions to `read-all`, preventing the workflow from
@@ -112,14 +107,14 @@ jobs:
112107

113108
working-directory: ${{ github.workspace }}/mdn/content
114109
run: |
115-
mkdir -p ${BUILD_OUT_ROOT}
110+
mkdir -p $BUILD_OUT_ROOT
116111
117112
# Don't use `yarn build` (from mdn/content) because that one hardcodes
118113
# the BUILD_OUT_ROOT and CONTENT_ROOT env vars.
119114
node node_modules/@mdn/yari/build/cli.js ${GIT_DIFF_CONTENT}
120115
121116
echo "Disk usage size of build"
122-
du -sh ${BUILD_OUT_ROOT}
117+
du -sh $BUILD_OUT_ROOT
123118
124119
# Save the PR number into the build
125120
echo ${{ github.event.number }} > ${BUILD_OUT_ROOT}/NR
@@ -130,16 +125,13 @@ jobs:
130125
# be able to use this raw diff file for the benefit of analyzing.
131126
wget https://github.com/${{ github.repository }}/compare/${BASE_SHA}...${HEAD_SHA}.diff -O ${BUILD_OUT_ROOT}/DIFF
132127
133-
# Set the output variable so the next job could skip if there are no assets
134-
echo "has_assets=true" >> "$GITHUB_OUTPUT"
135-
136128
- name: Merge static assets with built documents
137129
if: env.GIT_DIFF_CONTENT
138130
run: |
139131
# Exclude the .map files, as they're used for debugging JS and CSS.
140132
rsync -a --exclude "*.map" ${{ github.workspace }}/mdn/content/node_modules/@mdn/yari/client/build/ ${BUILD_OUT_ROOT}
141133
# Show the final disk usage size of the build.
142-
du -sh ${BUILD_OUT_ROOT}
134+
du -sh $BUILD_OUT_ROOT
143135
144136
- uses: actions/upload-artifact@v4
145137
if: env.GIT_DIFF_CONTENT
@@ -154,16 +146,6 @@ jobs:
154146
CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
155147
working-directory: ${{ github.workspace }}/mdn/content
156148
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
149+
echo $GIT_DIFF_FILES
150+
151+
yarn filecheck $GIT_DIFF_FILES

0 commit comments

Comments
 (0)