diff --git a/.github/actions/label/build.js b/.github/actions/label/build.js index 39503e28172..c4d456b194e 100644 --- a/.github/actions/label/build.js +++ b/.github/actions/label/build.js @@ -3,8 +3,11 @@ */ const [owner, repo] = ["gear-tech", "gear"]; -const { LABEL, REF, HEAD_SHA } = process.env; -const linux = LABEL === "A0-pleasereview"; +const { LABEL, REF, HEAD_SHA, TITLE, NUMBER } = process.env; +const linux = + LABEL === "A0-pleasereview" || + LABEL === "A4-insubstantial" || + LABEL === "A2-mergeoncegreen"; const checks = linux ? ["linux", "win-cross"] : ["x86"]; const workflow_id = linux ? ".github/workflows/build.yml" @@ -18,7 +21,7 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); /** * If skipping this action. **/ -const skip = async ({ github }) => { +const skip = async ({ core, github }) => { const { data: { check_runs }, } = await github.rest.checks.listForRef({ @@ -27,16 +30,29 @@ const skip = async ({ github }) => { ref: REF, }); + core.info(`check runs: ${check_runs}`); + const runs = linux - ? check_runs.filter((run) => run.name === "build" || run.name === "build / linux") - : check_runs.filter((run) => run.name === "build / macox-x86"); + ? check_runs.filter( + (run) => run.name === "build" || run.name === "build / linux" + ) + : check_runs.filter((run) => run.name === "build / macos-x86"); - if (runs.length === 0) return false; + // Skip this action by default. + let skipped = false; for (run of runs) { - if (run.conclusion !== "skipped") return true; + // Process this action only if the previous build has been skipped. + if ( + (run.name === "build" && run.conclusion === "skipped") + ) + skipped = true; + + // If there is already a build, skip this action without more conditions. + if (run.name === "build / linux" || run.name === "build / macos-x86") + return true; } - return false; + return !skipped; }; /** @@ -72,8 +88,13 @@ const dispatchWorkflow = async ({ core, github }) => { repo, workflow_id, ref: REF, + inputs: { + title: TITLE, + number: NUMBER, + }, }); + // Wait for the workflow to be dispatched. await sleep(10000); // Get the target workflow run @@ -86,12 +107,16 @@ const dispatchWorkflow = async ({ core, github }) => { head_sha: HEAD_SHA, }); - if (workflow_runs.length != 1) { + if (workflow_runs.length === 0) { core.setFailed(`Incorrect workflow runs`); return; } - return workflow_runs[0]; + let sorted_runs = workflow_runs.sort((a, b) => { + return new Date(b.created_at) - new Date(a.created_at); + }); + + return sorted_runs[0]; }; /// List jobs of workflow run. @@ -122,14 +147,16 @@ const listJobs = async ({ github, core, run_id }) => { * The main function. **/ module.exports = async ({ github, core }) => { - if (await skip({ github })) { + if (await skip({ core, github })) { core.info("Build has already been processed."); return; } const run = await dispatchWorkflow({ core, github }); + core.info(`Dispatched workflow ${run.html_url}`); let labelChecks = await createChecks({ core, github }); + // Wait for the jobs to be completed. while (true) { const jobs = await listJobs({ github, core, run_id: run.id }); completed = jobs.filter((job) => job.status === "completed").length; @@ -171,7 +198,7 @@ module.exports = async ({ github, core }) => { if (completed === checks.length) { core.info("All jobs completed."); - break; + return; } else { await sleep(10000); } diff --git a/.github/workflows/PR.yml b/.github/workflows/PR.yml index 767f6dc3f33..6849ba7e024 100644 --- a/.github/workflows/PR.yml +++ b/.github/workflows/PR.yml @@ -53,6 +53,7 @@ jobs: needs: status if: >- contains(github.event.pull_request.labels.*.name, 'A0-pleasereview') + || contains(github.event.pull_request.labels.*.name, 'A4-insubstantial') || contains(github.event.pull_request.labels.*.name, 'A2-mergeoncegreen') uses: ./.github/workflows/build.yml with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 674a0f60ca6..71e687d38d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,15 @@ on: type: boolean default: false workflow_dispatch: + inputs: + title: + type: string + description: "Pull request title that triggers this workflow." + number: + type: string + description: "Pull request number that triggers this workflow" + +run-name: ${{ inputs.title }} ( ${{ format('#{0}', inputs.number) }} ) env: CARGO_INCREMENTAL: 0 diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 187032b8adc..9dd2ef902dc 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -5,16 +5,14 @@ on: branches: [master, vara-stage-1, vara-stage-2, vara-stage-3] types: [labeled] -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: dispatch: runs-on: ubuntu-latest if: >- github.event.label.name == 'A0-pleasereview' || github.event.label.name == 'E2-forcemacos' + || github.event.label.name == 'A4-insubstantial' + || github.event.label.name == 'A2-mergeoncegreen' steps: - uses: actions/checkout@v3 with: @@ -24,6 +22,8 @@ jobs: HEAD_SHA: ${{ github.event.pull_request.head.sha }} LABEL: ${{ github.event.label.name }} REF: ${{ github.head_ref || github.ref_name }} + TITLE: ${{ github.event.pull_request.title }} + NUMBER: ${{ github.event.number }} with: script: | const script = require('./.github/actions/label/build.js');