mirror of
https://github.com/DeterminateSystems/nix-installer-action.git
synced 2024-12-23 05:22:21 +01:00
Add the job-status option (#125)
This commit is contained in:
parent
ddfca32d6f
commit
b92f66560d
3 changed files with 12 additions and 3036 deletions
|
@ -34,6 +34,9 @@ inputs:
|
||||||
init:
|
init:
|
||||||
description: "The init system to configure, requires `planner: linux-multi` (allowing the choice between `none` or `systemd`)"
|
description: "The init system to configure, requires `planner: linux-multi` (allowing the choice between `none` or `systemd`)"
|
||||||
required: false
|
required: false
|
||||||
|
job-status:
|
||||||
|
description: The overall status of the job. Set automatically, for aggregate analysis of Nix stability.
|
||||||
|
default: ${{ job.status }}
|
||||||
kvm:
|
kvm:
|
||||||
description: Automatically configure the GitHub Actions Runner for NixOS test supports, if the host supports it.
|
description: Automatically configure the GitHub Actions Runner for NixOS test supports, if the host supports it.
|
||||||
required: false
|
required: false
|
||||||
|
|
2980
dist/index.js
generated
vendored
2980
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
65
src/index.ts
65
src/index.ts
|
@ -1,5 +1,4 @@
|
||||||
import * as actionsCore from "@actions/core";
|
import * as actionsCore from "@actions/core";
|
||||||
import * as github from "@actions/github";
|
|
||||||
import * as actionsExec from "@actions/exec";
|
import * as actionsExec from "@actions/exec";
|
||||||
import { access, readFile } from "node:fs/promises";
|
import { access, readFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
@ -26,7 +25,7 @@ const EVENT_START_DOCKER_SHIM = "start_docker_shim";
|
||||||
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
|
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
|
||||||
|
|
||||||
// Other events
|
// Other events
|
||||||
const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow";
|
const EVENT_CONCLUDE_JOB = "conclude_job";
|
||||||
|
|
||||||
// Facts
|
// Facts
|
||||||
const FACT_DETERMINATE_NIX = "determinate_nix";
|
const FACT_DETERMINATE_NIX = "determinate_nix";
|
||||||
|
@ -39,13 +38,6 @@ const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
|
||||||
// Flags
|
// Flags
|
||||||
const FLAG_DETERMINATE = "--determinate";
|
const FLAG_DETERMINATE = "--determinate";
|
||||||
|
|
||||||
type WorkflowConclusion =
|
|
||||||
| "success"
|
|
||||||
| "failure"
|
|
||||||
| "cancelled"
|
|
||||||
| "unavailable"
|
|
||||||
| "no-jobs";
|
|
||||||
|
|
||||||
class NixInstallerAction extends DetSysAction {
|
class NixInstallerAction extends DetSysAction {
|
||||||
determinate: boolean;
|
determinate: boolean;
|
||||||
platform: string;
|
platform: string;
|
||||||
|
@ -58,6 +50,7 @@ class NixInstallerAction extends DetSysAction {
|
||||||
githubToken: string | null;
|
githubToken: string | null;
|
||||||
forceDockerShim: boolean;
|
forceDockerShim: boolean;
|
||||||
init: string | null;
|
init: string | null;
|
||||||
|
jobConclusion: string | null;
|
||||||
localRoot: string | null;
|
localRoot: string | null;
|
||||||
logDirectives: string | null;
|
logDirectives: string | null;
|
||||||
logger: string | null;
|
logger: string | null;
|
||||||
|
@ -100,6 +93,7 @@ class NixInstallerAction extends DetSysAction {
|
||||||
this.githubToken = inputs.getStringOrNull("github-token");
|
this.githubToken = inputs.getStringOrNull("github-token");
|
||||||
this.githubServerUrl = inputs.getStringOrNull("github-server-url");
|
this.githubServerUrl = inputs.getStringOrNull("github-server-url");
|
||||||
this.init = inputs.getStringOrNull("init");
|
this.init = inputs.getStringOrNull("init");
|
||||||
|
this.jobConclusion = inputs.getStringOrNull("job-status");
|
||||||
this.localRoot = inputs.getStringOrNull("local-root");
|
this.localRoot = inputs.getStringOrNull("local-root");
|
||||||
this.logDirectives = inputs.getStringOrNull("log-directives");
|
this.logDirectives = inputs.getStringOrNull("log-directives");
|
||||||
this.logger = inputs.getStringOrNull("logger");
|
this.logger = inputs.getStringOrNull("logger");
|
||||||
|
@ -1036,63 +1030,14 @@ class NixInstallerAction extends DetSysAction {
|
||||||
|
|
||||||
async reportOverall(): Promise<void> {
|
async reportOverall(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
this.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
|
this.recordEvent(EVENT_CONCLUDE_JOB, {
|
||||||
conclusion: await this.getWorkflowConclusion(),
|
conclusion: this.jobConclusion ?? "unknown",
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
actionsCore.debug(`Error submitting post-run diagnostics report: ${e}`);
|
actionsCore.debug(`Error submitting post-run diagnostics report: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getWorkflowConclusion(): Promise<
|
|
||||||
undefined | WorkflowConclusion
|
|
||||||
> {
|
|
||||||
if (this.githubToken == null) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const octokit = github.getOctokit(this.githubToken);
|
|
||||||
const jobs = await octokit.paginate(
|
|
||||||
octokit.rest.actions.listJobsForWorkflowRun,
|
|
||||||
{
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
run_id: github.context.runId,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
actionsCore.debug(`awaited jobs: ${jobs}`);
|
|
||||||
const job = jobs
|
|
||||||
.filter((candidate) => candidate.name === github.context.job)
|
|
||||||
.at(0);
|
|
||||||
if (job === undefined) {
|
|
||||||
return "no-jobs";
|
|
||||||
}
|
|
||||||
|
|
||||||
const outcomes = (job.steps ?? []).map((j) => j.conclusion ?? "unknown");
|
|
||||||
|
|
||||||
// Possible values: success, failure, cancelled, or skipped
|
|
||||||
// from: https://docs.github.com/en/actions/learn-github-actions/contexts
|
|
||||||
|
|
||||||
if (outcomes.includes("failure")) {
|
|
||||||
// Any failures fails the job
|
|
||||||
return "failure";
|
|
||||||
}
|
|
||||||
if (outcomes.includes("cancelled")) {
|
|
||||||
// Any cancellations cancels the job
|
|
||||||
return "cancelled";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume success if no jobs failed or were canceled
|
|
||||||
return "success";
|
|
||||||
} catch (e) {
|
|
||||||
actionsCore.debug(`Error determining final disposition: ${e}`);
|
|
||||||
return "unavailable";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private get defaultPlanner(): string {
|
private get defaultPlanner(): string {
|
||||||
if (this.isMacOS) {
|
if (this.isMacOS) {
|
||||||
return "macos";
|
return "macos";
|
||||||
|
|
Loading…
Reference in a new issue