From 051d2927edcca603bdacd885df3bcf7919a0badb Mon Sep 17 00:00:00 2001 From: HyukjinKwon Date: Mon, 19 Apr 2021 20:44:52 +0900 Subject: [PATCH] Guide users to sync branch and enable GitHub Actions in their forked repository --- .github/workflows/notify_test_workflow.yml | 81 +++++++++++++++------- .github/workflows/update_build_status.yml | 6 +- 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/.github/workflows/notify_test_workflow.yml b/.github/workflows/notify_test_workflow.yml index f1813c9b4c24b..0b725dc18cbf0 100644 --- a/.github/workflows/notify_test_workflow.yml +++ b/.github/workflows/notify_test_workflow.yml @@ -57,34 +57,63 @@ jobs: await new Promise(r => setTimeout(r, 3000)) const runs = await github.request(endpoint, params) - const runID = runs.data.workflow_runs[0].id - // TODO: If no workflows were found, it's likely GitHub Actions was not enabled - - if (runs.data.workflow_runs[0].head_sha != context.payload.pull_request.head.sha) { - throw new Error('There was a new unsynced commit pushed. Please retrigger the workflow.'); - } - - const runUrl = 'https://github.com/' - + context.payload.pull_request.head.repo.full_name - + '/actions/runs/' - + runID const name = 'Build and test' const head_sha = context.payload.pull_request.head.sha - const status = 'queued' + let status = 'queued' + + if (runs.data.workflow_runs.length === 0) { + status = 'completed' + const conclusion = 'action_required' + + github.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: name, + head_sha: head_sha, + status: status, + conclusion: conclusion, + output: { + title: 'Workflow run detection failed', + summary: ` + Unable to detect the workflow run for testing the changes in your PR. - github.checks.create({ - ...context.repo, - name, - head_sha, - status, - output: { - title: 'Test results', - summary: runUrl, - text: JSON.stringify({ - owner: context.payload.pull_request.head.repo.owner.login, - repo: context.payload.pull_request.head.repo.name, - run_id: runID - }) + 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. + 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: + \`\`\`bash + git fetch upstream + git rebase upstream/master + git push origin YOUR_BRANCH --force + \`\`\`` + } + }) + } else { + const runID = runs.data.workflow_runs[0].id + + if (runs.data.workflow_runs[0].head_sha != context.payload.pull_request.head.sha) { + throw new Error('There was a new unsynced commit pushed. Please retrigger the workflow.'); } - }) + + const runUrl = 'https://github.com/' + + context.payload.pull_request.head.repo.full_name + + '/actions/runs/' + + runID + + github.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: name, + head_sha: head_sha, + status: status, + output: { + title: 'Test results', + summary: '[See test results](' + runUrl + ')', + text: JSON.stringify({ + owner: context.payload.pull_request.head.repo.owner.login, + repo: context.payload.pull_request.head.repo.name, + run_id: runID + }) + }, + details_url: runUrl, + }) + } diff --git a/.github/workflows/update_build_status.yml b/.github/workflows/update_build_status.yml index 777f147f09b31..16fbe3a6f66c7 100644 --- a/.github/workflows/update_build_status.yml +++ b/.github/workflows/update_build_status.yml @@ -58,7 +58,7 @@ jobs: // Iterator GitHub Checks in the PR for await (const cr of checkRuns.data.check_runs) { - if (cr.name == 'Build and test') { + if (cr.name == 'Build and test' && cr.conclusion != "action_required") { // text contains parameters to make request in JSON. const params = JSON.parse(cr.output.text) @@ -74,7 +74,8 @@ jobs: check_run_id: cr.id, output: cr.output, status: run.data.status, - conclusion: run.data.conclusion + conclusion: run.data.conclusion, + details_url: run.data.details_url }) } else { console.log(' Run ' + cr.id + ': set status (' + run.data.status + ')') @@ -84,6 +85,7 @@ jobs: check_run_id: cr.id, output: cr.output, status: run.data.status, + details_url: run.data.details_url }) }