Skip to content

Commit

Permalink
test issue2679 skip ci
Browse files Browse the repository at this point in the history
  • Loading branch information
zondervancalvez committed Sep 10, 2024
1 parent 7b32791 commit fbd5ee6
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Get the output response
run: echo "${{ steps.lint-git-repo.outputs.lint-git-repo-response }}"

override-skip-ci:
uses: ./.github/workflows/skip-ci-check.yaml

check-coverage:
outputs:
run-coverage: ${{ steps.set-output.outputs.run-coverage }}
Expand Down Expand Up @@ -2662,6 +2665,7 @@ jobs:
ignore-unfixed: false
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'

name: Cactus_CI
'on':
pull_request:
Expand All @@ -2672,4 +2676,11 @@ name: Cactus_CI
push:
branches:
- main
- dev
- dev
workflow_dispatch:
inputs:
run_ci:
description: 'Force run CI, overriding #skip-ci in commit messages'
required: true
default: false
type: boolean
22 changes: 22 additions & 0 deletions .github/workflows/skip-ci-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Skip CI Checker
env:
NODEJS_VERSION: v18.18.2
on:
workflow_call:

jobs:
ci-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2

Check failure on line 12 in .github/workflows/skip-ci-check.yaml

View workflow job for this annotation

GitHub Actions / ActionLint / Lint_GitHub_Actions

the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

- name: Set up Node.js
uses: actions/setup-node@v4.0.3
with:
node-version: ${{ env.NODEJS_VERSION }}

- name: Check skip CI logic
run: node tools/skip-ci.js
env:
INPUT_RUN_CI: ${{ github.event.inputs.run_ci }}
70 changes: 70 additions & 0 deletions tools/skip-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Maintainers allowed to use the #skip-ci tag
const MAINTAINERS = ["trusted-maintainer-1", "trusted-maintainer-2"];

// Check if manual override is set from workflow_dispatch input
const checkOverride = () => {
const override = process.env.INPUT_RUN_CI; // This gets the input from the workflow_dispatch event
if (override && override.toLowerCase() === "true") {
console.log(
"Manual override triggered. CI will run regardless of #skip-ci.",
);
return true;
}
return false;
};

// Check commit message for #skip-ci
const checkSkipCI = () => {
console.log("Checking commit message for #skip-ci...");
const commitMessage = runCommand("git log -1 --pretty=%B");
if (commitMessage.includes("#skip-ci")) {
console.log("Skip requested in commit message.");
return true;
} else {
console.log("No skip request found.");
return false;
}
};

// Check if committer is a trusted maintainer
const checkCommitterIsMaintainer = () => {
const committer = runCommand("git log -1 --pretty=%an");
console.log(`Committer: ${committer}`);

if (MAINTAINERS.includes(committer)) {
console.log("Committer is a trusted maintainer, skipping tests.");
return true;
} else {
console.error("Untrusted committer, failing the job.");
return false;
}
};

// Main logic
const main = () => {
const override = checkOverride();

if (!override) {
const shouldSkipCI = checkSkipCI();

if (shouldSkipCI) {
const isMaintainer = checkCommitterIsMaintainer();
if (isMaintainer) {
console.log("CI skipped as per request.");
process.exit(0); // Exit successfully to skip CI
} else {
console.error("Committer is not trusted. CI will not be skipped.");
process.exit(1); // Fail the pipeline
}
} else {
console.log("No skip requested. Proceeding with CI.");
process.exit(0); // Exit successfully to run CI
}
} else {
console.log("Manual override set. Running CI.");
process.exit(0); // Exit successfully to run CI
}
};

// Run the main function
main();

0 comments on commit fbd5ee6

Please sign in to comment.