Skip to content

Commit 895539c

Browse files
ci: use separate workflows for 'push' and 'pull_request' (#3491)
1 parent 454c31e commit 895539c

File tree

5 files changed

+79
-82
lines changed

5 files changed

+79
-82
lines changed

.github/workflows/canary.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Canary Release
22
on:
33
workflow_run:
44
workflows:
5-
- CI
5+
- PullRequest
66
types:
77
- completed
88
jobs:

.github/workflows/ci.yml

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: CI
2-
on: [push, pull_request]
2+
on: workflow_call
33
jobs:
44
save-github-event:
55
name: "Save `github.event` as an artifact to use in subsequent 'workflow_run' actions"
@@ -183,67 +183,6 @@ jobs:
183183
- name: Run Tests
184184
run: npm run testonly
185185

186-
benchmark:
187-
name: Run benchmark
188-
runs-on: ubuntu-latest
189-
if: github.event_name == 'pull_request'
190-
steps:
191-
- name: Checkout repo
192-
uses: actions/checkout@v2
193-
with:
194-
persist-credentials: false
195-
196-
- name: Deepen cloned repo
197-
env:
198-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
199-
run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE'
200-
201-
- name: Setup Node.js
202-
uses: actions/setup-node@v2
203-
with:
204-
cache: npm
205-
node-version-file: '.node-version'
206-
207-
- name: Install Dependencies
208-
run: npm ci --ignore-scripts
209-
210-
- name: Run Benchmark
211-
run: 'npm run benchmark -- --revs HEAD BASE'
212-
213-
diff-npm-package:
214-
name: Diff content of NPM package
215-
runs-on: ubuntu-latest
216-
if: github.event_name == 'pull_request'
217-
steps:
218-
- name: Checkout repo
219-
uses: actions/checkout@v2
220-
with:
221-
persist-credentials: false
222-
223-
- name: Deepen cloned repo
224-
env:
225-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
226-
run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE'
227-
228-
- name: Setup Node.js
229-
uses: actions/setup-node@v2
230-
with:
231-
cache: npm
232-
node-version-file: '.node-version'
233-
234-
- name: Install Dependencies
235-
run: npm ci --ignore-scripts
236-
237-
- name: Generate report
238-
run: 'node resources/diff-npm-package.js BASE HEAD'
239-
240-
- name: Upload generated report
241-
uses: actions/upload-artifact@v2
242-
with:
243-
name: npm-dist-diff.html
244-
path: ./npm-dist-diff.html
245-
if-no-files-found: ignore
246-
247186
build-npm-dist:
248187
name: Build 'npmDist' artifact
249188
runs-on: ubuntu-latest

.github/workflows/deploy-artifact-as-branch.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ jobs:
2626
- name: Remove existing files first
2727
run: git rm -r .
2828

29-
- name: Download artifact into cloned branch
30-
run: gh run download "$WORKFLOW_ID" -n "$ARTIFACT_NAME"
31-
env:
32-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
WORKFLOW_ID: ${{ inputs.workflow_id }}
34-
ARTIFACT_NAME: ${{ inputs.artifact_name }}
29+
- uses: actions/download-artifact@v2
30+
with:
31+
name: ${{ inputs.artifact_name }}
3532

3633
- name: Publish target branch
3734
run: |

.github/workflows/pull_request.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: PullRequest
2+
on: pull_request
3+
jobs:
4+
ci:
5+
uses: ./.github/workflows/ci.yml
6+
7+
benchmark:
8+
name: Run benchmark
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repo
12+
uses: actions/checkout@v2
13+
with:
14+
persist-credentials: false
15+
16+
- name: Deepen cloned repo
17+
env:
18+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
19+
run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE'
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v2
23+
with:
24+
cache: npm
25+
node-version-file: '.node-version'
26+
27+
- name: Install Dependencies
28+
run: npm ci --ignore-scripts
29+
30+
- name: Run Benchmark
31+
run: 'npm run benchmark -- --revs HEAD BASE'
32+
33+
diff-npm-package:
34+
name: Diff content of NPM package
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v2
39+
with:
40+
persist-credentials: false
41+
42+
- name: Deepen cloned repo
43+
env:
44+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
45+
run: 'git fetch --depth=1 origin $BASE_SHA:refs/tags/BASE'
46+
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v2
49+
with:
50+
cache: npm
51+
node-version-file: '.node-version'
52+
53+
- name: Install Dependencies
54+
run: npm ci --ignore-scripts
55+
56+
- name: Generate report
57+
run: 'node resources/diff-npm-package.js BASE HEAD'
58+
59+
- name: Upload generated report
60+
uses: actions/upload-artifact@v2
61+
with:
62+
name: npm-dist-diff.html
63+
path: ./npm-dist-diff.html
64+
if-no-files-found: ignore
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
name: CD
2-
on:
3-
workflow_run:
4-
workflows:
5-
- CI
6-
types:
7-
- completed
8-
branches:
9-
- main
1+
name: Push
2+
on: push
103
jobs:
4+
ci:
5+
uses: ./.github/workflows/ci.yml
116
deploy-to-npm-branch:
127
name: Deploy to `npm` branch
13-
if: github.event.workflow_run.event == 'push'
8+
needs: ci
9+
if: github.ref == 'refs/heads/main'
1410
uses: ./.github/workflows/deploy-artifact-as-branch.yml
1511
with:
16-
workflow_id: ${{github.event.workflow_run.id}}
12+
workflow_id: ${{github.run_id}}
1713
artifact_name: npmDist
1814
target_branch: npm
1915
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'npm' branch"
2016

2117
deploy-to-deno-branch:
2218
name: Deploy to `deno` branch
23-
if: github.event.workflow_run.event == 'push'
19+
needs: ci
20+
if: github.ref == 'refs/heads/main'
2421
uses: ./.github/workflows/deploy-artifact-as-branch.yml
2522
with:
26-
workflow_id: ${{github.event.workflow_run.id}}
23+
workflow_id: ${{github.run_id}}
2724
artifact_name: denoDist
2825
target_branch: deno
2926
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'deno' branch"

0 commit comments

Comments
 (0)