From 60fbf34db72987c18d8bbb03e469677313cb5ebe Mon Sep 17 00:00:00 2001 From: HyukjinKwon Date: Thu, 15 Apr 2021 22:56:04 +0900 Subject: [PATCH 1/2] Create checks --- .github/workflows/notify_test_workflow.yml | 38 ++++++++++------ .github/workflows/update_build_status.yml | 52 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/update_build_status.yml diff --git a/.github/workflows/notify_test_workflow.yml b/.github/workflows/notify_test_workflow.yml index 2e459ca8204d1..f0e339dd34403 100644 --- a/.github/workflows/notify_test_workflow.yml +++ b/.github/workflows/notify_test_workflow.yml @@ -14,6 +14,9 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const endpoint = "GET /repos/:owner/:repo/actions/workflows/:id/runs?&branch=:branch" + // TODO: Should use pull_request.user and pull_request.user.repos_url? + // If a different person creates a commit to another forked repo, + // it would be able to detect. const params = { owner: context.payload.pull_request.head.repo.owner.login, repo: context.payload.pull_request.head.repo.name, @@ -22,19 +25,28 @@ jobs: } const runs = await github.request(endpoint, params) - var runID = runs.data.workflow_runs[0].id + const runID = runs.data.workflow_runs[0].id + const runUrl = "https://github.com/" + + context.payload.pull_request.head.repo.full_name + + "/actions/runs/" + + runID - var msg = "**[Test build #" + runID + "]" - + "(https://github.com/" + context.payload.pull_request.head.repo.full_name - + "/actions/runs/" + runID + ")** " - + "for PR " + context.issue.number - + " at commit [`" + context.payload.pull_request.head.sha.substring(0, 7) + "`]" - + "(https://github.com/" + context.payload.pull_request.head.repo.full_name - + "/commit/" + context.payload.pull_request.head.sha + ")." + const name = 'Build and test' + const head_sha = context.payload.pull_request.head.sha + const status = 'in_progress' - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - body: msg + github.checks.create({ + ...context.repo, + name, + head_sha, + status, + output: { + title: 'Build and test', + 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 + }) + } }) diff --git a/.github/workflows/update_build_status.yml b/.github/workflows/update_build_status.yml new file mode 100644 index 0000000000000..0c53a01a23891 --- /dev/null +++ b/.github/workflows/update_build_status.yml @@ -0,0 +1,52 @@ +name: Update build status workflow + +on: + pull_request_target: + types: [opened, reopened, synchronize] + +jobs: + stale: + runs-on: ubuntu-20.04 + steps: + - name: "Update build status" + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const endpoint = "GET /repos/:owner/:repo/pulls?state=:state" + const params = { + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open' + } + + const maybeReady = ["clean", "has_hooks", "unknown", "unstable"]; + const notReady = ["dirty", "draft"]; + + for await (const prs of client.paginate.iterator(endpoint,params)) { + const prs = prs.data.filter(pr => { + console.log("Mergeable state:" + pr.mergeable_state); + if (pr.mergeable_state == null || maybeReady.includes(pr.mergeable_state)) { + const checkRuns = await github.request('GET /repos/{owner}/{repo}/commits/{ref}/check-runs', { + owner: context.repo.owner, + repo: context.repo.repo, + ref: pr.head.sha + }) + + if (checkRuns[0].name == "Build and test" && checkRuns[0].status == "in_progress") { + const params = JSON.parse(checkRuns[0].output.text) // text contains parameters to make request in JSON + const { conclusion } = await github.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}', params) + + if (conclusion == "success" || conclusion == "failure") { + await github.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', { + owner: context.repo.owner, + repo: context.repo.repo, + check_run_id: checkRuns[0].id, + status: 'completed', + conclusion: conclusion + }) + } + } + } + } + } From ddec734a7ec35483799c97e62b403025952ef7cc Mon Sep 17 00:00:00 2001 From: HyukjinKwon Date: Thu, 15 Apr 2021 23:18:15 +0900 Subject: [PATCH 2/2] Arbitrary change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa7d1dd338be0..9fc9117ba6183 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Apache Spark -Spark is a unified analytics engine for large-scale data processing. It provides +Apache Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames,