Skip to content

Commit

Permalink
chore(ci): skip non-ubuntu test release jobs on PRs (denoland#17353)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 12, 2023
1 parent ee2c6cb commit 9d54765
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 80 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/ci.generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ const installDenoStep = {
with: { "deno-version": "v1.x" },
};

function cancelEarlyIfDraftPr(nextSteps: Record<string, unknown>[]): unknown[] {
function cancelEarlyIfDraftPr(
nextSteps: Record<string, unknown>[],
): Record<string, unknown>[] {
// Couple issues with GH Actions:
//
// 1. The pull_request event type does not include the commit message, so
Expand All @@ -129,14 +131,36 @@ function cancelEarlyIfDraftPr(nextSteps: Record<string, unknown>[]): unknown[] {
"echo $GIT_MESSAGE | grep '\\[ci\\]' || (echo 'Exiting due to draft PR. Commit with [ci] to bypass.' ; echo 'EXIT_EARLY=true' >> $GITHUB_OUTPUT)",
].join("\n"),
},
...nextSteps.map((step) => {
const condition = "steps.exit_early.outputs.EXIT_EARLY != 'true'";
step.if = "if" in step ? `${condition} && (${step.if})` : condition;
return step;
}),
...nextSteps.map((step) =>
skipForCondition(step, "steps.exit_early.outputs.EXIT_EARLY != 'true'")
),
];
}

function skipJobsIfPrAndMarkedSkip(
steps: Record<string, unknown>[],
): Record<string, unknown>[] {
// GitHub does not make skipping a specific matrix element easy
// so just apply this condition to all the steps.
// https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
return steps.map((s) =>
skipForCondition(
s,
"!(github.event_name == 'pull_request' && matrix.skip_pr)",
)
);
}

function skipForCondition(
step: Record<string, unknown>,
condition: string,
): Record<string, unknown> {
return {
...step,
if: "if" in step ? `${condition} && (${step.if})` : condition,
};
}

const ci = {
name: "ci",
on: {
Expand Down Expand Up @@ -181,6 +205,7 @@ const ci = {
os: Runners.macos,
job: "test",
profile: "release",
skip_pr: true,
},
{
os: Runners.windows,
Expand All @@ -191,6 +216,7 @@ const ci = {
os: Runners.windows,
job: "test",
profile: "release",
skip_pr: true,
},
{
os: Runners.linux,
Expand Down Expand Up @@ -229,7 +255,7 @@ const ci = {
CARGO_TERM_COLOR: "always",
RUST_BACKTRACE: "full",
},
steps: [
steps: skipJobsIfPrAndMarkedSkip([
{
name: "Configure git",
run: [
Expand Down Expand Up @@ -791,7 +817,7 @@ const ci = {
},
},
]),
],
]),
},
"publish-canary": {
name: "publish canary",
Expand Down
Loading

0 comments on commit 9d54765

Please sign in to comment.