Skip to content

Commit f733f69

Browse files
authored
fix(ci): run Tests on Crowdin PRs
Signed-off-by: Aviv Keller <me@aviv.sh>
1 parent c32c588 commit f733f69

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

.github/workflows/lint-and-tests.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ on:
1919
branches:
2020
- main
2121
merge_group:
22+
pull_request_target:
23+
types: [labeled]
2224

23-
# The permissions specified below apply to workflows triggered by `merge_group`, `push`, and `pull_request` events that originate from the same repository (non-fork).
25+
# The permissions specified below apply to workflows triggered by `merge_group`, `push`, `pull_request_target`, and `pull_request` events
26+
# that originate from the same repository (non-fork).
2427
# However, workflows triggered by `pull_request` events from forked repositories are treated differently for security reasons:
2528
# - These workflows **do not** have access to any secrets configured in the repository.
2629
# - They are also **not granted any permissions** to perform actions on the base repository.
@@ -38,6 +41,12 @@ env:
3841

3942
jobs:
4043
lint:
44+
# This workflow should only be triggered by the pull_request_target event
45+
# when the label 'github_actions:pull-request' is added to a crowdin PR.
46+
#
47+
# We don't need to run Quality checks on Crowdin PRs, so we just skip this
48+
# step.
49+
if: ${{ github.event_name != 'pull_request_target' }}
4150
name: Quality checks
4251
runs-on: ubuntu-latest
4352

@@ -82,25 +91,16 @@ jobs:
8291
run: npm i --no-audit --no-fund --ignore-scripts --userconfig=/dev/null
8392

8493
- name: Run quality checks with `turbo`
85-
# We run the ESLint and Prettier commands on all Workflow triggers of the `Lint` job, besides if
86-
# the Pull Request comes from a Crowdin Branch, as we don't want to run ESLint and Prettier on Crowdin PRs
87-
# Note: Linting and Prettifying of files on Crowdin PRs is handled by the `translations-pr.yml` Workflow
88-
if: |
89-
(github.event_name == 'push' || github.event_name == 'merge_group') ||
90-
(github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'chore/crowdin')
9194
run: npx turbo lint check-types prettier
9295

9396
- name: Save Lint Cache
9497
# We only want to save caches on `push` events or `pull_request_target` events
9598
# and if it is a `pull_request_target` event, we want to avoid saving the cache if the PR comes from Dependabot
96-
# or if it comes from an automated Crowdin Pull Request
9799
# The reason we save caches on `push` is because caches creates on `main` (default) branches can be reused within
98100
# other Pull Requests and PRs coming from forks
99101
if: |
100102
github.event_name == 'push' ||
101-
(github.event_name == 'pull_request' &&
102-
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false &&
103-
github.event.pull_request.head.ref != 'chore/crowdin')
103+
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false
104104
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
105105
with:
106106
path: |
@@ -114,6 +114,18 @@ jobs:
114114
tests:
115115
name: Tests
116116
runs-on: ubuntu-latest
117+
# This condition ensures the job only runs in the following cases:
118+
# - The event is *not* pull_request_target, OR
119+
# - The event *is* pull_request_target AND all of the following are true:
120+
# - The label added is 'github_actions:pull-request',
121+
# - The PR head branch is 'chore/crowdin' (ensures it's a Crowdin-generated PR).
122+
if: |
123+
github.event_name != 'pull_request_target' ||
124+
(
125+
github.event_name == 'pull_request_target' &&
126+
github.event.label.name == 'github_actions:pull-request' &&
127+
github.event.pull_request.head.ref == 'chore/crowdin'
128+
)
117129
118130
steps:
119131
- name: Harden Runner
@@ -123,6 +135,8 @@ jobs:
123135

124136
- name: Git Checkout
125137
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
138+
with:
139+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
126140

127141
- name: Set up Node.js
128142
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0

0 commit comments

Comments
 (0)