Compare commits

..

2 Commits

Author SHA1 Message Date
dvag-gloeckner-daniel
7098fdc4f5 feat: make service log level configurable
Some checks failed
Internal - Main - Continuous Integration / ci (push) Has been cancelled
Internal - Main - Continuous Integration / release (push) Has been cancelled
Need fix to Issue / main (push) Has been cancelled
Mark stale issues and pull requests / main (push) Has been cancelled
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-06-19 13:03:41 +02:00
Emilien Escalle
a035f13e41 feat: upgrade dependencies
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-06-19 12:01:03 +02:00
19 changed files with 378 additions and 154 deletions

View File

@ -36,7 +36,7 @@
}, },
"features": { "features": {
"ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/prettier:1": {}, "ghcr.io/devcontainers-community/npm-features/prettier:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {} "ghcr.io/devcontainers/features/docker-in-docker:2": {}
} }
} }

View File

@ -1,6 +1,136 @@
<svg xmlns="http://www.w3.org/2000/svg" width="43%" height="43%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color: #ffffff;"> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<title>anchor</title> <!-- Created with Inkscape (http://www.inkscape.org/) -->
<circle cx="12" cy="5" r="3"></circle>
<line x1="12" y1="22" x2="12" y2="8"></line> <svg
<path d="M5 12H2a10 10 0 0 0 20 0h-3"></path> width="202.43709mm"
</svg> height="70.114586mm"
viewBox="0 0 202.43709 70.114586"
version="1.1"
id="svg3661"
xml:space="preserve"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><defs
id="defs3658"><rect
x="275.63507"
y="20.725599"
width="460.92081"
height="83.953773"
id="rect5149" /></defs><g
id="layer1"
transform="translate(-0.56195824,-0.08901982)"><g
style="clip-rule:evenodd;fill-rule:evenodd;image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision"
id="g4730"
transform="matrix(0.26458333,0,0,0.26458333,0.69424991,0.22131149)"><g
id="g4624"><path
style="opacity:1"
fill="#f9fbfd"
d="m -0.5,-0.5 c 86,0 172,0 258,0 0,88.3333 0,176.667 0,265 -86,0 -172,0 -258,0 0,-88.333 0,-176.6667 0,-265 z"
id="path4622" /></g><g
id="g4628"><path
style="opacity:1"
fill="#2671d3"
d="M 220.5,6.5 C 159.335,7.33287 98.0014,7.83287 36.5,8 31.2716,9.28404 26.2716,11.1174 21.5,13.5 26.3598,9.40829 32.0264,6.90829 38.5,6 99.1885,5.18183 159.855,5.34849 220.5,6.5 Z"
id="path4626" /></g><g
id="g4632"><path
style="opacity:1"
fill="#267dd7"
d="m 220.5,6.5 c 14.514,3.6797 24.014,12.6797 28.5,27 0.5,64.3325 0.667,128.666 0.5,193 -0.667,-8.842 -1.333,-17.842 -2,-27 -8.846,-3.282 -17.846,-3.782 -27,-1.5 -10.267,5.938 -20.267,12.272 -30,19 -17.775,11.355 -36.775,14.021 -57,8 1.238,-0.69 1.238,-1.19 0,-1.5 10.103,-5.891 20.103,-12.057 30,-18.5 7.011,-6.508 12.678,-14.008 17,-22.5 1.922,1.211 3.755,2.544 5.5,4 2.882,-6.345 4.049,-13.012 3.5,-20 -0.167,-3.667 -0.333,-7.333 -0.5,-11 -0.583,-1.502 -1.416,-2.835 -2.5,-4 -7.529,5.592 -15.196,10.926 -23,16 3.15,1.318 5.483,3.484 7,6.5 -4.505,11.004 -12.171,18.837 -23,23.5 -4.554,-0.03 -8.054,-2.03 -10.5,-6 -0.5,-14.329 -0.667,-28.663 -0.5,-43 5.949,1.079 11.949,1.246 18,0.5 3.958,-3.908 3.958,-7.741 0,-11.5 -5.238,-1 -11.238,-1.333 -18,-1 -0.165,-3.35 0.002,-6.683 0.5,-10 9.151,-5.924 12.317,-13.924 9.5,-24 -6.659,-12.9421 -16.659,-16.4421 -30,-10.5 -4.009,3.1607 -7.009,6.994 -9,11.5 -0.819,2.805 -1.319,5.805 -1.5,9 -0.333,-0.333 -0.667,-0.667 -1,-1 -0.622,2.231 -1.789,4.065 -3.5,5.5 1.266,0.309 2.433,0.809 3.5,1.5 0.388,-0.928 1.055,-1.595 2,-2 2.669,4.168 6.169,7.501 10.5,10 0.987,3.268 1.32,6.602 1,10 -6.43,-0.333 -12.097,0 -17,1 -3.4778,3.522 -3.8112,7.356 -1,11.5 6.574,0.386 12.908,0.553 19,0.5 -0.831,14.161 -1.331,28.494 -1.5,43 -2.19,3.672 -5.357,5.672 -9.5,6 -11.3755,-5.043 -19.3755,-13.376 -24,-25 1.6768,-2.26 3.8434,-3.927 6.5,-5 0.6172,-0.949 0.4506,-1.782 -0.5,-2.5 -7.4397,-4.442 -14.6064,-9.275 -21.5,-14.5 -1.7684,2.412 -2.9351,5.079 -3.5,8 -1.8405,9.453 -1.0072,18.786 2.5,28 1.159,1.066 1.9924,0.733 2.5,-1 1.0077,-1.839 2.5077,-3.172 4.5,-4 5.1779,9.675 11.6779,18.342 19.5,26 -2.2087,1.099 -4.2087,0.599 -6,-1.5 -10.4817,-3.651 -21.1483,-4.318 -32,-2 -15.9561,6.486 -32.2895,11.653 -49,15.5 -0.16666,-61.334 0,-122.6676 0.5,-184 0.56704,-2.6677 1.06704,-5.3344 1.5,-8 1.7739,-6.7746 5.7739,-11.7746 12,-15 4.7716,-2.3826 9.7716,-4.21596 15,-5.5 61.5014,-0.16713 122.835,-0.66713 184,-1.5 z"
id="path4630" /></g><g
id="g4636"><path
style="opacity:1"
fill="#fafbfd"
d="m 80.5,38.5 c 12.5427,5.2701 24.876,11.1034 37,17.5 1.295,3.7864 1.295,7.6197 0,11.5 -12.298,7.1346 -24.4646,14.4679 -36.5,22 -0.6667,-4.3333 -0.6667,-8.6667 0,-13 C 87.7477,71.8757 94.581,67.3757 101.5,63 94.9375,58.107 88.1042,53.607 81,49.5 80.5014,45.8484 80.3347,42.1817 80.5,38.5 Z"
id="path4634" /></g><g
id="g4640"><path
style="opacity:1"
fill="#fdfdfe"
d="m 140.5,47.5 c 12.333,0 24.667,0 37,0 0,3.3333 0,6.6667 0,10 -12.333,0 -24.667,0 -37,0 0,-3.3333 0,-6.6667 0,-10 z"
id="path4638" /></g><g
id="g4644"><path
style="opacity:1"
fill="#015ccd"
d="m 140.5,63.5 c 12.489,-0.9954 25.156,-1.3287 38,-1 0.317,4.2016 -0.017,8.2016 -1,12 0,-3.6667 0,-7.3333 0,-11 -12.333,0 -24.667,0 -37,0 z"
id="path4642" /></g><g
id="g4648"><path
style="opacity:1"
fill="#f6f9fc"
d="m 140.5,63.5 c 12.333,0 24.667,0 37,0 0,3.6667 0,7.3333 0,11 -12.155,0.9952 -24.489,1.3286 -37,1 0,-4 0,-8 0,-12 z"
id="path4646" /></g><g
id="g4652"><path
style="opacity:1"
fill="#1273d5"
d="m 9.5,28.5 c -0.43296,2.6656 -0.93296,5.3323 -1.5,8 -0.5,61.3324 -0.66666,122.666 -0.5,184 -0.66667,0 -1.33333,0 -2,0 -0.16666,-61.001 0,-122.0009 0.5,-183 0.50531,-3.365 1.67197,-6.365 3.5,-9 z"
id="path4650" /></g><g
id="g4656"><path
style="opacity:1"
fill="#fbfcfd"
d="m 146.5,102.5 c 1.362,9.94 -2.138,17.607 -10.5,23 -0.499,3.986 -0.666,7.986 -0.5,12 6.333,0 12.667,0 19,0 3.958,3.759 3.958,7.592 0,11.5 -6.051,0.746 -12.051,0.579 -18,-0.5 -1.161,14.494 -1.328,29.161 -0.5,44 2.532,4.407 6.365,6.074 11.5,5 10.829,-4.663 18.495,-12.496 23,-23.5 -1.517,-3.016 -3.85,-5.182 -7,-6.5 7.804,-5.074 15.471,-10.408 23,-16 1.084,1.165 1.917,2.498 2.5,4 0.167,3.667 0.333,7.333 0.5,11 0.549,6.988 -0.618,13.655 -3.5,20 -1.745,-1.456 -3.578,-2.789 -5.5,-4 -4.322,8.492 -9.989,15.992 -17,22.5 -9.897,6.443 -19.897,12.609 -30,18.5 -2.124,1.674 -4.458,2.507 -7,2.5 -10.561,-6.112 -21.227,-11.945 -32,-17.5 -7.8221,-7.658 -14.3221,-16.325 -19.5,-26 -1.9923,0.828 -3.4923,2.161 -4.5,4 -1.2498,-0.077 -2.0831,-0.744 -2.5,-2 -2.1781,-8.184 -3.0114,-16.517 -2.5,-25 0.5649,-2.921 1.7316,-5.588 3.5,-8 6.8936,5.225 14.0603,10.058 21.5,14.5 0.9506,0.718 1.1172,1.551 0.5,2.5 -2.6566,1.073 -4.8232,2.74 -6.5,5 4.6245,11.624 12.6245,19.957 24,25 4.78,0.859 8.28,-0.808 10.5,-5 0.5,-14.663 0.667,-29.33 0.5,-44 -6.092,0.053 -12.426,-0.114 -19,-0.5 -2.8112,-4.144 -2.4778,-7.978 1,-11.5 6,0 12,0 18,0 0.324,-4.055 -0.009,-8.055 -1,-12 -8.426,-4.852 -12.093,-12.186 -11,-22 1.991,-4.506 4.991,-8.3393 9,-11.5 13.341,-5.9421 23.341,-2.4421 30,10.5 z"
id="path4654" /></g><g
id="g4660"><path
style="opacity:1"
fill="#2678d5"
d="m 124.5,101.5 c 8.367,0.239 10.7,4.072 7,11.5 -7.112,2.554 -10.612,0.054 -10.5,-7.5 1.376,-1.205 2.542,-2.538 3.5,-4 z"
id="path4658" /></g><g
id="g4664"><path
style="opacity:1"
fill="#1c68d1"
d="m 107.5,103.5 c -1.093,9.814 2.574,17.148 11,22 0.991,3.945 1.324,7.945 1,12 -6,0 -12,0 -18,0 4.903,-1 10.57,-1.333 17,-1 0.32,-3.398 -0.013,-6.732 -1,-10 -4.331,-2.499 -7.831,-5.832 -10.5,-10 -0.945,0.405 -1.612,1.072 -2,2 -1.067,-0.691 -2.234,-1.191 -3.5,-1.5 1.711,-1.435 2.878,-3.269 3.5,-5.5 0.333,0.333 0.667,0.667 1,1 0.181,-3.195 0.681,-6.195 1.5,-9 z"
id="path4662" /></g><g
id="g4668"><path
style="opacity:1"
fill="#0b5bce"
d="m 146.5,102.5 c 2.817,10.076 -0.349,18.076 -9.5,24 -0.498,3.317 -0.665,6.65 -0.5,10 6.762,-0.333 12.762,0 18,1 -6.333,0 -12.667,0 -19,0 -0.166,-4.014 0.001,-8.014 0.5,-12 8.362,-5.393 11.862,-13.06 10.5,-23 z"
id="path4666" /></g><g
id="g4672"><path
style="opacity:1"
fill="#0452ca"
d="m 119.5,149.5 c 0.167,14.67 0,29.337 -0.5,44 -2.22,4.192 -5.72,5.859 -10.5,5 4.143,-0.328 7.31,-2.328 9.5,-6 0.169,-14.506 0.669,-28.839 1.5,-43 z"
id="path4670" /></g><g
id="g4676"><path
style="opacity:1"
fill="#1662cf"
d="m 65.5,159.5 c -0.5114,8.483 0.3219,16.816 2.5,25 0.4169,1.256 1.2502,1.923 2.5,2 -0.5076,1.733 -1.341,2.066 -2.5,1 -3.5072,-9.214 -4.3405,-18.547 -2.5,-28 z"
id="path4674" /></g><g
id="g4680"><path
style="opacity:1"
fill="#0356cd"
d="m 136.5,148.5 c -0.167,14.337 0,28.671 0.5,43 2.446,3.97 5.946,5.97 10.5,6 -5.135,1.074 -8.968,-0.593 -11.5,-5 -0.828,-14.839 -0.661,-29.506 0.5,-44 z"
id="path4678" /></g><g
id="g4684"><path
style="opacity:1"
fill="#256ab8"
d="m 249.5,226.5 c -1.768,13.413 -8.768,22.747 -21,28 -3.627,0.929 -7.293,1.763 -11,2.5 -60,0.667 -120,0.667 -180,0 -12.703,-2.88 -22.0363,-10.047 -28,-21.5 -2.49487,-4.569 -3.82821,-9.569 -4,-15 0.66667,0 1.33333,0 2,0 16.7105,-3.847 33.0439,-9.014 49,-15.5 10.8517,-2.318 21.5183,-1.651 32,2 1.7913,2.099 3.7913,2.599 6,1.5 10.773,5.555 21.439,11.388 32,17.5 2.542,0.007 4.876,-0.826 7,-2.5 1.238,0.31 1.238,0.81 0,1.5 20.225,6.021 39.225,3.355 57,-8 9.733,-6.728 19.733,-13.062 30,-19 9.154,-2.282 18.154,-1.782 27,1.5 0.667,9.158 1.333,18.158 2,27 z"
id="path4682" /></g><g
id="g4688"><path
style="opacity:1"
fill="#265cb3"
d="m 9.5,235.5 c 5.9637,11.453 15.297,18.62 28,21.5 60,0.667 120,0.667 180,0 3.707,-0.737 7.373,-1.571 11,-2.5 -4.256,2.405 -8.923,3.905 -14,4.5 -58,0.667 -116,0.667 -174,0 -14.901,-2.087 -25.2344,-9.92 -31,-23.5 z"
id="path4686" /></g></g><text
xml:space="preserve"
transform="scale(0.26458333)"
id="text5147"
style="font-size:42.6667px;font-family:Inter;-inkscape-font-specification:'Inter, @opsz=32.0,wght=900';font-variation-settings:'opsz' 32, 'wght' 900;white-space:pre;shape-inside:url(#rect5149);fill:#001d20;stroke-width:10.5638;stroke-linecap:round;stroke-linejoin:bevel;paint-order:markers fill stroke" /><text
xml:space="preserve"
style="font-size:28.4729px;font-family:Inter;-inkscape-font-specification:'Inter, @opsz=32.0,wght=900';font-variation-settings:'opsz' 32, 'wght' 900;fill:#001d20;stroke-width:7.04957;stroke-linecap:round;stroke-linejoin:bevel;paint-order:markers fill stroke"
x="73.198349"
y="22.445642"
id="text5155"><tspan
style="stroke-width:7.04953"
x="73.198349"
y="22.445642"
id="tspan5207"
dy="1.1">compose</tspan><tspan
style="stroke-width:7.04953"
x="73.198349"
y="58.036766"
id="tspan5217"
dy="-9.6169167">action</tspan></text><text
xml:space="preserve"
style="font-size:11.2889px;font-family:Inter;-inkscape-font-specification:'Inter, @opsz=32.0,wght=900';font-variation-settings:'opsz' 32, 'wght' 900;fill:#001d20;stroke-width:2.79501;stroke-linecap:round;stroke-linejoin:bevel;paint-order:markers fill stroke"
x="74.858276"
y="62.121162"
id="text5213"><tspan
id="tspan5211"
style="stroke-width:2.795"
x="74.858276"
y="62.121162">By hoverkraft</tspan></text></g></svg>

Before

Width:  |  Height:  |  Size: 382 B

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -39,7 +39,10 @@ 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.
@ -92,6 +95,10 @@ 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 -->
@ -100,17 +107,18 @@ 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** |
| <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **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>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>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>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
View File

@ -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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
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, debug, }) { getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, serviceLogger, }) {
return { return {
config: composeFiles, config: composeFiles,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
callback: (chunk) => debug(chunk.toString()), callback: (chunk) => serviceLogger(chunk.toString()),
executable: { executable: {
executablePath: "docker", executablePath: "docker",
options: dockerFlags, options: dockerFlags,
@ -33225,6 +33225,7 @@ 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";
@ -33236,6 +33237,7 @@ 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 {
@ -33250,6 +33252,7 @@ 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() {
@ -33305,6 +33308,13 @@ 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;
@ -33377,7 +33387,7 @@ exports.ManualInstallerAdapter = ManualInstallerAdapter;
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.LoggerService = void 0; exports.LogLevel = exports.LoggerService = void 0;
const core_1 = __nccwpck_require__(7484); const core_1 = __nccwpck_require__(7484);
class LoggerService { class LoggerService {
warn(message) { warn(message) {
@ -33389,8 +33399,23 @@ 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
View File

@ -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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
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, debug, }) { getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, serviceLogger, }) {
return { return {
config: composeFiles, config: composeFiles,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
callback: (chunk) => debug(chunk.toString()), callback: (chunk) => serviceLogger(chunk.toString()),
executable: { executable: {
executablePath: "docker", executablePath: "docker",
options: dockerFlags, options: dockerFlags,
@ -26302,6 +26302,7 @@ 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";
@ -26313,6 +26314,7 @@ 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 {
@ -26327,6 +26329,7 @@ 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() {
@ -26382,6 +26385,13 @@ 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;
@ -26394,7 +26404,7 @@ exports.InputService = InputService;
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.LoggerService = void 0; exports.LogLevel = exports.LoggerService = void 0;
const core_1 = __nccwpck_require__(7484); const core_1 = __nccwpck_require__(7484);
class LoggerService { class LoggerService {
warn(message) { warn(message) {
@ -26406,8 +26416,23 @@ 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 = {}));
/***/ }), /***/ }),

14
package-lock.json generated
View File

@ -10,16 +10,16 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.1",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^2.0.2",
"@octokit/action": "^8.0.1", "@octokit/action": "^8.0.2",
"docker-compose": "^1.2.0" "docker-compose": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"@ts-dev-tools/core": "^1.6.2", "@ts-dev-tools/core": "^1.6.2",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint-plugin-github": "^6.0.0", "eslint-plugin-github": "^6.0.0",
"eslint-plugin-jsonc": "^2.20.0" "eslint-plugin-jsonc": "^2.20.1"
}, },
"engines": { "engines": {
"node": ">=20" "node": ">=20"
@ -4664,9 +4664,9 @@
} }
}, },
"node_modules/eslint-plugin-jsonc": { "node_modules/eslint-plugin-jsonc": {
"version": "2.20.0", "version": "2.20.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.20.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.20.1.tgz",
"integrity": "sha512-FRgCn9Hzk5eKboCbVMrr9QrhM0eO4G+WKH8IFXoaeqhM/2kuWzbStJn4kkr0VWL8J5H8RYZF+Aoam1vlBaZVkw==", "integrity": "sha512-gUzIwQHXx7ZPypUoadcyRi4WbHW2TPixDr0kqQ4miuJBU0emJmyGTlnaT3Og9X2a8R1CDayN9BFSq5weGWbTng==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -4677,7 +4677,7 @@
"graphemer": "^1.4.0", "graphemer": "^1.4.0",
"jsonc-eslint-parser": "^2.4.0", "jsonc-eslint-parser": "^2.4.0",
"natural-compare": "^1.4.0", "natural-compare": "^1.4.0",
"synckit": "^0.6.2 || ^0.7.3 || ^0.10.3" "synckit": "^0.6.2 || ^0.7.3 || ^0.11.5"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"

View File

@ -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 '**/*.ts'", "format": "prettier --cache --write .",
"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%",
@ -73,16 +73,16 @@
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.1",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^2.0.2",
"@octokit/action": "^8.0.1", "@octokit/action": "^8.0.2",
"docker-compose": "^1.2.0" "docker-compose": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"@ts-dev-tools/core": "^1.6.2", "@ts-dev-tools/core": "^1.6.2",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.38.3",
"eslint-plugin-github": "^6.0.0", "eslint-plugin-github": "^6.0.0",
"eslint-plugin-jsonc": "^2.20.0" "eslint-plugin-jsonc": "^2.20.1"
}, },
"eslintConfig": { "eslintConfig": {
"root": true, "root": true,

View File

@ -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 } from "./services/logger.service"; import { LoggerService, LogLevel } 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,6 +37,7 @@ 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");
@ -50,7 +51,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}' '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({ expect(installMock).toHaveBeenCalledWith({
@ -66,7 +67,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
upFlags: [], upFlags: [],
services: [], services: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(setFailedMock).not.toHaveBeenCalled(); expect(setFailedMock).not.toHaveBeenCalled();
@ -84,6 +85,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
composeVersion: null, composeVersion: null,
githubToken: null, githubToken: null,
serviceLogLevel: LogLevel.Debug,
})); }));
// Act // Act
@ -97,7 +99,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
upFlags: [], upFlags: [],
services: ["web"], services: ["web"],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(setFailedMock).not.toHaveBeenCalled(); expect(setFailedMock).not.toHaveBeenCalled();
}); });
@ -117,6 +119,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
composeVersion: null, composeVersion: null,
githubToken: null, githubToken: null,
serviceLogLevel: LogLevel.Debug,
})); }));
// Act // Act
@ -141,6 +144,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
composeVersion: null, composeVersion: null,
githubToken: null, githubToken: null,
serviceLogLevel: LogLevel.Debug,
})); }));
// Act // Act

View File

@ -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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
loggerService.info("docker compose service(s) are up"); loggerService.info("docker compose service(s) are up");
} catch (error) { } catch (error) {

View File

@ -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 } from "./services/logger.service"; import { LoggerService, LogLevel } 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,6 +34,7 @@ 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");
@ -49,7 +50,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}' '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)"); expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
@ -61,7 +62,7 @@ describe("index", () => {
composeFlags: [], composeFlags: [],
upFlags: [], upFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: debugMock, serviceLogger: debugMock,
}); });
expect(setFailedMock).not.toHaveBeenCalled(); expect(setFailedMock).not.toHaveBeenCalled();

View File

@ -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 } from "./services/logger.service"; import { LoggerService, LogLevel } 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,6 +36,7 @@ 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" });
@ -52,7 +53,7 @@ describe("run", () => {
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
services: [], services: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(downMock).toHaveBeenCalledWith({ expect(downMock).toHaveBeenCalledWith({
@ -61,7 +62,7 @@ describe("run", () => {
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
downFlags: [], downFlags: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs"); expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
@ -83,6 +84,7 @@ 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({
@ -102,7 +104,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
dockerFlags: [], dockerFlags: [],
services: [], services: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(downMock).toHaveBeenCalledWith({ expect(downMock).toHaveBeenCalledWith({
@ -111,7 +113,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
dockerFlags: [], dockerFlags: [],
downFlags: [], downFlags: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error"); expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
@ -148,6 +150,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
composeVersion: null, composeVersion: null,
githubToken: null, githubToken: null,
serviceLogLevel: LogLevel.Debug,
})); }));
// Act // Act
@ -172,6 +175,7 @@ describe("run", () => {
cwd: "/current/working/dir", cwd: "/current/working/dir",
composeVersion: null, composeVersion: null,
githubToken: null, githubToken: null,
serviceLogLevel: LogLevel.Debug,
})); }));
// Act // Act

View File

@ -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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
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,
debug: loggerService.debug, serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
}); });
loggerService.info("docker compose is down"); loggerService.info("docker compose is down");

View File

@ -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 } from "./services/logger.service"; import { LoggerService, LogLevel } 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,6 +33,7 @@ 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" });
@ -48,7 +49,7 @@ describe("post", () => {
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
services: [], services: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(downMock).toHaveBeenCalledWith({ expect(downMock).toHaveBeenCalledWith({
@ -57,7 +58,7 @@ describe("post", () => {
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
downFlags: [], downFlags: [],
debug: debugMock, serviceLogger: debugMock,
}); });
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs"); expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");

View File

@ -31,7 +31,7 @@ describe("DockerComposeService", () => {
composeFlags: [], composeFlags: [],
upFlags: [], upFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: jest.fn(), serviceLogger: jest.fn(),
}; };
await service.up(upInputs); await service.up(upInputs);
@ -47,6 +47,15 @@ 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 () => {
@ -57,7 +66,7 @@ describe("DockerComposeService", () => {
composeFlags: [], composeFlags: [],
upFlags: [], upFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: jest.fn(), serviceLogger: jest.fn(),
}; };
await service.up(upInputs); await service.up(upInputs);
@ -83,7 +92,7 @@ describe("DockerComposeService", () => {
composeFlags: [], composeFlags: [],
upFlags: ["--build"], upFlags: ["--build"],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: jest.fn(), serviceLogger: jest.fn(),
}; };
await service.up(upInputs); await service.up(upInputs);
@ -110,7 +119,7 @@ describe("DockerComposeService", () => {
composeFlags: [], composeFlags: [],
downFlags: ["--volumes", "--remove-orphans"], downFlags: ["--volumes", "--remove-orphans"],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: jest.fn(), serviceLogger: jest.fn(),
}; };
await service.down(downInputs); await service.down(downInputs);
@ -138,7 +147,7 @@ describe("DockerComposeService", () => {
services: ["helloworld2", "helloworld3"], services: ["helloworld2", "helloworld3"],
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
debug: debugMock, serviceLogger: debugMock,
}; };
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" }); logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });

View File

@ -13,7 +13,7 @@ type OptionsInputs = {
composeFiles: Inputs["composeFiles"]; composeFiles: Inputs["composeFiles"];
composeFlags: Inputs["composeFlags"]; composeFlags: Inputs["composeFlags"];
cwd: Inputs["cwd"]; cwd: Inputs["cwd"];
debug: (message: string) => void; serviceLogger: (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,
debug, serviceLogger,
}: OptionsInputs): IDockerComposeOptions { }: OptionsInputs): IDockerComposeOptions {
return { return {
config: composeFiles, config: composeFiles,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
callback: (chunk) => debug(chunk.toString()), callback: (chunk) => serviceLogger(chunk.toString()),
executable: { executable: {
executablePath: "docker", executablePath: "docker",
options: dockerFlags, options: dockerFlags,

View File

@ -1,6 +1,7 @@
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;
@ -15,6 +16,15 @@ 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();
}); });
@ -25,15 +35,6 @@ 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:
@ -51,15 +52,6 @@ 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);
@ -149,15 +141,6 @@ 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:
@ -175,15 +158,6 @@ 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);
@ -196,15 +170,6 @@ 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:
@ -222,15 +187,6 @@ 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);
@ -243,15 +199,6 @@ 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:
@ -269,15 +216,6 @@ 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);
@ -289,14 +227,6 @@ 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:
@ -315,14 +245,6 @@ 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:
@ -338,5 +260,53 @@ 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'
);
});
});
}); });
}); });

View File

@ -1,6 +1,7 @@
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[];
@ -12,6 +13,7 @@ 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 {
@ -24,6 +26,7 @@ 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";
@ -40,6 +43,7 @@ export class InputService {
cwd: this.getCwd(), cwd: this.getCwd(),
composeVersion: this.getComposeVersion(), composeVersion: this.getComposeVersion(),
githubToken: this.getGithubToken(), githubToken: this.getGithubToken(),
serviceLogLevel: this.getServiceLogLevel(),
}; };
} }
@ -115,4 +119,14 @@ 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;
}
} }

View File

@ -1,4 +1,4 @@
import { LoggerService } from "./logger.service"; import { LoggerService, LogLevel } 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,4 +43,21 @@ 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);
});
});
}); });

View File

@ -12,4 +12,20 @@ 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",
} }