Skip to content

Commit ee5a86c

Browse files
committed
ci: Push Runs Were Deduplicated for Branches with Open Pull Requests
1 parent 3cc2dbf commit ee5a86c

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

.github/workflows/tests.yml

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,59 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
48

59
concurrency:
610
group: ${{ github.workflow }}-${{ github.ref }}
711
cancel-in-progress: true
812

913
jobs:
14+
pr-check:
15+
runs-on: ubuntu-latest
16+
17+
outputs:
18+
has_open_pr: ${{ steps.detect.outputs.has_open_pr }}
19+
20+
steps:
21+
- name: Detect open pull request for current branch
22+
id: detect
23+
env:
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
run: |
26+
set -euo pipefail
27+
28+
if [[ "${{ github.event_name }}" != "push" || "${{ github.ref }}" == "refs/heads/main" ]]; then
29+
echo "has_open_pr=false" >> "$GITHUB_OUTPUT"
30+
exit 0
31+
fi
32+
33+
branch="${GITHUB_REF#refs/heads/}"
34+
head="${GITHUB_REPOSITORY_OWNER}:${branch}"
35+
api_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls"
36+
37+
count="$(
38+
curl -fsSL \
39+
-H "Authorization: Bearer ${GH_TOKEN}" \
40+
-H "Accept: application/vnd.github+json" \
41+
--get "${api_url}" \
42+
--data-urlencode "state=open" \
43+
--data-urlencode "head=${head}" \
44+
--data-urlencode "per_page=1" \
45+
| python3 -c 'import json,sys; print(len(json.load(sys.stdin)))'
46+
)"
47+
48+
if [[ "${count}" -gt 0 ]]; then
49+
echo "has_open_pr=true" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "has_open_pr=false" >> "$GITHUB_OUTPUT"
52+
fi
53+
1054
eslint:
55+
needs: pr-check
56+
if: github.event_name != 'push' || github.ref == 'refs/heads/main' || needs.pr-check.outputs.has_open_pr != 'true'
1157
runs-on: ubuntu-latest
1258

1359
strategy:
@@ -50,6 +96,10 @@ jobs:
5096
if: matrix.node-version != '24.x'
5197
run: yarn test
5298

99+
- name: Install Playwright Chromium
100+
if: matrix.node-version == '24.x'
101+
run: yarn playwright install --with-deps chromium
102+
53103
- name: Run merged coverage
54104
if: matrix.node-version == '24.x'
55105
run: |

0 commit comments

Comments
 (0)