Skip to content

Commit ff8dcd1

Browse files
dvag-gloeckner-danielneilime
authored andcommitted
feat: make service log level configurable
1 parent a035f13 commit ff8dcd1

16 files changed

+221
-136
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ Some extra options can be passed to the `docker compose up` command using the `u
3939
### Post hook
4040

4141
On post hook, the action will run `docker compose down` to clean up the services.
42-
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.
42+
43+
Logs of the Docker Compose services are logged using GitHub `core.ts` API before the cleanup.
44+
The log level can be set using the `services-log-level` input. The default is `debug`, which will
45+
only print logs if [debug mode](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging) is switched on.
4346

4447
Some extra options can be passed to the `docker compose down` command using the `down-flags` input.
4548

@@ -92,6 +95,10 @@ Some extra options can be passed to the `docker compose down` command using the
9295
#
9396
# Default: ${{ github.token }}
9497
github-token: ""
98+
99+
# Description: The log level used for Docker Compose service logs. Can be one of "debug", "info".
100+
# Default: "debug"
101+
services-log-level: "debug"
95102
```
96103
97104
<!-- end usage -->
@@ -100,17 +107,18 @@ Some extra options can be passed to the `docker compose down` command using the
100107
101108
<!-- start inputs -->
102109
103-
| **Input** | **Description** | **Default** | **Required** |
104-
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
105-
| <code>docker-flags</code> | Additional options to pass to <code>docker</code> command. | | **false** |
106-
| <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** |
107-
| <code>services</code> | Services to perform docker compose up. | | **false** |
108-
| <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **false** |
109-
| <code>down-flags</code> | Additional options to pass to <code>docker compose down</code> command. | | **false** |
110-
| <code>compose-flags</code> | Additional options to pass to <code>docker compose</code> command. | | **false** |
111-
| <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** |
112-
| <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** |
113-
| <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** |
110+
| **Input** | **Description** | **Default** | **Required** |
111+
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
112+
| <code>docker-flags</code> | Additional options to pass to <code>docker</code> command. | | **false** |
113+
| <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** |
114+
| <code>services</code> | Services to perform docker compose up. | | **false** |
115+
| <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **false** |
116+
| <code>down-flags</code> | Additional options to pass to <code>docker compose down</code> command. | | **false** |
117+
| <code>compose-flags</code> | Additional options to pass to <code>docker compose</code> command. | | **false** |
118+
| <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** |
119+
| <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** |
120+
| <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** |
121+
| <code>services-log-level</code> | The log level used for Docker Compose service logs. Can be one of "debug", "info". | debug | **false** |
114122
115123
<!-- end inputs -->
116124
<!-- start outputs -->

dist/index.js

Lines changed: 29 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post.js

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"lint": "eslint \"src/**/*.{ts,tsx}\"",
3131
"all": "npm run format && npm run lint && npm run test && npm run package",
3232
"build": "tsc --noEmit",
33-
"format": "prettier --cache --write '**/*.ts'",
33+
"format": "prettier --cache --write .",
3434
"jest": "jest --detectOpenHandles --forceExit",
3535
"test": "npm run jest --maxWorkers=50%",
3636
"test:watch": "npm run jest --watch --maxWorkers=25%",

src/index-runner.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from "@actions/core";
22
import { InputService } from "./services/input.service";
3-
import { LoggerService } from "./services/logger.service";
3+
import { LoggerService, LogLevel } from "./services/logger.service";
44
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
55
import * as indexRunner from "./index-runner";
66
import { DockerComposeService } from "./services/docker-compose.service";
@@ -37,6 +37,7 @@ describe("run", () => {
3737
cwd: "/current/working/dir",
3838
composeVersion: "1.29.2",
3939
githubToken: null,
40+
serviceLogLevel: LogLevel.Debug,
4041
}));
4142

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

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

5657
expect(installMock).toHaveBeenCalledWith({
@@ -66,7 +67,7 @@ describe("run", () => {
6667
cwd: "/current/working/dir",
6768
upFlags: [],
6869
services: [],
69-
debug: debugMock,
70+
serviceLogger: debugMock,
7071
});
7172

7273
expect(setFailedMock).not.toHaveBeenCalled();
@@ -84,6 +85,7 @@ describe("run", () => {
8485
cwd: "/current/working/dir",
8586
composeVersion: null,
8687
githubToken: null,
88+
serviceLogLevel: LogLevel.Debug,
8789
}));
8890

8991
// Act
@@ -97,7 +99,7 @@ describe("run", () => {
9799
cwd: "/current/working/dir",
98100
upFlags: [],
99101
services: ["web"],
100-
debug: debugMock,
102+
serviceLogger: debugMock,
101103
});
102104
expect(setFailedMock).not.toHaveBeenCalled();
103105
});
@@ -117,6 +119,7 @@ describe("run", () => {
117119
cwd: "/current/working/dir",
118120
composeVersion: null,
119121
githubToken: null,
122+
serviceLogLevel: LogLevel.Debug,
120123
}));
121124

122125
// Act
@@ -141,6 +144,7 @@ describe("run", () => {
141144
cwd: "/current/working/dir",
142145
composeVersion: null,
143146
githubToken: null,
147+
serviceLogLevel: LogLevel.Debug,
144148
}));
145149

146150
// Act

src/index-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function run(): Promise<void> {
4242
cwd: inputs.cwd,
4343
upFlags: inputs.upFlags,
4444
services: inputs.services,
45-
debug: loggerService.debug,
45+
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
4646
});
4747
loggerService.info("docker compose service(s) are up");
4848
} catch (error) {

src/index.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from "@actions/core";
22
import { DockerComposeService } from "./services/docker-compose.service";
33
import { InputService } from "./services/input.service";
4-
import { LoggerService } from "./services/logger.service";
4+
import { LoggerService, LogLevel } from "./services/logger.service";
55
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
66

77
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
@@ -34,6 +34,7 @@ describe("index", () => {
3434
cwd: "/current/working/dir",
3535
composeVersion: null,
3636
githubToken: null,
37+
serviceLogLevel: LogLevel.Debug,
3738
}));
3839

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

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

6768
expect(setFailedMock).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)