Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ 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](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.

Expand Down Expand Up @@ -92,6 +95,10 @@ Some extra options can be passed to the `docker compose down` command using the
#
# Default: ${{ 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 -->
Expand All @@ -100,17 +107,18 @@ Some extra options can be passed to the `docker compose down` command using the

<!-- start inputs -->

| **Input** | **Description** | **Default** | **Required** |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
| <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>services</code> | Services to perform docker compose up. | | **false** |
| <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **false** |
| <code>down-flags</code> | Additional options to pass to <code>docker compose down</code> command. | | **false** |
| <code>compose-flags</code> | Additional options to pass to <code>docker compose</code> command. | | **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>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** |
| **Input** | **Description** | **Default** | **Required** |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
| <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>services</code> | Services to perform docker compose up. | | **false** |
| <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **false** |
| <code>down-flags</code> | Additional options to pass to <code>docker compose down</code> command. | | **false** |
| <code>compose-flags</code> | Additional options to pass to <code>docker compose</code> command. | | **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>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 -->
<!-- start outputs -->
Expand Down
33 changes: 29 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions dist/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint": "eslint \"src/**/*.{ts,tsx}\"",
"all": "npm run format && npm run lint && npm run test && npm run package",
"build": "tsc --noEmit",
"format": "prettier --cache --write '**/*.ts'",
"format": "prettier --cache --write .",
"jest": "jest --detectOpenHandles --forceExit",
"test": "npm run jest --maxWorkers=50%",
"test:watch": "npm run jest --watch --maxWorkers=25%",
Expand Down
12 changes: 8 additions & 4 deletions src/index-runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@actions/core";
import { InputService } from "./services/input.service";
import { LoggerService } from "./services/logger.service";
import { LoggerService, LogLevel } from "./services/logger.service";
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
import * as indexRunner from "./index-runner";
import { DockerComposeService } from "./services/docker-compose.service";
Expand Down Expand Up @@ -37,6 +37,7 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: "1.29.2",
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));

installMock.mockResolvedValue("1.29.2");
Expand All @@ -50,7 +51,7 @@ describe("run", () => {
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");

expect(debugMock).toHaveBeenCalledWith(
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null,"serviceLogLevel":"debug"}'
);

expect(installMock).toHaveBeenCalledWith({
Expand All @@ -66,7 +67,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: [],
debug: debugMock,
serviceLogger: debugMock,
});

expect(setFailedMock).not.toHaveBeenCalled();
Expand All @@ -84,6 +85,7 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));

// Act
Expand All @@ -97,7 +99,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: ["web"],
debug: debugMock,
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
});
Expand All @@ -117,6 +119,7 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));

// Act
Expand All @@ -141,6 +144,7 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));

// Act
Expand Down
2 changes: 1 addition & 1 deletion src/index-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function run(): Promise<void> {
cwd: inputs.cwd,
upFlags: inputs.upFlags,
services: inputs.services,
debug: loggerService.debug,
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
});
loggerService.info("docker compose service(s) are up");
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from "@actions/core";
import { DockerComposeService } from "./services/docker-compose.service";
import { InputService } from "./services/input.service";
import { LoggerService } from "./services/logger.service";
import { LoggerService, LogLevel } from "./services/logger.service";
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";

let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
Expand Down Expand Up @@ -34,6 +34,7 @@ describe("index", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));

installMock.mockResolvedValue("1.2.3");
Expand All @@ -49,7 +50,7 @@ describe("index", () => {
// Verify that all of the functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(
1,
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null}'
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}'
);

expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
Expand All @@ -61,7 +62,7 @@ describe("index", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
serviceLogger: debugMock,
});

expect(setFailedMock).not.toHaveBeenCalled();
Expand Down
Loading
Loading