Skip to content

Commit

Permalink
Merge branch 'master' into dd/mx-lock-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Diatlov committed Sep 22, 2023
2 parents 185154b + 2943b74 commit 316a176
Show file tree
Hide file tree
Showing 604 changed files with 35,557 additions and 22,874 deletions.
206 changes: 206 additions & 0 deletions .github/actions/label/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/**
* Javascript module for the label action.
*/

const [owner, repo] = ["gear-tech", "gear"];
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"
: ".github/workflows/build-macos.yml";

/**
* Sleep for ms milliseconds.
**/
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

/**
* If skipping this action.
**/
const skip = async ({ core, github }) => {
const {
data: { check_runs },
} = await github.rest.checks.listForRef({
owner,
repo,
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 / macos-x86");

// Skip this action by default.
let skipped = false;
for (run of runs) {
// 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 !skipped;
};

/**
* Create build checks.
*
* TODO:
* * Queue the new created checks to check suite PR (#3087).
* * Support re-runing the checks. (#3088)
**/
const createChecks = async ({ core, github }) => {
let status = {};
for (check of checks) {
const { data: res } = await github.rest.checks.create({
owner,
repo,
name: `build / ${check}`,
head_sha: HEAD_SHA,
});

core.info(`Created check ${check}`);
status[check] = res;
}

return status;
};

/**
* Dispatch the target workflow.
*/
const dispatchWorkflow = async ({ core, github }) => {
await github.rest.actions.createWorkflowDispatch({
owner,
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
const {
data: { workflow_runs },
} = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id,
head_sha: HEAD_SHA,
});

if (workflow_runs.length === 0) {
core.setFailed(`Incorrect workflow runs`);
return;
}

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.
const listJobs = async ({ github, core, run_id }) => {
const {
data: { jobs },
} = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id,
});

if (jobs.length === 0) {
core.setFailed(`Empty jobs from dispatched workflow`);
return;
}

const requiredJobs = jobs.filter((job) => checks.includes(job.name));
if (requiredJobs.length !== checks.length) {
core.setFailed(`Incorrect count for disptached jobs`);
return;
}

return requiredJobs;
};

/**
* The main function.
**/
module.exports = async ({ github, core }) => {
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;

for (job of jobs) {
let checkJob = labelChecks[job.name];
if (
checkJob.status !== job.status ||
checkJob.conclusion !== job.conclusion
) {
core.info(
`Updating check ${job.name}, status: ${job.status}, conclusion: ${job.conclusion}`
);

let { status, conclusion } = job;

let data = {
owner,
repo,
check_run_id: checkJob.id,
status,
output: {
title: `Build ${job.name}`,
summary: `ref ${job.html_url}`,
},
};

labelChecks[job.name].status = status;
if (conclusion) {
data.conclusion = conclusion;
labelChecks[job.name].conclusion = conclusion;
}

await github.rest.checks.update(data);
} else {
continue;
}
}

if (completed === checks.length) {
core.info("All jobs completed.");
return;
} else {
await sleep(10000);
}
}
};
28 changes: 28 additions & 0 deletions .github/actions/label/skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Javascript module for skipping CI
*/

const SKIP_CI = "[skip-ci]";
const { TITLE, HEAD_SHA } = process.env;
const CHECKS = ["check", "build"]
const [owner, repo] = ["gear-tech", "gear"];

module.exports = async ({ github, core }) => {
if (!TITLE.includes(SKIP_CI)) return;

core.info(`Skipping CI for ${TITLE}`);

for (check of CHECKS) {
const { data: res } = await github.rest.checks.create({
owner,
repo,
name: `${check} / linux`,
head_sha: HEAD_SHA,
status: "completed",
conclusion: "success",
});

core.info(`Created check ${check}`);
core.info(JSON.stringify(res, null, 2));
}
}
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
labels: ["A4-insubstantial", "E2-forcemacos"]
labels: ["A0-pleasereview", "A4-insubstantial", "E2-forcemacos"]
schedule:
interval: "weekly"
day: "friday"
commit-message:
prefix: "[skip ci] "
prefix: "[depbot] "

- package-ecosystem: "cargo"
directory: "/examples/"
labels: ["A4-insubstantial"]
labels: ["A0-pleasereview", "A4-insubstantial"]
schedule:
interval: "weekly"
day: "friday"
commit-message:
prefix: "[skip ci] "
prefix: "[depbot] "

- package-ecosystem: "github-actions"
directory: "/"
labels: ["A4-insubstantial"]
labels: ["A0-pleasereview", "A4-insubstantial"]
schedule:
interval: "weekly"
day: "friday"
commit-message:
prefix: "[skip ci] "
prefix: "[depbot] "
6 changes: 3 additions & 3 deletions .github/workflows/Build-gear-loader-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ env:

jobs:
build-gear-loader:
runs-on: [self-hosted, epyc-4, k8s-runner]
runs-on: [kuberunner]
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
- name: "ACTIONS: Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Install: Set cargo path"
run: echo "/tmp/cargo/bin" >> $GITHUB_PATH
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
needs: build-gear-loader
steps:
- name: "ACTIONS: Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download artifact
uses: actions/download-artifact@v3
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/CI-docker-gear.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI | docker-gear release version

on:
workflow_dispatch:
inputs:
release_version:
description: 'Release version from https://get.gear.rs Example: v1.0.0. *Null = latest'
required: false
default: ''

env:
RELEASE_VERSION: ${{ github.event.inputs.release_version }}

jobs:
build:
runs-on: [kuberunner]
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v2

- uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-gear-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-gear
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: |
if [ -z "${{ env.RELEASE_VERSION }}" ]; then
echo "DOCKER_TAGS=ghcr.io/gear-tech/node:latest" >> $GITHUB_ENV
else
echo "DOCKER_TAGS=ghcr.io/gear-tech/node:latest,ghcr.io/gear-tech/node:${{ env.RELEASE_VERSION }}" >> $GITHUB_ENV
fi
- uses: docker/build-push-action@v4
with:
file: ./docker/Dockerfile-release
push: true
tags: ${{ env.DOCKER_TAGS }}
build-args: |
RELEASE_VERSION=${{ env.RELEASE_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
Loading

0 comments on commit 316a176

Please sign in to comment.