Fix HTTP status code logic

This commit is contained in:
Luc Perkins 2024-05-20 09:20:03 -03:00
parent 93f3ded0b4
commit edc61c4d5a
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
4 changed files with 36 additions and 18 deletions

View file

@ -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
View file

@ -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

File diff suppressed because one or more lines are too long

View file

@ -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();