From d9c2ddc74b55f0394349b69988ff07620f2392e7 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:26:39 +0400 Subject: [PATCH] ci(label): conditional dispatching build --- .github/workflows/build.yml | 2 +- .github/workflows/label.yml | 46 +++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 49caea896e9..5c7cdf47da3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ env: jobs: linux: - if: ${{ always() && inputs.linux }} + if: ${{ inputs.linux }} runs-on: [kuberunner, github-runner-02] env: LLVM_PROFILE_FILE: "gear-%p-%m.profraw" diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index c62f4e5f832..13fb953fcc2 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -10,42 +10,54 @@ concurrency: cancel-in-progress: true jobs: - build: - # uses: ./.github/workflows/build.yml - # # TODO: dispatch this workflow with github action API - # # for more conditions. for example, if the there is - # # already a build check exist. (issue-2888) - # if: github.event.label.name == 'A0-pleasereview' - # with: - # macos: ${{ github.event.label.name == 'E2-forcemacos' }} + check: runs-on: ubuntu-latest steps: - uses: actions/github-script@v6 + id: label-checks with: script: | const [owner, repo] = ["gear-tech", "gear"]; - const { ref, payload: { issue } } = context; - // const ref = "cl/issue-2888"; - // const issue_number = 3070; + const { ref, payload: { issue: issue_number } } = context; // List all labels of the current pull request. - const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + const { data: labelsArr } = await github.rest.issues.listLabelsOnIssue({ owner, repo, issue_number, }); - console.log(labels); + const labels = labelsArr.map((label) => label.name); + let [linux, macos] = [ + labels.includes("A0-pleasereview"), + labels.includes("E2-forcemacos") + ]; + + if (linux == macos == false) return; // List the latest check runs const { - data: { - check_runs - } + data: { check_runs } } = await github.rest.checks.listForRef({ owner, repo, ref, }); - // console.log(check_runs); + for (const run in check_runs) { + if (run.name == "build) { + linux = (run.conclusion == "skipped"); + } else if (run.name == "build / macos") { + macos = (run.conclusion == "skipped"); + } + } + + const build = linux || macos; + return { build, linux, win: linux, macos } + + - uses: ./.github/workflows/build.yml + if: ${{ steps.label-checks.outputs.result.build }} + with: + linux: ${{ steps.label-checks.outputs.result.linux }} + win: ${{ steps.label-checks.outputs.result.win }} + macos: ${{ steps.label-checks.outputs.result.macos }}