Skip to content

Commit 59f6192

Browse files
authored
chore(ci): conditionally skip 'push' event (#4872)
1 parent b863359 commit 59f6192

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

.github/workflows/mocha.yml

+23-12
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,28 @@ on:
1313

1414
jobs:
1515
prevent-double-run:
16+
# skip 'push' event when an open PR exists
1617
name: Prevent double run
1718
runs-on: ubuntu-latest
18-
# Run 'pull-request' event only on external PRs from forked repos.
19-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
19+
outputs:
20+
pr-id: ${{ steps.findPr.outputs.number }}
2021
steps:
21-
- run: 'echo run Tests'
22+
- name: Check event pull_request
23+
if: github.event_name == 'pull_request'
24+
run: 'echo pull_request: run workflow'
25+
- uses: actions/checkout@v2
26+
if: github.event_name == 'push'
27+
- name: Check event push
28+
id: findPr
29+
if: github.event_name == 'push'
30+
uses: jwalton/gh-find-current-pr@v1
31+
with:
32+
state: open
2233

2334
smoke:
2435
name: 'Smoke [Node.js v${{ matrix.node }} / ${{ matrix.os }}]'
2536
needs: prevent-double-run
37+
if: needs.prevent-double-run.outputs.pr-id == ''
2638
runs-on: '${{ matrix.os }}'
2739
strategy:
2840
matrix:
@@ -89,7 +101,7 @@ jobs:
89101
- uses: actions/checkout@v2
90102
- name: Get npm cache directory in Windows
91103
id: npm-cache
92-
if: "${{ matrix.os == 'windows-2019' }}"
104+
if: ${{ matrix.os == 'windows-2019' }}
93105
run: |
94106
echo "::set-output name=dir::$(npm config get cache)"
95107
- name: 'Cache node_modules'
@@ -111,22 +123,21 @@ jobs:
111123
# this is so mocha-github-actions-reporter can find mocha
112124
NODE_PATH: lib
113125
- name: Generate Coverage Report (Linux + Node.js latest)
114-
if: '${{ matrix.env.COVERAGE }}'
126+
if: ${{ matrix.env.COVERAGE }}
115127
run: npm start coverage-report-lcov
116128
- name: Upload Coverage to Coveralls (Linux + Node.js latest)
117-
if: '${{ matrix.env.COVERAGE }}'
129+
if: ${{ matrix.env.COVERAGE }}
118130
uses: coverallsapp/github-action@master
119131
with:
120132
github-token: '${{ secrets.GITHUB_TOKEN }}'
121133

122134
test-browser:
123-
# TODO: configure to retain build artifacts in `.karma/` dir
124135
name: 'Browser Tests'
125136
needs: smoke
126-
timeout-minutes: 20
127137
runs-on: ubuntu-latest
128-
# Run 'push' event only because of sauce labs token
129-
if: github.event_name == 'push'
138+
timeout-minutes: 20
139+
# Don't run forked 'pull_request' without saucelabs token
140+
if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork
130141
steps:
131142
- uses: actions/setup-node@v2
132143
with:
@@ -146,5 +157,5 @@ jobs:
146157
- name: Run Browser Tests
147158
run: npm start test.browser
148159
env:
149-
SAUCE_USERNAME: '${{secrets.SAUCE_USERNAME}}'
150-
SAUCE_ACCESS_KEY: '${{secrets.SAUCE_ACCESS_KEY}}'
160+
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
161+
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}

0 commit comments

Comments
 (0)