Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(PR): manage validator checks in PR.yml #3767

Merged
merged 17 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/message/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ outputs:
description: If trigger check.
macos:
description: If enable macos.
validator:
description: If enable validator checks.

runs:
using: node20
Expand Down
53 changes: 35 additions & 18 deletions .github/actions/message/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
*/

const ps = require("child_process");
const core = require('@actions/core');
const github = require('@actions/github');
const core = require("@actions/core");
const github = require("@actions/github");

const BUILD_LABELS = ["A0-pleasereview", 'A4-insubstantial', 'A2-mergeoncegreen'];
const CHECKS = ["check", "build"]
const DEPBOT = "[depbot]";
const BUILD_LABELS = [
"A0-pleasereview",
"A4-insubstantial",
"A2-mergeoncegreen",
];

const CHECKS = ["check", "build"];
const MACOS = "E2-forcemacos";
const SCCACHE_PREFIX = '/mnt/sccache/';
const VALIDATOR_LABEL = "check-validator";
const DEPBOT = "[depbot]";
const SCCACHE_PREFIX = "/mnt/sccache/";
const SKIP_CI = "[skip-ci]";
const SKIP_CACHE = "[skip-cache]";
const [owner, repo] = ["gear-tech", "gear"];
Expand Down Expand Up @@ -47,11 +53,17 @@ async function mock(head_sha) {
*/
async function main() {
const {
pull_request: { title, head: { sha, ref: branch }, labels: _labels },
repository: { full_name: fullName }
pull_request: {
title,
head: { sha, ref: branch },
labels: _labels,
},
repository: { full_name: fullName },
} = github.context.payload;
const labels = _labels.map(l => l.name);
const message = ps.execSync(`git log --format=%B -n 1 ${sha}`, { encoding: "utf-8" }).trim();
const labels = _labels.map((l) => l.name);
const message = ps
.execSync(`git log --format=%B -n 1 ${sha}`, { encoding: "utf-8" })
.trim();

console.log("message: ", message);
console.log("head-sha: ", sha);
Expand All @@ -61,29 +73,34 @@ async function main() {

// Calculate configurations.
const isDepbot = fullName === `${owner}/${repo}` && title.includes(DEPBOT);
const skipCache = [title, message].some(s => s.includes(SKIP_CACHE));
const skipCI = [title, message].some(s => s.includes(SKIP_CI));
const build = !skipCI && (isDepbot || BUILD_LABELS.some(label => labels.includes(label)));
const skipCache = [title, message].some((s) => s.includes(SKIP_CACHE));
const skipCI = [title, message].some((s) => s.includes(SKIP_CI));
const build =
!skipCI &&
(isDepbot || BUILD_LABELS.some((label) => labels.includes(label)));
const macos = !skipCI && labels.includes(MACOS);
const validator = !skipCI && labels.includes(VALIDATOR_LABEL);
const cache = SCCACHE_PREFIX + branch.replace("/", "_");

// Set outputs
core.setOutput("build", build);
core.setOutput("check", !skipCI);
core.setOutput("macos", macos);
!skipCache && core.setOutput("cache", cache)
core.setOutput("validator", validator);
!skipCache && core.setOutput("cache", cache);

console.log("---");
console.log("build: ", build);
console.log("cache: ", skipCache ? "false" : cache);
console.log("check: ", !skipCI);
console.log("macos: ", macos);
console.log("validator: ", validator);
console.log("cache: ", skipCache ? "false" : cache);

// Mock checks if skipping CI.
if (skipCI) await mock(sha);
}

main().catch(err => {
main().catch((err) => {
core.error("ERROR: ", err.message);
core.error(err.stack)
})
core.error(err.stack);
});
6 changes: 6 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
cache: ${{ steps.config.outputs.cache }}
check: ${{ steps.config.outputs.check }}
macos: ${{ steps.config.outputs.macos }}
validator: ${{ steps.config.outputs.validator }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -51,3 +52,8 @@ jobs:
with:
cache: ${{ needs.status.outputs.cache }}
macos: ${{ needs.status.outputs.macos == 'true' }}

validator:
needs: status
if: ${{ needs.status.outputs.validator == 'true' }}
uses: ./.github/workflows/validation.yml
9 changes: 2 additions & 7 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
name: Live check on Vara Network Validator machine

on:
pull_request:
types: [synchronize, labeled, opened, reopened, ready_for_review]
branches: [master]
workflow_dispatch:
workflow_call:

env:
CARGO_TERM_COLOR: always

jobs:
tag-image:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'check-validator')
outputs:
image_tag: ${{ steps.image-tag.outputs.tag }}
steps:
Expand All @@ -25,10 +22,8 @@ jobs:

build-update-validator:
runs-on: [kuberunner]
if: contains(github.event.pull_request.labels.*.name, 'check-validator')
needs: tag-image
steps:

- name: Checkout repo
uses: actions/checkout@v4

Expand Down Expand Up @@ -56,7 +51,7 @@ jobs:

- name: SSH into VM
uses: appleboy/ssh-action@v1.0.3
env:
env:
NEW_IMAGE: ${{ needs.tag-image.outputs.image_tag }}
with:
host: ${{ secrets.VARA_VALIDATOR_8 }}
Expand Down
Loading