Compare commits

..

5 Commits

Author SHA1 Message Date
Emilien Escalle
b2d60131ea feat: add docker flags input
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-01-30 20:51:18 +01:00
Emilien Escalle
ca5588083a fix: npm security issue 2025-01-30 20:47:23 +01:00
Emilien Escalle
d24334d10a docs; use docker compose wording instead of docker-compose 2025-01-30 20:47:21 +01:00
Emilien Escalle
0807b14987 fix: print docker compose output to debug only
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-01-30 20:45:35 +01:00
Emilien Escalle
765986dd3e
docs: add ref link to debug mode
Some checks are pending
Internal - Main - Continuous Integration / ci (push) Waiting to run
Internal - Main - Continuous Integration / generate-readme (push) Blocked by required conditions
Signed-off-by: Emilien Escalle <neilime@users.noreply.github.com>
2025-01-30 10:04:38 +01:00
12 changed files with 35 additions and 12 deletions

View File

@ -41,7 +41,7 @@ Some extra options can be passed to the `docker compose up` command using the `u
### Post hook
On post hook, the action will run `docker compose down` to clean up the services.
In debug mode, the logs of the running services are printed before the cleanup.
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.
Some extra options can be passed to the `docker compose down` command using the `down-flags` input.

View File

@ -1,5 +1,5 @@
name: "Docker Compose Action"
description: "This action runs your compose file and clean up before action finished"
description: "This action runs your compose file(s) and clean up before action finished"
author: "Hoverkraft"
branding:
icon: anchor

5
dist/index.js generated vendored
View File

@ -33178,6 +33178,7 @@ async function run() {
cwd: inputs.cwd,
upFlags: inputs.upFlags,
services: inputs.services,
debug: loggerService.debug,
});
loggerService.info("docker compose service(s) are up");
}
@ -33313,12 +33314,12 @@ class DockerComposeService {
output: out,
};
}
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => debug(chunk.toString()),
executable: {
executablePath: "docker",
options: dockerFlags,

6
dist/post.js generated vendored
View File

@ -26340,6 +26340,7 @@ async function run() {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
debug: loggerService.debug,
});
if (error) {
loggerService.debug("docker compose error:\n" + error);
@ -26351,6 +26352,7 @@ async function run() {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
downFlags: inputs.downFlags,
debug: loggerService.debug,
});
loggerService.info("docker compose is down");
}
@ -26401,12 +26403,12 @@ class DockerComposeService {
output: out,
};
}
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => debug(chunk.toString()),
executable: {
executablePath: "docker",
options: dockerFlags,

View File

@ -66,6 +66,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: [],
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
@ -96,6 +97,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: ["web"],
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
});

View File

@ -42,6 +42,7 @@ export async function run(): Promise<void> {
cwd: inputs.cwd,
upFlags: inputs.upFlags,
services: inputs.services,
debug: loggerService.debug,
});
loggerService.info("docker compose service(s) are up");
} catch (error) {

View File

@ -61,6 +61,7 @@ describe("index", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();

View File

@ -52,6 +52,7 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -60,6 +61,7 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
@ -100,6 +102,7 @@ describe("run", () => {
cwd: "/current/working/dir",
dockerFlags: [],
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -108,6 +111,7 @@ describe("run", () => {
cwd: "/current/working/dir",
dockerFlags: [],
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");

View File

@ -21,6 +21,7 @@ export async function run(): Promise<void> {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
debug: loggerService.debug,
});
if (error) {
@ -35,6 +36,7 @@ export async function run(): Promise<void> {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
downFlags: inputs.downFlags,
debug: loggerService.debug,
});
loggerService.info("docker compose is down");

View File

@ -48,6 +48,7 @@ describe("post", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -56,6 +57,7 @@ describe("post", () => {
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");

View File

@ -31,6 +31,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -43,8 +44,8 @@ describe("DockerComposeService", () => {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
@ -56,6 +57,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -68,8 +70,8 @@ describe("DockerComposeService", () => {
executablePath: "docker",
options: ["--context", "dev"],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
@ -81,6 +83,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: ["--build"],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -90,11 +93,11 @@ describe("DockerComposeService", () => {
commandOptions: ["--build"],
config: ["docker-compose.yml"],
cwd: "/current/working/dir",
callback: expect.any(Function),
executable: {
executablePath: "docker",
options: [],
},
log: true,
});
});
});
@ -107,6 +110,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
downFlags: ["--volumes", "--remove-orphans"],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.down(downInputs);
@ -119,20 +123,22 @@ describe("DockerComposeService", () => {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
});
describe("logs", () => {
it("should call logs with correct options", async () => {
const debugMock = jest.fn();
const logsInputs: LogsInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["helloworld2", "helloworld3"],
composeFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
};
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
@ -142,13 +148,13 @@ describe("DockerComposeService", () => {
expect(dockerCompose.logs).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
composeOptions: [],
config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir",
executable: {
executablePath: "docker",
options: [],
},
follow: false,
callback: expect.any(Function),
});
});
});

View File

@ -13,6 +13,7 @@ type OptionsInputs = {
composeFiles: Inputs["composeFiles"];
composeFlags: Inputs["composeFlags"];
cwd: Inputs["cwd"];
debug: (message: string) => void;
};
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
@ -65,12 +66,13 @@ export class DockerComposeService {
composeFiles,
composeFlags,
cwd,
debug,
}: OptionsInputs): IDockerComposeOptions {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => debug(chunk.toString()),
executable: {
executablePath: "docker",
options: dockerFlags,