mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-14 16:43:07 +08:00
Compare commits
1 Commits
3a9fe54818
...
94b2037a7a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94b2037a7a |
12
README.md
12
README.md
@ -39,10 +39,7 @@ Some extra options can be passed to the `docker compose up` command using the `u
|
|||||||
### Post hook
|
### Post hook
|
||||||
|
|
||||||
On post hook, the action will run `docker compose down` to clean up the services.
|
On post hook, the action will run `docker compose down` to clean up the services.
|
||||||
|
In [debug mode](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging), the logs of the running services are printed before the cleanup.
|
||||||
Logs of the Docker Compose services are logged using GitHub `core.ts` API before the cleanup.
|
|
||||||
The log level can be set using the `services-log-level` input. The default is `debug`, which will
|
|
||||||
only print logs if [debug mode](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging) is switched on.
|
|
||||||
|
|
||||||
Some extra options can be passed to the `docker compose down` command using the `down-flags` input.
|
Some extra options can be passed to the `docker compose down` command using the `down-flags` input.
|
||||||
|
|
||||||
@ -95,10 +92,6 @@ Some extra options can be passed to the `docker compose down` command using the
|
|||||||
#
|
#
|
||||||
# Default: ${{ github.token }}
|
# Default: ${{ github.token }}
|
||||||
github-token: ""
|
github-token: ""
|
||||||
|
|
||||||
# Description: The log level used for Docker Compose service logs. Can be one of "debug", "info".
|
|
||||||
# Default: "debug"
|
|
||||||
services-log-level: "debug"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- end usage -->
|
<!-- end usage -->
|
||||||
@ -108,7 +101,7 @@ Some extra options can be passed to the `docker compose down` command using the
|
|||||||
<!-- start inputs -->
|
<!-- start inputs -->
|
||||||
|
|
||||||
| **Input** | **Description** | **Default** | **Required** |
|
| **Input** | **Description** | **Default** | **Required** |
|
||||||
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
|
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
|
||||||
| <code>docker-flags</code> | Additional options to pass to <code>docker</code> command. | | **false** |
|
| <code>docker-flags</code> | Additional options to pass to <code>docker</code> command. | | **false** |
|
||||||
| <code>compose-file</code> | Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd). | <code>./docker-compose.yml</code> | **false** |
|
| <code>compose-file</code> | Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd). | <code>./docker-compose.yml</code> | **false** |
|
||||||
| <code>services</code> | Services to perform docker compose up. | | **false** |
|
| <code>services</code> | Services to perform docker compose up. | | **false** |
|
||||||
@ -118,7 +111,6 @@ Some extra options can be passed to the `docker compose down` command using the
|
|||||||
| <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** |
|
| <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** |
|
||||||
| <code>compose-version</code> | Compose version to use.<br />If null (default), it will use the current installed version.<br />If "latest", it will install the latest version. | | **false** |
|
| <code>compose-version</code> | Compose version to use.<br />If null (default), it will use the current installed version.<br />If "latest", it will install the latest version. | | **false** |
|
||||||
| <code>github-token</code> | The GitHub token used to create an authenticated client (to fetch the latest version of docker compose). | <code>${{ github.token }}</code> | **false** |
|
| <code>github-token</code> | The GitHub token used to create an authenticated client (to fetch the latest version of docker compose). | <code>${{ github.token }}</code> | **false** |
|
||||||
| <code>services-log-level</code> | The log level used for Docker Compose service logs. Can be one of "debug", "info". | debug | **false** |
|
|
||||||
|
|
||||||
<!-- end inputs -->
|
<!-- end inputs -->
|
||||||
<!-- start outputs -->
|
<!-- start outputs -->
|
||||||
|
|||||||
33
dist/index.js
generated
vendored
33
dist/index.js
generated
vendored
@ -33052,7 +33052,7 @@ async function run() {
|
|||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
upFlags: inputs.upFlags,
|
upFlags: inputs.upFlags,
|
||||||
services: inputs.services,
|
services: inputs.services,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
loggerService.info("docker compose service(s) are up");
|
loggerService.info("docker compose service(s) are up");
|
||||||
}
|
}
|
||||||
@ -33197,12 +33197,12 @@ class DockerComposeService {
|
|||||||
output: out,
|
output: out,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, serviceLogger, }) {
|
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||||
return {
|
return {
|
||||||
config: composeFiles,
|
config: composeFiles,
|
||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => serviceLogger(chunk.toString()),
|
callback: (chunk) => debug(chunk.toString()),
|
||||||
executable: {
|
executable: {
|
||||||
executablePath: "docker",
|
executablePath: "docker",
|
||||||
options: dockerFlags,
|
options: dockerFlags,
|
||||||
@ -33225,7 +33225,6 @@ exports.InputService = exports.COMPOSE_VERSION_LATEST = exports.InputNames = voi
|
|||||||
const core_1 = __nccwpck_require__(7484);
|
const core_1 = __nccwpck_require__(7484);
|
||||||
const fs_1 = __nccwpck_require__(9896);
|
const fs_1 = __nccwpck_require__(9896);
|
||||||
const path_1 = __nccwpck_require__(6928);
|
const path_1 = __nccwpck_require__(6928);
|
||||||
const logger_service_1 = __nccwpck_require__(8187);
|
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
InputNames["DockerFlags"] = "docker-flags";
|
InputNames["DockerFlags"] = "docker-flags";
|
||||||
@ -33237,7 +33236,6 @@ var InputNames;
|
|||||||
InputNames["Cwd"] = "cwd";
|
InputNames["Cwd"] = "cwd";
|
||||||
InputNames["ComposeVersion"] = "compose-version";
|
InputNames["ComposeVersion"] = "compose-version";
|
||||||
InputNames["GithubToken"] = "github-token";
|
InputNames["GithubToken"] = "github-token";
|
||||||
InputNames["ServiceLogLevel"] = "services-log-level";
|
|
||||||
})(InputNames || (exports.InputNames = InputNames = {}));
|
})(InputNames || (exports.InputNames = InputNames = {}));
|
||||||
exports.COMPOSE_VERSION_LATEST = "latest";
|
exports.COMPOSE_VERSION_LATEST = "latest";
|
||||||
class InputService {
|
class InputService {
|
||||||
@ -33252,7 +33250,6 @@ class InputService {
|
|||||||
cwd: this.getCwd(),
|
cwd: this.getCwd(),
|
||||||
composeVersion: this.getComposeVersion(),
|
composeVersion: this.getComposeVersion(),
|
||||||
githubToken: this.getGithubToken(),
|
githubToken: this.getGithubToken(),
|
||||||
serviceLogLevel: this.getServiceLogLevel(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getDockerFlags() {
|
getDockerFlags() {
|
||||||
@ -33308,13 +33305,6 @@ class InputService {
|
|||||||
required: false,
|
required: false,
|
||||||
}) || null);
|
}) || null);
|
||||||
}
|
}
|
||||||
getServiceLogLevel() {
|
|
||||||
const configuredLevel = (0, core_1.getInput)(InputNames.ServiceLogLevel, { required: false });
|
|
||||||
if (configuredLevel && !Object.values(logger_service_1.LogLevel).includes(configuredLevel)) {
|
|
||||||
throw new Error(`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(logger_service_1.LogLevel).join(", ")}`);
|
|
||||||
}
|
|
||||||
return configuredLevel || logger_service_1.LogLevel.Debug;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.InputService = InputService;
|
exports.InputService = InputService;
|
||||||
|
|
||||||
@ -33387,7 +33377,7 @@ exports.ManualInstallerAdapter = ManualInstallerAdapter;
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.LogLevel = exports.LoggerService = void 0;
|
exports.LoggerService = void 0;
|
||||||
const core_1 = __nccwpck_require__(7484);
|
const core_1 = __nccwpck_require__(7484);
|
||||||
class LoggerService {
|
class LoggerService {
|
||||||
warn(message) {
|
warn(message) {
|
||||||
@ -33399,23 +33389,8 @@ class LoggerService {
|
|||||||
debug(message) {
|
debug(message) {
|
||||||
(0, core_1.debug)(message);
|
(0, core_1.debug)(message);
|
||||||
}
|
}
|
||||||
getServiceLogger(level) {
|
|
||||||
switch (level) {
|
|
||||||
case LogLevel.Debug:
|
|
||||||
return this.debug;
|
|
||||||
case LogLevel.Info:
|
|
||||||
return this.info;
|
|
||||||
default:
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.LoggerService = LoggerService;
|
exports.LoggerService = LoggerService;
|
||||||
var LogLevel;
|
|
||||||
(function (LogLevel) {
|
|
||||||
LogLevel["Debug"] = "debug";
|
|
||||||
LogLevel["Info"] = "info";
|
|
||||||
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
35
dist/post.js
generated
vendored
35
dist/post.js
generated
vendored
@ -26212,7 +26212,7 @@ async function run() {
|
|||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
services: inputs.services,
|
services: inputs.services,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
if (error) {
|
if (error) {
|
||||||
loggerService.debug("docker compose error:\n" + error);
|
loggerService.debug("docker compose error:\n" + error);
|
||||||
@ -26224,7 +26224,7 @@ async function run() {
|
|||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
downFlags: inputs.downFlags,
|
downFlags: inputs.downFlags,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
loggerService.info("docker compose is down");
|
loggerService.info("docker compose is down");
|
||||||
}
|
}
|
||||||
@ -26274,12 +26274,12 @@ class DockerComposeService {
|
|||||||
output: out,
|
output: out,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, serviceLogger, }) {
|
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||||
return {
|
return {
|
||||||
config: composeFiles,
|
config: composeFiles,
|
||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => serviceLogger(chunk.toString()),
|
callback: (chunk) => debug(chunk.toString()),
|
||||||
executable: {
|
executable: {
|
||||||
executablePath: "docker",
|
executablePath: "docker",
|
||||||
options: dockerFlags,
|
options: dockerFlags,
|
||||||
@ -26302,7 +26302,6 @@ exports.InputService = exports.COMPOSE_VERSION_LATEST = exports.InputNames = voi
|
|||||||
const core_1 = __nccwpck_require__(7484);
|
const core_1 = __nccwpck_require__(7484);
|
||||||
const fs_1 = __nccwpck_require__(9896);
|
const fs_1 = __nccwpck_require__(9896);
|
||||||
const path_1 = __nccwpck_require__(6928);
|
const path_1 = __nccwpck_require__(6928);
|
||||||
const logger_service_1 = __nccwpck_require__(8187);
|
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
InputNames["DockerFlags"] = "docker-flags";
|
InputNames["DockerFlags"] = "docker-flags";
|
||||||
@ -26314,7 +26313,6 @@ var InputNames;
|
|||||||
InputNames["Cwd"] = "cwd";
|
InputNames["Cwd"] = "cwd";
|
||||||
InputNames["ComposeVersion"] = "compose-version";
|
InputNames["ComposeVersion"] = "compose-version";
|
||||||
InputNames["GithubToken"] = "github-token";
|
InputNames["GithubToken"] = "github-token";
|
||||||
InputNames["ServiceLogLevel"] = "services-log-level";
|
|
||||||
})(InputNames || (exports.InputNames = InputNames = {}));
|
})(InputNames || (exports.InputNames = InputNames = {}));
|
||||||
exports.COMPOSE_VERSION_LATEST = "latest";
|
exports.COMPOSE_VERSION_LATEST = "latest";
|
||||||
class InputService {
|
class InputService {
|
||||||
@ -26329,7 +26327,6 @@ class InputService {
|
|||||||
cwd: this.getCwd(),
|
cwd: this.getCwd(),
|
||||||
composeVersion: this.getComposeVersion(),
|
composeVersion: this.getComposeVersion(),
|
||||||
githubToken: this.getGithubToken(),
|
githubToken: this.getGithubToken(),
|
||||||
serviceLogLevel: this.getServiceLogLevel(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getDockerFlags() {
|
getDockerFlags() {
|
||||||
@ -26385,13 +26382,6 @@ class InputService {
|
|||||||
required: false,
|
required: false,
|
||||||
}) || null);
|
}) || null);
|
||||||
}
|
}
|
||||||
getServiceLogLevel() {
|
|
||||||
const configuredLevel = (0, core_1.getInput)(InputNames.ServiceLogLevel, { required: false });
|
|
||||||
if (configuredLevel && !Object.values(logger_service_1.LogLevel).includes(configuredLevel)) {
|
|
||||||
throw new Error(`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(logger_service_1.LogLevel).join(", ")}`);
|
|
||||||
}
|
|
||||||
return configuredLevel || logger_service_1.LogLevel.Debug;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.InputService = InputService;
|
exports.InputService = InputService;
|
||||||
|
|
||||||
@ -26404,7 +26394,7 @@ exports.InputService = InputService;
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.LogLevel = exports.LoggerService = void 0;
|
exports.LoggerService = void 0;
|
||||||
const core_1 = __nccwpck_require__(7484);
|
const core_1 = __nccwpck_require__(7484);
|
||||||
class LoggerService {
|
class LoggerService {
|
||||||
warn(message) {
|
warn(message) {
|
||||||
@ -26416,23 +26406,8 @@ class LoggerService {
|
|||||||
debug(message) {
|
debug(message) {
|
||||||
(0, core_1.debug)(message);
|
(0, core_1.debug)(message);
|
||||||
}
|
}
|
||||||
getServiceLogger(level) {
|
|
||||||
switch (level) {
|
|
||||||
case LogLevel.Debug:
|
|
||||||
return this.debug;
|
|
||||||
case LogLevel.Info:
|
|
||||||
return this.info;
|
|
||||||
default:
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.LoggerService = LoggerService;
|
exports.LoggerService = LoggerService;
|
||||||
var LogLevel;
|
|
||||||
(function (LogLevel) {
|
|
||||||
LogLevel["Debug"] = "debug";
|
|
||||||
LogLevel["Info"] = "info";
|
|
||||||
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
||||||
"all": "npm run format && npm run lint && npm run test && npm run package",
|
"all": "npm run format && npm run lint && npm run test && npm run package",
|
||||||
"build": "tsc --noEmit",
|
"build": "tsc --noEmit",
|
||||||
"format": "prettier --cache --write .",
|
"format": "prettier --cache --write '**/*.ts'",
|
||||||
"jest": "jest --detectOpenHandles --forceExit",
|
"jest": "jest --detectOpenHandles --forceExit",
|
||||||
"test": "npm run jest --maxWorkers=50%",
|
"test": "npm run jest --maxWorkers=50%",
|
||||||
"test:watch": "npm run jest --watch --maxWorkers=25%",
|
"test:watch": "npm run jest --watch --maxWorkers=25%",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { InputService } from "./services/input.service";
|
import { InputService } from "./services/input.service";
|
||||||
import { LoggerService, LogLevel } from "./services/logger.service";
|
import { LoggerService } from "./services/logger.service";
|
||||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
||||||
import * as indexRunner from "./index-runner";
|
import * as indexRunner from "./index-runner";
|
||||||
import { DockerComposeService } from "./services/docker-compose.service";
|
import { DockerComposeService } from "./services/docker-compose.service";
|
||||||
@ -37,7 +37,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: "1.29.2",
|
composeVersion: "1.29.2",
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
installMock.mockResolvedValue("1.29.2");
|
installMock.mockResolvedValue("1.29.2");
|
||||||
@ -51,7 +50,7 @@ describe("run", () => {
|
|||||||
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
||||||
|
|
||||||
expect(debugMock).toHaveBeenCalledWith(
|
expect(debugMock).toHaveBeenCalledWith(
|
||||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null,"serviceLogLevel":"debug"}'
|
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(installMock).toHaveBeenCalledWith({
|
expect(installMock).toHaveBeenCalledWith({
|
||||||
@ -67,7 +66,7 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
services: [],
|
services: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(setFailedMock).not.toHaveBeenCalled();
|
expect(setFailedMock).not.toHaveBeenCalled();
|
||||||
@ -85,7 +84,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@ -99,7 +97,7 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
expect(setFailedMock).not.toHaveBeenCalled();
|
expect(setFailedMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@ -119,7 +117,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@ -144,7 +141,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export async function run(): Promise<void> {
|
|||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
upFlags: inputs.upFlags,
|
upFlags: inputs.upFlags,
|
||||||
services: inputs.services,
|
services: inputs.services,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
loggerService.info("docker compose service(s) are up");
|
loggerService.info("docker compose service(s) are up");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { DockerComposeService } from "./services/docker-compose.service";
|
import { DockerComposeService } from "./services/docker-compose.service";
|
||||||
import { InputService } from "./services/input.service";
|
import { InputService } from "./services/input.service";
|
||||||
import { LoggerService, LogLevel } from "./services/logger.service";
|
import { LoggerService } from "./services/logger.service";
|
||||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
||||||
|
|
||||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||||
@ -34,7 +34,6 @@ describe("index", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
installMock.mockResolvedValue("1.2.3");
|
installMock.mockResolvedValue("1.2.3");
|
||||||
@ -50,7 +49,7 @@ describe("index", () => {
|
|||||||
// Verify that all of the functions were called correctly
|
// Verify that all of the functions were called correctly
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(
|
expect(debugMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}'
|
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null}'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
|
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
|
||||||
@ -62,7 +61,7 @@ describe("index", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(setFailedMock).not.toHaveBeenCalled();
|
expect(setFailedMock).not.toHaveBeenCalled();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { InputService } from "./services/input.service";
|
import { InputService } from "./services/input.service";
|
||||||
import { LoggerService, LogLevel } from "./services/logger.service";
|
import { LoggerService } from "./services/logger.service";
|
||||||
import * as postRunner from "./post-runner";
|
import * as postRunner from "./post-runner";
|
||||||
import { DockerComposeService } from "./services/docker-compose.service";
|
import { DockerComposeService } from "./services/docker-compose.service";
|
||||||
|
|
||||||
@ -36,7 +36,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||||
@ -53,7 +52,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
services: [],
|
services: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
@ -62,7 +61,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
||||||
@ -84,7 +83,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
logsMock.mockResolvedValue({
|
logsMock.mockResolvedValue({
|
||||||
@ -104,7 +102,7 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
dockerFlags: [],
|
dockerFlags: [],
|
||||||
services: [],
|
services: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
@ -113,7 +111,7 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
dockerFlags: [],
|
dockerFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
|
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
|
||||||
@ -150,7 +148,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@ -175,7 +172,6 @@ describe("run", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export async function run(): Promise<void> {
|
|||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
services: inputs.services,
|
services: inputs.services,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -36,7 +36,7 @@ export async function run(): Promise<void> {
|
|||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
downFlags: inputs.downFlags,
|
downFlags: inputs.downFlags,
|
||||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
debug: loggerService.debug,
|
||||||
});
|
});
|
||||||
|
|
||||||
loggerService.info("docker compose is down");
|
loggerService.info("docker compose is down");
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { DockerComposeService } from "./services/docker-compose.service";
|
import { DockerComposeService } from "./services/docker-compose.service";
|
||||||
import { InputService } from "./services/input.service";
|
import { InputService } from "./services/input.service";
|
||||||
import { LoggerService, LogLevel } from "./services/logger.service";
|
import { LoggerService } from "./services/logger.service";
|
||||||
|
|
||||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||||
@ -33,7 +33,6 @@ describe("post", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
composeVersion: null,
|
composeVersion: null,
|
||||||
githubToken: null,
|
githubToken: null,
|
||||||
serviceLogLevel: LogLevel.Debug,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||||
@ -49,7 +48,7 @@ describe("post", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
services: [],
|
services: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
@ -58,7 +57,7 @@ describe("post", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
|
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
|
||||||
|
|||||||
@ -31,7 +31,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: jest.fn(),
|
debug: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.up(upInputs);
|
await service.up(upInputs);
|
||||||
@ -47,15 +47,6 @@ describe("DockerComposeService", () => {
|
|||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
callback: expect.any(Function),
|
callback: expect.any(Function),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure callback is calling the service logger
|
|
||||||
const callback = upAllMock?.mock?.calls[0][0]?.callback;
|
|
||||||
expect(callback).toBeDefined();
|
|
||||||
|
|
||||||
const message = "test log output";
|
|
||||||
callback ? callback(Buffer.from(message)) : null;
|
|
||||||
|
|
||||||
expect(upInputs.serviceLogger).toHaveBeenCalledWith("test log output");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call up with specific docker flags", async () => {
|
it("should call up with specific docker flags", async () => {
|
||||||
@ -66,7 +57,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: jest.fn(),
|
debug: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.up(upInputs);
|
await service.up(upInputs);
|
||||||
@ -92,7 +83,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: ["--build"],
|
upFlags: ["--build"],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: jest.fn(),
|
debug: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.up(upInputs);
|
await service.up(upInputs);
|
||||||
@ -119,7 +110,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
downFlags: ["--volumes", "--remove-orphans"],
|
downFlags: ["--volumes", "--remove-orphans"],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: jest.fn(),
|
debug: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.down(downInputs);
|
await service.down(downInputs);
|
||||||
@ -147,7 +138,7 @@ describe("DockerComposeService", () => {
|
|||||||
services: ["helloworld2", "helloworld3"],
|
services: ["helloworld2", "helloworld3"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
serviceLogger: debugMock,
|
debug: debugMock,
|
||||||
};
|
};
|
||||||
|
|
||||||
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
||||||
|
|||||||
@ -13,7 +13,7 @@ type OptionsInputs = {
|
|||||||
composeFiles: Inputs["composeFiles"];
|
composeFiles: Inputs["composeFiles"];
|
||||||
composeFlags: Inputs["composeFlags"];
|
composeFlags: Inputs["composeFlags"];
|
||||||
cwd: Inputs["cwd"];
|
cwd: Inputs["cwd"];
|
||||||
serviceLogger: (message: string) => void;
|
debug: (message: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
|
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
|
||||||
@ -66,13 +66,13 @@ export class DockerComposeService {
|
|||||||
composeFiles,
|
composeFiles,
|
||||||
composeFlags,
|
composeFlags,
|
||||||
cwd,
|
cwd,
|
||||||
serviceLogger,
|
debug,
|
||||||
}: OptionsInputs): IDockerComposeOptions {
|
}: OptionsInputs): IDockerComposeOptions {
|
||||||
return {
|
return {
|
||||||
config: composeFiles,
|
config: composeFiles,
|
||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => serviceLogger(chunk.toString()),
|
callback: (chunk) => debug(chunk.toString()),
|
||||||
executable: {
|
executable: {
|
||||||
executablePath: "docker",
|
executablePath: "docker",
|
||||||
options: dockerFlags,
|
options: dockerFlags,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { InputService, InputNames } from "./input.service";
|
import { InputService, InputNames } from "./input.service";
|
||||||
import { LogLevel } from "./logger.service";
|
|
||||||
|
|
||||||
describe("InputService", () => {
|
describe("InputService", () => {
|
||||||
let service: InputService;
|
let service: InputService;
|
||||||
@ -16,15 +15,6 @@ describe("InputService", () => {
|
|||||||
getInputMock = jest.spyOn(core, "getInput").mockImplementation();
|
getInputMock = jest.spyOn(core, "getInput").mockImplementation();
|
||||||
getMultilineInputMock = jest.spyOn(core, "getMultilineInput").mockImplementation();
|
getMultilineInputMock = jest.spyOn(core, "getMultilineInput").mockImplementation();
|
||||||
|
|
||||||
getMultilineInputMock.mockImplementation((inputName) => {
|
|
||||||
switch (inputName) {
|
|
||||||
case InputNames.ComposeFile:
|
|
||||||
return ["file1"];
|
|
||||||
default:
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
service = new InputService();
|
service = new InputService();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,6 +25,15 @@ describe("InputService", () => {
|
|||||||
describe("getInputs", () => {
|
describe("getInputs", () => {
|
||||||
describe("docker-flags", () => {
|
describe("docker-flags", () => {
|
||||||
it("should return given docker-flags input", () => {
|
it("should return given docker-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.DockerFlags:
|
case InputNames.DockerFlags:
|
||||||
@ -52,6 +51,15 @@ describe("InputService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty array when no docker-flags input", () => {
|
it("should return empty array when no docker-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockReturnValue("");
|
getInputMock.mockReturnValue("");
|
||||||
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
existsSyncMock.mockReturnValue(true);
|
||||||
@ -141,6 +149,15 @@ describe("InputService", () => {
|
|||||||
|
|
||||||
describe("compose-flags", () => {
|
describe("compose-flags", () => {
|
||||||
it("should return given compose-flags input", () => {
|
it("should return given compose-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.ComposeFlags:
|
case InputNames.ComposeFlags:
|
||||||
@ -158,6 +175,15 @@ describe("InputService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty array when no compose-flags input", () => {
|
it("should return empty array when no compose-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockReturnValue("");
|
getInputMock.mockReturnValue("");
|
||||||
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
existsSyncMock.mockReturnValue(true);
|
||||||
@ -170,6 +196,15 @@ describe("InputService", () => {
|
|||||||
|
|
||||||
describe("up-flags", () => {
|
describe("up-flags", () => {
|
||||||
it("should return given up-flags input", () => {
|
it("should return given up-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.UpFlags:
|
case InputNames.UpFlags:
|
||||||
@ -187,6 +222,15 @@ describe("InputService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty array when no up-flags input", () => {
|
it("should return empty array when no up-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockReturnValue("");
|
getInputMock.mockReturnValue("");
|
||||||
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
existsSyncMock.mockReturnValue(true);
|
||||||
@ -199,6 +243,15 @@ describe("InputService", () => {
|
|||||||
|
|
||||||
describe("down-flags", () => {
|
describe("down-flags", () => {
|
||||||
it("should return given down-flags input", () => {
|
it("should return given down-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.DownFlags:
|
case InputNames.DownFlags:
|
||||||
@ -216,6 +269,15 @@ describe("InputService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty array when no down-flags input", () => {
|
it("should return empty array when no down-flags input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getInputMock.mockReturnValue("");
|
getInputMock.mockReturnValue("");
|
||||||
existsSyncMock.mockReturnValue(true);
|
existsSyncMock.mockReturnValue(true);
|
||||||
|
|
||||||
@ -227,6 +289,14 @@ describe("InputService", () => {
|
|||||||
|
|
||||||
describe("cwd", () => {
|
describe("cwd", () => {
|
||||||
it("should return given cwd input", () => {
|
it("should return given cwd input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.Cwd:
|
case InputNames.Cwd:
|
||||||
@ -245,6 +315,14 @@ describe("InputService", () => {
|
|||||||
|
|
||||||
describe("compose-version", () => {
|
describe("compose-version", () => {
|
||||||
it("should return given compose-version input", () => {
|
it("should return given compose-version input", () => {
|
||||||
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.ComposeFile:
|
||||||
|
return ["file1"];
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
getInputMock.mockImplementation((inputName) => {
|
getInputMock.mockImplementation((inputName) => {
|
||||||
switch (inputName) {
|
switch (inputName) {
|
||||||
case InputNames.ComposeVersion:
|
case InputNames.ComposeVersion:
|
||||||
@ -260,53 +338,5 @@ describe("InputService", () => {
|
|||||||
expect(inputs.composeVersion).toEqual("compose-version");
|
expect(inputs.composeVersion).toEqual("compose-version");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("services-log-level", () => {
|
|
||||||
it("should return given services-log-level input", () => {
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
|
||||||
switch (inputName) {
|
|
||||||
case InputNames.ServiceLogLevel:
|
|
||||||
return "info";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
|
||||||
|
|
||||||
const inputs = service.getInputs();
|
|
||||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Info);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return default services-log-level input", () => {
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
|
||||||
switch (inputName) {
|
|
||||||
case InputNames.ServiceLogLevel:
|
|
||||||
return "";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
|
||||||
|
|
||||||
const inputs = service.getInputs();
|
|
||||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Debug);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw an error when services-log-level input is invalid", () => {
|
|
||||||
getInputMock.mockImplementation((inputName) => {
|
|
||||||
switch (inputName) {
|
|
||||||
case InputNames.ServiceLogLevel:
|
|
||||||
return "invalid-log-level";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
existsSyncMock.mockReturnValue(true);
|
|
||||||
|
|
||||||
expect(() => service.getInputs()).toThrow(
|
|
||||||
'Invalid service log level "invalid-log-level". Valid values are: debug, info'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { getInput, getMultilineInput } from "@actions/core";
|
import { getInput, getMultilineInput } from "@actions/core";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { LogLevel } from "./logger.service";
|
|
||||||
|
|
||||||
export type Inputs = {
|
export type Inputs = {
|
||||||
dockerFlags: string[];
|
dockerFlags: string[];
|
||||||
@ -13,7 +12,6 @@ export type Inputs = {
|
|||||||
cwd: string;
|
cwd: string;
|
||||||
composeVersion: string | null;
|
composeVersion: string | null;
|
||||||
githubToken: string | null;
|
githubToken: string | null;
|
||||||
serviceLogLevel: LogLevel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum InputNames {
|
export enum InputNames {
|
||||||
@ -26,7 +24,6 @@ export enum InputNames {
|
|||||||
Cwd = "cwd",
|
Cwd = "cwd",
|
||||||
ComposeVersion = "compose-version",
|
ComposeVersion = "compose-version",
|
||||||
GithubToken = "github-token",
|
GithubToken = "github-token",
|
||||||
ServiceLogLevel = "services-log-level",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const COMPOSE_VERSION_LATEST = "latest";
|
export const COMPOSE_VERSION_LATEST = "latest";
|
||||||
@ -43,7 +40,6 @@ export class InputService {
|
|||||||
cwd: this.getCwd(),
|
cwd: this.getCwd(),
|
||||||
composeVersion: this.getComposeVersion(),
|
composeVersion: this.getComposeVersion(),
|
||||||
githubToken: this.getGithubToken(),
|
githubToken: this.getGithubToken(),
|
||||||
serviceLogLevel: this.getServiceLogLevel(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,14 +115,4 @@ export class InputService {
|
|||||||
}) || null
|
}) || null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getServiceLogLevel(): LogLevel {
|
|
||||||
const configuredLevel = getInput(InputNames.ServiceLogLevel, { required: false });
|
|
||||||
if (configuredLevel && !Object.values(LogLevel).includes(configuredLevel as LogLevel)) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(LogLevel).join(", ")}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (configuredLevel as LogLevel) || LogLevel.Debug;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { LoggerService, LogLevel } from "./logger.service";
|
import { LoggerService } from "./logger.service";
|
||||||
import { debug, info, warning } from "@actions/core";
|
import { debug, info, warning } from "@actions/core";
|
||||||
|
|
||||||
jest.mock("@actions/core", () => ({
|
jest.mock("@actions/core", () => ({
|
||||||
@ -43,21 +43,4 @@ describe("LoggerService", () => {
|
|||||||
expect(debug).toHaveBeenCalledWith(message);
|
expect(debug).toHaveBeenCalledWith(message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getServiceLogger", () => {
|
|
||||||
it("should return the correct logger function for debug level", () => {
|
|
||||||
const logger = loggerService.getServiceLogger(LogLevel.Debug);
|
|
||||||
expect(logger).toBe(loggerService.debug);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return the correct logger function for info level", () => {
|
|
||||||
const logger = loggerService.getServiceLogger(LogLevel.Info);
|
|
||||||
expect(logger).toBe(loggerService.info);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should default to info level if an unknown level is provided", () => {
|
|
||||||
const logger = loggerService.getServiceLogger("unknown" as LogLevel);
|
|
||||||
expect(logger).toBe(loggerService.info);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,20 +12,4 @@ export class LoggerService {
|
|||||||
debug(message: string) {
|
debug(message: string) {
|
||||||
debug(message);
|
debug(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
getServiceLogger(level: LogLevel): (message: string) => void {
|
|
||||||
switch (level) {
|
|
||||||
case LogLevel.Debug:
|
|
||||||
return this.debug;
|
|
||||||
case LogLevel.Info:
|
|
||||||
return this.info;
|
|
||||||
default:
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum LogLevel {
|
|
||||||
Debug = "debug",
|
|
||||||
Info = "info",
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user