Skip to content

Commit 303e767

Browse files
committed
Use workflow_run instead of pull_request_target
1 parent bf701bd commit 303e767

2 files changed

Lines changed: 67 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: CI
22

3-
on: [push, pull_request_target]
3+
on:
4+
push:
5+
branches:
6+
- 'spark-*'
7+
tags:
8+
- '*'
9+
pull_request:
410

511
jobs:
612
build:
713
name: Build
814
runs-on: ubuntu-latest
9-
if: >
10-
github.event_name == 'push' ||
11-
github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
1215

1316
steps:
1417
- name: Checkout
@@ -43,9 +46,6 @@ jobs:
4346
name: Unit Tests (Dgraph ${{ matrix.dgraph-version }} and Python ${{ matrix.python-version }})
4447
runs-on: ubuntu-latest
4548
needs: build
46-
if: >
47-
github.event_name == 'push' ||
48-
github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
4949

5050
strategy:
5151
fail-fast: false
@@ -128,7 +128,11 @@ jobs:
128128
needs: test
129129

130130
runs-on: ubuntu-latest
131-
if: success() || failure()
131+
# the workflow is useless on pull_request events from fork repositories
132+
# as it can not create check runs or pull request comments
133+
if: >
134+
( success() || failure() ) &&
135+
( github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository )
132136
133137
steps:
134138
- name: Download Artifacts
@@ -137,20 +141,17 @@ jobs:
137141
path: artifacts
138142

139143
- name: Publish Unit Test Results
140-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
144+
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1
141145
with:
142-
check_name: Unit Test Results
143-
github_token: ${{ secrets.GITHUB_TOKEN }}
146+
github_token: ${{ github.token }}
144147
files: "artifacts/Unit Test Results*/**/*.xml"
148+
comment_on_pr: ${{ github.event_name != 'push' }}
145149
log_level: DEBUG
146150

147151
integration:
148152
name: Integration Tests (Dgraph ${{ matrix.dgraph-version }})
149153
runs-on: ubuntu-latest
150154
needs: build
151-
if: >
152-
github.event_name == 'push' ||
153-
github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
154155

155156
strategy:
156157
fail-fast: false

.github/workflows/fork.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Fork
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
unit-test-results:
11+
name: Unit Test Results from Fork
12+
runs-on: ubuntu-latest
13+
if: >
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion != 'skipped' &&
16+
github.event.workflow_run.head_repository.full_name != github.repository
17+
18+
steps:
19+
- name: Download Artifacts
20+
uses: actions/github-script@v3.1.0
21+
with:
22+
script: |
23+
var artifacts = await github.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{ github.event.workflow_run.id }},
27+
});
28+
for (const artifact of artifacts.data.artifacts) {
29+
var download = await github.actions.downloadArtifact({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
artifact_id: artifact.id,
33+
archive_format: 'zip',
34+
});
35+
var fs = require('fs');
36+
fs.writeFileSync(`${{github.workspace}}/artifact-${artifact.id}.zip`, Buffer.from(download.data));
37+
}
38+
- name: Extract Artifacts
39+
run: |
40+
for file in artifact-*.zip
41+
do
42+
dir="${file/%.zip/}"
43+
mkdir -p "$dir"
44+
unzip -d "$dir" "$file"
45+
done
46+
47+
- name: Unit Test Results
48+
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1
49+
with:
50+
github_token: ${{ github.token }}
51+
commit: ${{ github.event.workflow_run.head_sha }}
52+
files: "**/*.xml"

0 commit comments

Comments
 (0)