mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 01:12:17 +01:00
Fix HTTP status code logic
This commit is contained in:
parent
93f3ded0b4
commit
edc61c4d5a
4 changed files with 36 additions and 18 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -32,6 +32,7 @@ jobs:
|
|||
- run: git diff --exit-code
|
||||
|
||||
test-no-nix:
|
||||
needs: build
|
||||
name: "Test: Nix not installed"
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
|
@ -47,6 +48,7 @@ jobs:
|
|||
strict-mode: true
|
||||
|
||||
run-x86_64-linux-untrusted:
|
||||
needs: build
|
||||
name: Run x86_64 Linux, Untrusted
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
|
|
21
dist/index.js
generated
vendored
21
dist/index.js
generated
vendored
|
@ -94996,8 +94996,15 @@ var MagicNixCacheAction = class {
|
|||
try {
|
||||
core.debug(`Indicating workflow start`);
|
||||
const hostAndPort = inputs_exports.getString("listen");
|
||||
const res = await this.client.post(`http://${hostAndPort}/api/workflow-start`).json();
|
||||
core.debug(`back from post: ${res}`);
|
||||
const res = await this.client.post(
|
||||
`http://${hostAndPort}/api/workflow-start`
|
||||
);
|
||||
if (res.statusCode !== 200) {
|
||||
this.failInStrictMode(
|
||||
`Failed to trigger workflow start hook. Expected status 200 but got ${res.statusCode}`
|
||||
);
|
||||
}
|
||||
core.debug(`back from post: ${JSON.stringify(res)}`);
|
||||
} catch (e) {
|
||||
core.info(`Error marking the workflow as started:`);
|
||||
core.info((0,external_node_util_.inspect)(e));
|
||||
|
@ -95022,13 +95029,15 @@ var MagicNixCacheAction = class {
|
|||
try {
|
||||
core.debug(`about to post to localhost`);
|
||||
const hostAndPort = inputs_exports.getString("listen");
|
||||
const res = await this.client.post(`http://${hostAndPort}/api/workflow-finish`).json();
|
||||
if (res.status !== 200) {
|
||||
const res = await this.client.post(
|
||||
`http://${hostAndPort}/api/workflow-finish`
|
||||
);
|
||||
if (res.statusCode !== 200) {
|
||||
this.failInStrictMode(
|
||||
`Failed to trigger workflow finish hook. Response: ${JSON.stringify(res)}`
|
||||
`Failed to trigger workflow finish hook. Expected status 200 but got ${res.statusCode}`
|
||||
);
|
||||
}
|
||||
core.debug(`back from post: ${res}`);
|
||||
core.debug(`back from post: ${JSON.stringify(res.body)}`);
|
||||
} finally {
|
||||
core.debug(`unwatching the daemon log`);
|
||||
log.unwatch();
|
||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
29
src/index.ts
29
src/index.ts
|
@ -1,7 +1,7 @@
|
|||
import { netrcPath, tailLog } from "./helpers.js";
|
||||
import * as actionsCore from "@actions/core";
|
||||
import { IdsToolbox, inputs } from "detsys-ts";
|
||||
import got, { Got } from "got";
|
||||
import got, { Got, Response } from "got";
|
||||
import * as http from "http";
|
||||
import { SpawnOptions, exec, spawn } from "node:child_process";
|
||||
import { mkdirSync, openSync, readFileSync } from "node:fs";
|
||||
|
@ -274,10 +274,17 @@ class MagicNixCacheAction {
|
|||
try {
|
||||
actionsCore.debug(`Indicating workflow start`);
|
||||
const hostAndPort = inputs.getString("listen");
|
||||
const res: Response = await this.client
|
||||
.post(`http://${hostAndPort}/api/workflow-start`)
|
||||
.json();
|
||||
actionsCore.debug(`back from post: ${res}`);
|
||||
const res: Response<string> = await this.client.post(
|
||||
`http://${hostAndPort}/api/workflow-start`,
|
||||
);
|
||||
|
||||
if (res.statusCode !== 200) {
|
||||
this.failInStrictMode(
|
||||
`Failed to trigger workflow start hook. Expected status 200 but got ${res.statusCode}`,
|
||||
);
|
||||
}
|
||||
|
||||
actionsCore.debug(`back from post: ${JSON.stringify(res)}`);
|
||||
} catch (e) {
|
||||
actionsCore.info(`Error marking the workflow as started:`);
|
||||
actionsCore.info(inspect(e));
|
||||
|
@ -307,17 +314,17 @@ class MagicNixCacheAction {
|
|||
try {
|
||||
actionsCore.debug(`about to post to localhost`);
|
||||
const hostAndPort = inputs.getString("listen");
|
||||
const res: Response = await this.client
|
||||
.post(`http://${hostAndPort}/api/workflow-finish`)
|
||||
.json();
|
||||
const res: Response<string> = await this.client.post(
|
||||
`http://${hostAndPort}/api/workflow-finish`,
|
||||
);
|
||||
|
||||
if (res.status !== 200) {
|
||||
if (res.statusCode !== 200) {
|
||||
this.failInStrictMode(
|
||||
`Failed to trigger workflow finish hook. Response: ${JSON.stringify(res)}`,
|
||||
`Failed to trigger workflow finish hook. Expected status 200 but got ${res.statusCode}`,
|
||||
);
|
||||
}
|
||||
|
||||
actionsCore.debug(`back from post: ${res}`);
|
||||
actionsCore.debug(`back from post: ${JSON.stringify(res.body)}`);
|
||||
} finally {
|
||||
actionsCore.debug(`unwatching the daemon log`);
|
||||
log.unwatch();
|
||||
|
|
Loading…
Reference in a new issue