Skip to content

Commit dc7d41e

Browse files
HyukjinKwondongjoon-hyun
authored andcommitted
[SPARK-35120][INFRA] Guide users to sync branch and enable GitHub Actions in their forked repository
### What changes were proposed in this pull request? This PR proposes to add messages when the workflow fails to find the workflow run in a forked repository, for example as below: **Before** ![Screen Shot 2021-04-19 at 9 41 52 PM](https://user-images.githubusercontent.com/6477701/115238011-28e19b00-a158-11eb-8c5c-6374ca1e9790.png) ![Screen Shot 2021-04-19 at 9 42 00 PM](https://user-images.githubusercontent.com/6477701/115237984-22ebba00-a158-11eb-9b0f-11fe11072830.png) **After** ![Screen Shot 2021-04-19 at 9 25 32 PM](https://user-images.githubusercontent.com/6477701/115237507-9c36dd00-a157-11eb-8ba7-f5f88caa1058.png) ![Screen Shot 2021-04-19 at 9 23 13 PM](https://user-images.githubusercontent.com/6477701/115236793-c2a84880-a156-11eb-98fc-1bb7d4bc31dd.png) (typo `foce` in the image was fixed) See this example: https://github.com/HyukjinKwon/spark/runs/2380644793 ### Why are the changes needed? To guide users to enable Github Actions in their forked repositories (and sync their branch to the latest `master` in Apache Spark). ### Does this PR introduce _any_ user-facing change? No, dev-only. ### How was this patch tested? Manually tested in: - HyukjinKwon#47 - HyukjinKwon#46 Closes #32235 from HyukjinKwon/test-test-test. Authored-by: HyukjinKwon <gurwls223@apache.org> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
1 parent 0c2e9b9 commit dc7d41e

File tree

2 files changed

+59
-28
lines changed

2 files changed

+59
-28
lines changed

.github/workflows/notify_test_workflow.yml

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,63 @@ jobs:
5757
await new Promise(r => setTimeout(r, 3000))
5858
5959
const runs = await github.request(endpoint, params)
60-
const runID = runs.data.workflow_runs[0].id
61-
// TODO: If no workflows were found, it's likely GitHub Actions was not enabled
62-
63-
if (runs.data.workflow_runs[0].head_sha != context.payload.pull_request.head.sha) {
64-
throw new Error('There was a new unsynced commit pushed. Please retrigger the workflow.');
65-
}
66-
67-
const runUrl = 'https://github.com/'
68-
+ context.payload.pull_request.head.repo.full_name
69-
+ '/actions/runs/'
70-
+ runID
7160
7261
const name = 'Build and test'
7362
const head_sha = context.payload.pull_request.head.sha
74-
const status = 'queued'
63+
let status = 'queued'
64+
65+
if (runs.data.workflow_runs.length === 0) {
66+
status = 'completed'
67+
const conclusion = 'action_required'
68+
69+
github.checks.create({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
name: name,
73+
head_sha: head_sha,
74+
status: status,
75+
conclusion: conclusion,
76+
output: {
77+
title: 'Workflow run detection failed',
78+
summary: `
79+
Unable to detect the workflow run for testing the changes in your PR.
7580
76-
github.checks.create({
77-
...context.repo,
78-
name,
79-
head_sha,
80-
status,
81-
output: {
82-
title: 'Test results',
83-
summary: runUrl,
84-
text: JSON.stringify({
85-
owner: context.payload.pull_request.head.repo.owner.login,
86-
repo: context.payload.pull_request.head.repo.name,
87-
run_id: runID
88-
})
81+
1. If you did not enable GitHub Actions in your forked repository, please enable it. See also [Disabling or limiting GitHub Actions for a repository](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository) for more details.
82+
2. It is possible your branch is based on the old \`master\` branch in Apache Spark, please sync your branch to the latest master branch. For example as below:
83+
\`\`\`bash
84+
git fetch upstream
85+
git rebase upstream/master
86+
git push origin YOUR_BRANCH --force
87+
\`\`\``
88+
}
89+
})
90+
} else {
91+
const runID = runs.data.workflow_runs[0].id
92+
93+
if (runs.data.workflow_runs[0].head_sha != context.payload.pull_request.head.sha) {
94+
throw new Error('There was a new unsynced commit pushed. Please retrigger the workflow.');
8995
}
90-
})
96+
97+
const runUrl = 'https://github.com/'
98+
+ context.payload.pull_request.head.repo.full_name
99+
+ '/actions/runs/'
100+
+ runID
101+
102+
github.checks.create({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
name: name,
106+
head_sha: head_sha,
107+
status: status,
108+
output: {
109+
title: 'Test results',
110+
summary: '[See test results](' + runUrl + ')',
111+
text: JSON.stringify({
112+
owner: context.payload.pull_request.head.repo.owner.login,
113+
repo: context.payload.pull_request.head.repo.name,
114+
run_id: runID
115+
})
116+
},
117+
details_url: runUrl,
118+
})
119+
}

.github/workflows/update_build_status.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
5959
// Iterator GitHub Checks in the PR
6060
for await (const cr of checkRuns.data.check_runs) {
61-
if (cr.name == 'Build and test') {
61+
if (cr.name == 'Build and test' && cr.conclusion != "action_required") {
6262
// text contains parameters to make request in JSON.
6363
const params = JSON.parse(cr.output.text)
6464
@@ -74,7 +74,8 @@ jobs:
7474
check_run_id: cr.id,
7575
output: cr.output,
7676
status: run.data.status,
77-
conclusion: run.data.conclusion
77+
conclusion: run.data.conclusion,
78+
details_url: run.data.details_url
7879
})
7980
} else {
8081
console.log(' Run ' + cr.id + ': set status (' + run.data.status + ')')
@@ -84,6 +85,7 @@ jobs:
8485
check_run_id: cr.id,
8586
output: cr.output,
8687
status: run.data.status,
88+
details_url: run.data.details_url
8789
})
8890
}
8991

0 commit comments

Comments
 (0)