Skip to content

ci(label): trigger workflows on labelling #46

ci(label): trigger workflows on labelling

ci(label): trigger workflows on labelling #46

Workflow file for this run

name: Label
on:
pull_request:
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'
steps:
- uses: actions/checkout@v3
- name: Set HEAD_SHA
run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- uses: actions/github-script@v6
env:
LABEL: ${{ github.event.label.name }}
REF: ${{ github.ref_name }}
with:
script: |
const { LABEL, REF, HEAD_SHA } = process.env;
const [owner, repo] = ["gear-tech", "gear"];
const linux = (LABEL === "A0-pleasereview");
// List the latest check runs
const {
data: { check_runs }
} = await github.rest.checks.listForRef({
owner,
repo,
ref: REF,
});
// Filter the traget skipped workflow run.
const runs = linux
?check_runs.filter((run) => run.name === "build")
:check_runs.filter((run) => run.name === "build / macox-x86")
console.log(runs);
if (runs.length === 0) return;
if (runs[0].conclusion !== "skipped") return;
/**
* The main logic starts from here.
**/
// Dispatch target workflow.
const workflow_id = linux
?".github/workflows/build.yml"
:".github/workflows/build-macos.yml";
await github.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id,
ref: REF,
});
// Create check and update status
const check = async (name) => await github.rest.checks.create({
owner,
repo,
name,
head_sha: HEAD_SHA
});
const sleep = ms => new Promise(r => setTimeout(r, ms));
const update = async (checks) => {
const { workflow_runs } = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id,
head_sha: HEAD_SHA,
});
for (check of checks) {
const name = check.name;
let runs = workflow_runs.filter((run) => run.name === name);
if (runs.length !== 1) {
core.setFailed(`Could not find action ${name} from ${workflow_runs}`);
return;
}
const {
status,
conclusion,
id: external_id,
started_at,
url: details_url,
} = runs[0];
await github.rest.checks.update({
repo,
owner,
check_run_id: check.run_id,
external_id,
started_at,
details_url,
status,
conclusion,
});
if (status === "completed") {
checks = checks.filter((c) => c != check);
}
}
if (checks.length === 0) {
return true;
} else {
await sleep(10000);
return await update(checks);
}
}
if (linux) {
const buildLinux = await check("build / linux");
const buildWinCross = await check("build / win-cross");
await update([buildLinux, buildWinCross]);
} else {
const buildMacosX86 = await check("build / macos-x86");
await update([buildMacosX86])
}