Compare commits

..

No commits in common. "main" and "v2.1.0" have entirely different histories.
main ... v2.1.0

53 changed files with 6470 additions and 37098 deletions

View File

@ -1,29 +1,41 @@
{
"name": "Debian",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
"name": "GitHub Actions (TypeScript)",
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
"postCreateCommand": "npm install",
"customizations": {
"codespaces": {
"openFiles": ["README.md"]
},
"vscode": {
"extensions": [
"bierner.markdown-preview-github-styles",
"davidanson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"github.copilot",
"github.copilot-chat",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"me-dutour-mathieu.vscode-github-actions",
"redhat.vscode-yaml",
"rvest.vs-code-prettier-eslint",
"yzhang.markdown-all-in-one"
],
"settings": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"markdown.extension.list.indentationSize": "adaptive",
"markdown.extension.italic.indicator": "_",
"markdown.extension.orderedList.marker": "one"
}
}
},
"remoteEnv": {
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
},
"customizations": {
"vscode": {
"extensions": [
"eamodio.gitlens",
"github.copilot",
"github.copilot-chat",
"github.vscode-github-actions",
"ms-vscode.makefile-tools",
"bierner.markdown-preview-github-styles",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh"
}
}
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/prettier:1": {}
}
}

17
.ghadocs.json Normal file
View File

@ -0,0 +1,17 @@
{
"paths": {
"action": "action.yml",
"readme": "README.md"
},
"show_logo": true,
"versioning": {
"enabled": true,
"override": "",
"prefix": "v",
"branch": "main"
},
"owner": "hoverkraft-tech",
"repo": "compose-action",
"title_prefix": "GitHub Action: ",
"prettier": true
}

View File

@ -26,37 +26,17 @@ updates:
patterns:
- "*"
- package-ecosystem: docker-compose
directory: "/test"
open-pull-requests-limit: 20
schedule:
interval: weekly
day: friday
time: "04:00"
groups:
docker-compose-dependencies:
patterns:
- "*"
- package-ecosystem: npm
directory: "/"
open-pull-requests-limit: 20
versioning-strategy: increase
versioning-strategy: widen
schedule:
interval: weekly
day: friday
time: "04:00"
groups:
npm-dev-dependencies:
dependency-type: development
actions-dependencies:
patterns:
- "@actions/*"
- package-ecosystem: "devcontainers"
open-pull-requests-limit: 20
directory: "/"
schedule:
interval: weekly
day: friday
time: "04:00"
npm-dev-dependencies:
dependency-type: development

6
.github/ghadocs/branding.svg vendored Normal file
View File

@ -0,0 +1,6 @@
<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;">
<title>anchor</title>
<circle cx="12" cy="5" r="3"></circle>
<line x1="12" y1="22" x2="12" y2="8"></line>
<path d="M5 12H2a10 10 0 0 0 20 0h-3"></path>
</svg>

After

Width:  |  Height:  |  Size: 382 B

View File

@ -0,0 +1,12 @@
<!-- markdownlint-disable-next-line first-line-heading -->
### Example Using environment variables
```yaml
steps:
- uses: actions/checkout@v4
- uses: hoverkraft-tech/compose-action@v1.5.1
with:
compose-file: "./docker/docker-compose.yml"
env:
CUSTOM_VARIABLE: "test"
```

16
.github/ghadocs/examples/2_services.md vendored Normal file
View File

@ -0,0 +1,16 @@
<!-- markdownlint-disable-next-line first-line-heading -->
### Example using `services`
Perform `docker-compose up` to some given service instead of all of them
```yaml
steps:
# need checkout before using compose-action
- uses: actions/checkout@v3
- uses: hoverkraft-tech/compose-action@v1.5.1
with:
compose-file: "./docker/docker-compose.yml"
services: |
helloworld2
helloworld3
```

View File

@ -0,0 +1,7 @@
<!-- markdownlint-disable-next-line first-line-heading -->
### Example using `up-flags`
Specify flags to pass to the `docker-compose up`. Default is none. Can be used
to pass the `--build` flag, for example, if you want persistent volumes to be
deleted as well during cleanup. A full list of flags can be found in the
[docker-compose up documentation](https://docs.docker.com/compose/reference/up/).

View File

@ -0,0 +1,8 @@
<!-- markdownlint-disable-next-line first-line-heading -->
### Example using `down-flags`
Specify flags to pass to the `docker-compose down` command during cleanup.
Default is none. Can be used to pass the `--volumes` flag, for example, if you
want persistent volumes to be deleted as well during cleanup. A full list of
flags can be found in the
[docker-compose down documentation](https://docs.docker.com/compose/reference/down/).

View File

@ -0,0 +1,18 @@
<!-- markdownlint-disable-next-line first-line-heading -->
### Example using `compose-flags`
Specify flags to pass to the `docker-compose` command. Default is none. A full
list of flags can be found in the
[docker-compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help).
```yaml
steps:
# need checkout before using compose-action
- uses: actions/checkout@v3
- uses: hoverkraft-tech/compose-action@v1.5.1
with:
compose-file: "./docker/docker-compose.yml"
services: |
helloworld2
helloworld3
```

View File

@ -1,3 +0,0 @@
{
"ignore": ["**/dist/**", "**/node_modules/**", "**/coverage/**"]
}

67
.github/logo.svg vendored

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -1,30 +0,0 @@
---
template: |
# What's Changed
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION
name-template: "Version $RESOLVED_VERSION"
tag-template: "$RESOLVED_VERSION"
tag-prefix: ""
prerelease-identifier: "rc"
version-resolver:
major:
labels:
- "release-major"
minor:
labels:
- "release-minor"
patch:
labels:
- "release-patch"
default: patch
autolabeler:
- label: "release-major"
title:
- "/^BREAKING CHANGE:/"
- "/^\\w+!:/"
- "/^\\w+\\(.+\\)!:/"
- label: "release-minor"
title:
- "/^feat:/"
- "/^feat\\(.+\\):/"

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -3,205 +3,190 @@ name: Internal - Tests for action
on:
workflow_call:
permissions: {}
permissions:
contents: read
jobs:
test-action:
test-action-with-services:
runs-on: ubuntu-latest
name: ${{ matrix.name }} - ${{ matrix.assertion-name }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- name: Given multiple services when filtering services
assertion-name: "Then only expected services run"
compose-file: ./test/docker-compose.yml
services: |
service-b
service-c
assertion: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
- name: Given compose file when applying down flags
assertion-name: "Then teardown honors down flags"
compose-file: ./test/docker-compose.yml
down-flags: "--volumes"
assertion: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 || (echo "Service service-a is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 && echo "Service service-b should not be running without profile" && exit 1) || true
(docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 && echo "Service service-c should not be running without profile" && exit 1) || true
- name: Given compose profile when passing compose flags
assertion-name: "Then the requested profile is active"
compose-file: ./test/docker-compose.yml
compose-flags: "--profile profile-1"
down-flags: "--volumes"
assertion: |
docker compose -f ./test/docker-compose.yml -p profile-1 ps || (echo "Profile not used" && exit 1)
- name: Given image supplied via env when running action
assertion-name: "Then compose uses the provided env"
compose-file: ./test/docker-compose-with-env.yml
image-name: busybox
assertion: |
docker compose -f ./test/docker-compose-with-env.yml ps
docker compose -f ./test/docker-compose-with-env.yml ps | grep test-service-a-1 || (echo "Service service-a is not running" && exit 1)
- name: Given multiple compose files when selecting services
assertion-name: "Then only services from selection run"
compose-file: |
./test/docker-compose.yml
./test/docker-compose.ci.yml
services: |
service-b
service-d
assertion: |
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-d-1 || (echo "Service service-d is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
(docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-c-1 && echo "Unexpected service service-c is running" && exit 1) || true
- name: Given compose file in subdirectory when setting cwd
assertion-name: "Then only expected services run"
compose-file: docker-compose.yml
cwd: ./test
services: |
service-b
service-c
assertion: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
- name: Given absolute compose path when running action
assertion-name: "Then only expected services run"
compose-file: test/docker-compose.yml
use-absolute-path: true
services: |
service-b
service-c
assertion: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
- name: Given compose with multiple services when using abort-on-container-exit
assertion-name: "Then execution stops on container exit"
compose-file: test/docker-compose-web-mysql.yml
up-flags: "--build --abort-on-container-exit --exit-code-from=web"
assertion: |
WEB_EXIT_CODE=$(docker compose -f ./test/docker-compose-web-mysql.yml ps web --all --format json | jq ".ExitCode")
[ "$WEB_EXIT_CODE" == "0" ] || (echo "Web service did not exit successfully" && exit 1)
MYSQL_STATE=$(docker compose -f ./test/docker-compose-web-mysql.yml ps mysql --all --format json | jq -r ".State")
if [ "$MYSQL_STATE" = "running" ]; then
echo "MySQL service is still running"
exit 1
fi
- name: Given failing dependency when attaching dependencies
assertion-name: "Then failing service exits with code 1"
compose-file: test/docker-compose-fail.yml
up-flags: "--attach-dependencies"
assertion: |
EXIT_CODE=$(docker compose -f ./test/docker-compose-fail.yml ps service-a --all --format json | jq ".ExitCode")
[ "$EXIT_CODE" == "1" ] || (echo "Service service-a did not exit with code 1" && exit 1)
- name: Given compose version mismatch when requesting explicit version
assertion-name: "Then docker compose reports the requested version"
compose-file: ./test/docker-compose.yml
compose-version: "2.29.0"
expected-compose-version: "2.29.0"
ensure-version-mismatch: true
assertion: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1
fi
- name: Given compose version mismatch when requesting latest version
assertion-name: "Then docker compose reports the requested version"
compose-file: ./test/docker-compose.yml
compose-version: latest
fetch-latest-compose: true
ensure-version-mismatch: true
assertion: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1
fi
- name: Given custom docker context when providing docker flags
assertion-name: "Then docker compose uses that context"
compose-file: ./test/docker-compose.yml
compose-version: latest
docker-flags: "--context test-context"
docker-context: test-context
assertion: |
CURRENT_CONTEXT=$(docker context show)
if [ "$CURRENT_CONTEXT" != "test-context" ]; then
echo "Docker context is '$CURRENT_CONTEXT' instead of 'test-context'"
exit 1
fi
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 || (echo "Service service-a is not running under custom context" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 && echo "Service service-b should not be running without profile" && exit 1) || true
env:
DOCKER_COMPOSE_VERSION: ${{ matrix.expected-compose-version || '' }}
name: Test with services
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
persist-credentials: false
compose-file: "./test/docker-compose.yml"
services: |
service-b
service-c
- name: Set up Docker context
if: ${{ matrix.docker-context }}
uses: docker/setup-docker-action@e43656e248c0bd0647d3f5c195d116aacf6fcaf4 # v4.7.0
- name: "Assert: only expected services are running"
run: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
test-action-with-down-flags:
runs-on: ubuntu-latest
name: Test compose action
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
context: ${{ matrix.docker-context }}
compose-file: "./test/docker-compose.yml"
down-flags: "--volumes"
- name: Resolve absolute compose path
if: ${{ matrix.use-absolute-path }}
id: compose-path
run: echo "absolute=${GITHUB_WORKSPACE}/${{ matrix.compose-file }}" >> "$GITHUB_OUTPUT"
test-action-with-compose-flags:
runs-on: ubuntu-latest
name: Test with compose flags
steps:
- uses: actions/checkout@v4
- name: "Arrange: retrieve latest version of docker compose"
if: ${{ matrix.fetch-latest-compose }}
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
- name: Act
uses: ./
with:
script: |
const dockerComposeVersion = (await github.rest.repos.getLatestRelease({
owner: "docker",
repo: "compose",
})).data.tag_name.replace("v", "");
compose-file: "./test/docker-compose.yml"
compose-flags: "--profile profile-1"
down-flags: "--volumes"
core.exportVariable('DOCKER_COMPOSE_VERSION', dockerComposeVersion);
- name: "Assert: profile is used"
run: |
docker compose -f ./test/docker-compose.yml -p profile-1 ps || (echo "Profile not used" && exit 1)
test-action-with-env:
runs-on: ubuntu-latest
name: Test with env
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: "./test/docker-compose-with-env.yml"
env:
IMAGE_NAME: busybox
- name: "Assert: env is used"
env:
IMAGE_NAME: busybox
run: |
docker compose -f ./test/docker-compose-with-env.yml ps
docker compose -f ./test/docker-compose-with-env.yml ps | grep test-service-a-1 || (echo "Service service-a is not running" && exit 1)
test-action-with-multiple-compose-files:
runs-on: ubuntu-latest
name: Test with multiple compose files
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: |
./test/docker-compose.yml
./test/docker-compose.ci.yml
services: |
service-b
service-d
- name: "Assert: only expected services are running"
run: |
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-d-1 || (echo "Service service-d is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
(docker compose -f ./test/docker-compose.yml -f ./test/docker-compose.ci.yml ps | grep test-service-c-1 && echo "Unexpected service service-c is running" && exit 1) || true
test-action-with-cwd:
runs-on: ubuntu-latest
name: Test with cwd
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: "docker-compose.yml"
cwd: "./test"
services: |
service-b
service-c
- name: "Assert: only expected services are running"
run: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
test-action-with-absolute-path:
runs-on: ubuntu-latest
name: Test with absolute path
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: "${{ github.workspace }}/test/docker-compose.yml"
services: |
service-b
service-c
- name: "Assert: only expected services are running"
run: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-b-1 || (echo "Service service-b is not running" && exit 1)
docker compose -f ./test/docker-compose.yml ps | grep test-service-c-1 || (echo "Service service-c is not running" && exit 1)
(docker compose -f ./test/docker-compose.yml ps | grep test-service-a-1 && echo "Unexpected service service-a is running" && exit 1) || true
test-abort-on-container-exit:
runs-on: ubuntu-latest
name: Test with --abort-on-container-exit
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: "test/docker-compose-web-mysql.yml"
up-flags: "--build --abort-on-container-exit --exit-code-from=web"
test-attach-dependencies-failure:
runs-on: ubuntu-latest
name: Test with --attach-dependencies and service failure
steps:
- uses: actions/checkout@v4
- name: Act
uses: ./
with:
compose-file: "test/docker-compose-fail.yml"
up-flags: "--attach-dependencies"
- name: Assert
run: |
EXIT_CODE=$(docker compose -f ./test/docker-compose-fail.yml ps service-a --all --format json | jq ".ExitCode")
[ "$EXIT_CODE" == "1" ] || (echo "Service service-a did not exit with code 1" && exit 1)
test-action-with-compose-version:
runs-on: ubuntu-latest
name: Test with compose version
env:
DOCKER_COMPOSE_VERSION: "2.29.0"
steps:
- uses: actions/checkout@v4
- name: "Arrange: ensure original docker compose version is not the expected one"
if: ${{ matrix.ensure-version-mismatch }}
run: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
@ -214,19 +199,58 @@ jobs:
- name: Act
uses: ./
with:
compose-file: ${{ matrix.use-absolute-path && steps.compose-path.outputs.absolute || matrix.compose-file }}
services: ${{ matrix.services || '' }}
down-flags: ${{ matrix.down-flags || '' }}
compose-flags: ${{ matrix.compose-flags || '' }}
compose-version: ${{ matrix.compose-version || '' }}
cwd: ${{ matrix.cwd || '' }}
up-flags: ${{ matrix.up-flags || '' }}
docker-flags: ${{ matrix.docker-flags || '' }}
env:
IMAGE_NAME: ${{ matrix.image-name || '' }}
compose-file: "./test/docker-compose.yml"
compose-version: "2.29.0"
- name: ${{ matrix.assertion-name }}
if: ${{ matrix.assertion }}
run: ${{ matrix.assertion }}
env:
IMAGE_NAME: ${{ matrix.image-name || '' }}
- name: "Assert: compose version is used"
run: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1
fi
test-action-with-compose-version-latest:
runs-on: ubuntu-latest
name: Test with compose version latest
steps:
- uses: actions/checkout@v4
- name: "Arrange: retrieve latest version of docker compose"
uses: actions/github-script@v7
with:
script: |
const dockerComposeVersion = (await github.rest.repos.getLatestRelease({
owner: "docker",
repo: "compose",
})).data.tag_name.replace("v", "");
core.exportVariable('DOCKER_COMPOSE_VERSION', dockerComposeVersion);
- name: "Arrange: ensure original docker compose version is not the expected one"
run: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" == "$DOCKER_COMPOSE_VERSION" ]; then
echo "Docker compose version is already in $DOCKER_COMPOSE_VERSION version"
exit 1
fi
- name: Act
uses: ./
with:
compose-file: "./test/docker-compose.yml"
compose-version: "latest"
- name: "Assert: compose version is used"
run: |
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1
fi

View File

@ -3,25 +3,20 @@ name: Internal - Checks for dist
on:
workflow_call:
permissions: {}
permissions:
contents: read
jobs:
check-dist:
name: Check dist
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- id: setup-node
uses: hoverkraft-tech/ci-github-nodejs/actions/setup-node@c9d9d041ba4ef35695ee469c4782fa6a8bbebbcc # 0.21.2
- uses: actions/checkout@v4
- uses: hoverkraft-tech/ci-github-nodejs/actions/setup-node@0.7.0
- name: Build dist/ Directory
id: package
run: ${{ steps.setup-node.outputs.run-script-command }} package
run: npm run package
# This will fail the workflow if the PR wasn't created by Dependabot.
- name: Compare Directories
@ -32,3 +27,13 @@ jobs:
git diff --ignore-space-at-eol --text dist/
exit 1
fi
# If `dist/` was different than expected, and this was not a Dependabot
# PR, upload the expected version as a workflow artifact.
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
name: Upload Artifact
id: upload
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

View File

@ -3,18 +3,17 @@ name: Internal - Checks for nodejs
on:
workflow_call:
permissions: {}
permissions:
contents: read
security-events: write
id-token: write
jobs:
test-nodejs:
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@c9d9d041ba4ef35695ee469c4782fa6a8bbebbcc # 0.21.2
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@0.7.0
permissions:
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write
contents: read
with:
build: ""
test: |
{"coverage":"codecov"}

View File

@ -3,16 +3,16 @@ name: Common Continuous Integration tasks
on:
workflow_call:
permissions: {}
permissions:
contents: read
packages: read
statuses: write
security-events: write
id-token: write
jobs:
linter:
uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
permissions:
actions: read
contents: read
security-events: write
statuses: write
uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@0.16.0
with:
linter-env: |
FILTER_REGEX_EXCLUDE=dist/**/*
@ -27,24 +27,14 @@ jobs:
name: Test nodejs
needs: linter
uses: ./.github/workflows/__check-nodejs.yml
permissions:
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write
secrets: inherit
check-dist:
name: Test nodejs
needs: linter
uses: ./.github/workflows/__check-dist.yml
permissions:
contents: read
check-action:
name: Test action
needs: [check-nodejs, check-dist]
uses: ./.github/workflows/__check-action.yml
permissions:
contents: read

View File

@ -6,12 +6,11 @@ on:
pull_request_target:
branches: [main]
permissions: {}
permissions:
contents: read
issues: write
pull-requests: write
jobs:
greetings:
uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
permissions:
contents: read
issues: write
pull-requests: write
uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@0.16.0

View File

@ -5,64 +5,39 @@ on:
branches: [main]
tags: ["*"]
workflow_dispatch:
schedule:
- cron: "25 8 * * 1"
permissions:
contents: read
packages: read
statuses: write
security-events: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
ci:
uses: ./.github/workflows/__shared-ci.yml
permissions:
actions: read
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write
statuses: write
secrets: inherit
prepare-docs:
generate-readme:
needs: ci
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }}
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- uses: actions/checkout@v4
- uses: bitflight-devops/github-action-readme-generator@v1.8.0
with:
persist-credentials: false
owner: hoverkraft-tech
repo: compose-action
- name: 📖 Generate documentation
id: generate-documentation
uses: hoverkraft-tech/ci-dokumentor@c46a1a108957237cf485103a80b060c35c7dba33 # 0.2.2
with:
source: action.yml
extra-badges: |
[
{
"label":"codecov",
"url":"https://codecov.io/gh/hoverkraft-tech/compose-action/graph/badge.svg?token=90JXB7EIMA",
"linkUrl":"https://codecov.io/gh/hoverkraft-tech/compose-action"
}
]
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
- uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ vars.CI_BOT_APP_ID }}
private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}
- uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
- uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@0.16.0
with:
github-token: ${{ steps.generate-token.outputs.token }}
branch: docs/actions-workflows-documentation-update
@ -72,23 +47,3 @@ jobs:
docs: update actions and workflows documentation
[skip ci]
- id: upload-artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: documentation-files-${{ github.run_id }}
path: |
${{ steps.generate-documentation.outputs.destination }}
.github/logo.svg
sync-docs:
needs: prepare-docs
if: needs.prepare-docs.outputs.artifact-id
uses: hoverkraft-tech/public-docs/.github/workflows/sync-docs-dispatcher.yml@c40c17f7d6a8090950b3ef4bfc70502707a6bb9f # 0.3.0
permissions:
contents: read
with:
artifact-id: ${{ needs.prepare-docs.outputs.artifact-id }}
github-app-id: ${{ vars.CI_BOT_APP_ID }}
secrets:
github-app-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}

View File

@ -15,14 +15,13 @@ on:
before it; to go back further, enter an earlier SHA here"
required: false
permissions: {}
permissions:
contents: read
issues: write
jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
permissions:
contents: read
issues: write
uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@0.16.0
with:
manual-commit-ref: ${{ inputs.manual-commit-ref }}
manual-base-ref: ${{ inputs.manual-base-ref }}

View File

@ -1,26 +0,0 @@
---
name: "Prepare release"
on:
push:
branches: [main]
pull_request:
types: [opened, reopened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
release:
uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@84e8ace407055e7a40ba6670a8c697e1ce2dfafa # 0.20.1
permissions:
contents: write
id-token: write
pull-requests: write
with:
github-app-id: ${{ vars.CI_BOT_APP_ID }}
secrets:
github-app-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }}

View File

@ -5,7 +5,12 @@ on:
pull_request:
branches: [main]
permissions: {}
permissions:
contents: read
packages: read
statuses: write
security-events: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
@ -14,12 +19,4 @@ concurrency:
jobs:
ci:
uses: ./.github/workflows/__shared-ci.yml
permissions:
actions: read
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write
statuses: write
secrets: inherit

View File

@ -1,30 +0,0 @@
name: Release new action version
on:
release:
types: [released]
workflow_dispatch:
inputs:
#checkov:skip=CKV_GHA_7: required
TAG_NAME:
description: "Tag name that the major tag will point to"
required: true
env:
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
permissions: {}
jobs:
update_tag:
name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes
runs-on: ubuntu-latest
permissions:
contents: write
environment:
name: releaseNewActionVersion
steps:
- name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@23f4c6f12633a2da8f44938b71fde9afec138fb4 # v0.4.0
with:
source-tag: ${{ env.TAG_NAME }}

View File

@ -7,11 +7,10 @@ on:
- edited
- synchronize
permissions: {}
permissions:
contents: write
pull-requests: write
jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
permissions:
contents: write
pull-requests: write
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@0.16.0

View File

@ -4,11 +4,10 @@ on:
schedule:
- cron: "30 1 * * *"
permissions: {}
permissions:
issues: write
pull-requests: write
jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@b17226e57c8ef31f860719766656ebb6df017218 # 0.31.6
permissions:
issues: write
pull-requests: write
uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@0.16.0

1
.gitignore vendored
View File

@ -12,7 +12,6 @@ lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
eslint-report.json
# Runtime data
pids

View File

@ -1 +1 @@
20.19.3
20.9.0

View File

@ -1,80 +0,0 @@
# AGENTS.md — agent instructions and operational contract
This file exists so automated contributors (Copilot agents, bots, scripts) follow the same guardrails as human maintainers when working in `hoverkraft-tech/compose-action`. It summarizes what to read, which commands to run, and what is out of scope for agents.
## Organization-wide guidelines
- Always read and obey [hoverkraft-tech/.github/AGENTS.md](https://github.com/hoverkraft-tech/.github/blob/main/AGENTS.md) before touching this repository.
- Apply any additional instructions surfaced by the workspace (global Visual Studio Code prompts, repo-specific notices) alongside this contract.
## Canonical docs
- [README.md](./README.md) — product overview, supported inputs, and workflow examples. This is the primary contract for action users.
- [CONTRIBUTING.md](./CONTRIBUTING.md) — PR expectations, release hygiene, and how to collaborate with maintainers.
- [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) — behavioral expectations for every interaction.
## Instructional docs
- Source of truth for runtime logic lives under [`src/`](./src). Tests mirror the same structure under [`src/**/*.test.ts`](./src).
- GitHub Action fixtures and sample compose files live under [`test/`](./test). Use them when reproducing CI flows locally.
- Build artifacts belong in `dist/`. Never edit generated files by hand; instead update the matching TypeScript source and rerun the packaging commands described below.
## High-level rules (mandatory)
- Favor small, reviewable diffs. Coordinate large refactors with maintainers before starting.
- Keep behavior changes documented: update `README.md` and any affected workflow snippets.
- Never hardcode secrets, tokens, or personal data. Use GitHub Actions secrets or ask maintainers to provision them.
- Node 20+ is required. Match the tooling versions declared in `package.json`.
## Agent operational contract (when modifying code)
Before opening a PR or pushing a branch:
1. Read the relevant sections of `README.md` and inspect any affected files in `src/` and `test/`.
2. Implement changes in TypeScript source only; regenerate bundles with `npm run package` when shipping executable artifacts.
3. Run local validation limited to impacted areas at minimum:
- `npm run lint` (or `npm run lint:ci` when you need JSON output for CI).
- `npm run build` (type-check only).
- `npm run test` for quick feedback; `npm run test:ci` to reproduce CI (coverage + serial runs).
4. For action behavior changes, exercise the representative workflow under `test/` (e.g., `test/docker-compose.yml`) to confirm compose invocations behave as expected.
5. Add or update unit tests alongside any new logic, covering at least the happy path plus one failure or edge scenario.
6. Keep commits self-contained and use conventional commit messages compatible with `@commitlint/config-conventional`.
When opening a PR:
- Target a feature branch off `main`.
- Describe intent, touched areas, and the manual + automated test plan.
- Reference the docs you followed (for example: "Validated against readme > Usage" or "Followed CONTRIBUTING.md".).
- Ensure CI (lint, build, tests, package) is green before requesting human review.
## Validation & quality gates
- **Build:** `npm run build` must succeed (TypeScript compile cleanly, no `tsc` errors).
- **Lint:** `npm run lint:ci` must pass with no new warnings. Attach `eslint-report.json` to CI artifacts when relevant.
- **Tests:** `npm run test:ci` must pass and update coverage artifacts (see `coverage/`).
- **Bundle:** `npm run package` must regenerate `dist/` outputs; include updated bundles in the PR if runtime code changed.
## Allowed agent actions (examples)
- Fix documentation, typos, or metadata referenced by the GitHub Marketplace listing.
- Add or update unit tests, mocks, and fixtures in `src/` or `test/`.
- Refactor TypeScript modules in small, behavior-preserving increments (with tests and package outputs refreshed).
- Adjust CI/workflow helpers under `test/` to improve local reproducibility.
## Disallowed actions (must not do)
- Do not commit generated `dist/` artifacts without updating the corresponding TypeScript source and documenting the command used.
- Do not introduce new runtime dependencies without maintainer approval; prefer built-in Node APIs or existing deps.
- Do not modify Dockerfiles or GitHub Actions workflows to add secrets, credentials, or privileged steps.
- Do not land breaking changes to the public action inputs/outputs without updating `README.md` and gaining explicit maintainer sign-off.
## Guidance summary (quick checklist)
1. Read `README.md` + relevant source/test files.
2. Make the minimal change; add tests.
3. Run `npm run lint`, `npm run build`, `npm run test:ci`, and `npm run package`.
4. Open a PR referencing the docs you followed and include the test plan.
## If uncertain
Open an issue or draft PR in this repository describing the scenario, what docs you read, and the question you still have. Ping maintainers instead of guessing. When in doubt about the workflow contract, defer to the `README.md` and organization-wide AGENTS file.

View File

@ -1,12 +1,11 @@
FROM ghcr.io/super-linter/super-linter:slim-v8.0.0
#checkov:skip=CKV_DOCKER_2: required
FROM ghcr.io/super-linter/super-linter:slim-v7
HEALTHCHECK --interval=5m --timeout=10s --start-period=30s --retries=3 CMD ["/bin/sh","-c","test -d /github/home"]
ARG UID=1000
ARG GID=1000
RUN chown -R ${UID}:${GID} /github/home
USER ${UID}:${GID}
ENV RUN_LOCAL=true
ENV USE_FIND_ALGORITHM=true
ENV LOG_LEVEL=WARN
ENV LOG_FILE="/github/home/logs"
ENV LOG_FILE="../logs"

View File

@ -1,6 +1,6 @@
MIT License
Copyright hoverkraft
Copyright Hoverkraft
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@ -8,33 +8,27 @@ lint: ## Execute linting
lint-fix: ## Execute linting and fix
$(call run_linter, \
-e FIX_JSON_PRETTIER=true \
-e FIX_JAVASCRIPT_PRETTIER=true \
-e FIX_YAML_PRETTIER=true \
-e FIX_MARKDOWN=true \
-e FIX_JSON_PRETTIER=true \
-e FIX_MARKDOWN_PRETTIER=true \
-e FIX_NATURAL_LANGUAGE=true \
)
ci: ## Execute all formats and checks
@npm install
@npm audit fix
@npm run all
$(MAKE) lint-fix
-e FIX_NATURAL_LANGUAGE=true)
define run_linter
DEFAULT_WORKSPACE="$(CURDIR)"; \
LINTER_IMAGE="linter:latest"; \
VOLUME="$$DEFAULT_WORKSPACE:$$DEFAULT_WORKSPACE"; \
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $$LINTER_IMAGE .; \
docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) --tag $$LINTER_IMAGE .; \
docker run \
-e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \
-e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \
-e IGNORE_GITIGNORED_FILES=true \
-e FILTER_REGEX_EXCLUDE=dist/**/* \
-e VALIDATE_JSCPD=false \
-e VALIDATE_TYPESCRIPT_STANDARD=false \
-e VALIDATE_TYPESCRIPT_ES=false \
-e VALIDATE_TYPESCRIPT_PRETTIER=false \
-e VALIDATE_JAVASCRIPT_ES=false \
-e VALIDATE_JAVASCRIPT_STANDARD=false \
$(1) \
-v $$VOLUME \
--rm \

275
README.md
View File

@ -1,126 +1,113 @@
<!-- header:start -->
<!-- markdownlint-disable-next-line first-line-heading -->
<div align="center" width="100%">
<!-- start branding -->
# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItYW5jaG9yIiBjb2xvcj0iYmx1ZSI+PGNpcmNsZSBjeD0iMTIiIGN5PSI1IiByPSIzIj48L2NpcmNsZT48bGluZSB4MT0iMTIiIHkxPSIyMiIgeDI9IjEyIiB5Mj0iOCI+PC9saW5lPjxwYXRoIGQ9Ik01IDEySDJhMTAgMTAgMCAwIDAgMjAgMGgtMyI+PC9wYXRoPjwvc3ZnPg==) GitHub Action: Docker Compose Action
<img src=".github/ghadocs/branding.svg" width="15%" align="center" alt="branding<icon:anchor color:gray-dark>" />
<!-- end branding -->
<!-- start title -->
# <img src=".github/ghadocs/branding.svg" width="60px" align="center" alt="branding<icon:anchor color:gray-dark>" /> GitHub Action: Docker Compose Action
<!-- end title -->
<!-- start badges -->
<a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/v/release/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20tag" /></a><a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/release-date/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20date" /></a><img src="https://img.shields.io/github/last-commit/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Commit" /><a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Fissues"><img src="https://img.shields.io/github/issues/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Open%20Issues" /></a><img src="https://img.shields.io/github/downloads/hoverkraft-tech/compose-action/total?logo=github&style=flat-square" alt="Downloads" />
<!-- end badges -->
<div align="center">
<img src=".github/logo.svg" width="60px" align="center" alt="Docker Compose Action" />
</div>
<!-- start description -->
---
This action runs your docker-compose file and clean up before action finished
<!-- header:end -->
<!-- end description -->
<!-- badges:start -->
[![Marketplace](https://img.shields.io/badge/Marketplace-docker--compose--action-blue?logo=github-actions)](https://github.com/marketplace/actions/docker-compose-action)
[![Release](https://img.shields.io/github/v/release/hoverkraft-tech/compose-action)](https://github.com/hoverkraft-tech/compose-action/releases)
[![License](https://img.shields.io/github/license/hoverkraft-tech/compose-action)](http://choosealicense.com/licenses/mit/)
[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/compose-action?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/compose-action?style=social)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/compose-action/blob/main/CONTRIBUTING.md)
[![codecov](https://codecov.io/gh/hoverkraft-tech/compose-action/graph/badge.svg?token=90JXB7EIMA)](https://codecov.io/gh/hoverkraft-tech/compose-action)
<!-- badges:end -->
<!-- overview:start -->
## Overview
This action runs your compose file(s) and clean up before action finished
### Action
The action will run `docker compose up` to start the services defined in the given compose file(s).
The compose file(s) can be specified using the `compose-file` input.
Some extra options can be passed to the `docker compose up` command using the `up-flags` input.
### Post hook
On post hook, the action will run `docker compose down` to clean up the services.
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.
<!-- overview:end -->
<!-- usage:start -->
<!-- start contents -->
<!-- end contents -->
## Usage
### Action
The action will run `docker-compose up` to start the services defined in the given compose file(s).
The compose file(s) can be specified using the `compose-file` input.
Some extra options can be passed to the `docker-compose up` command using the `up-flags` input.
### 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.
Some extra options can be passed to the `docker-compose down` command using the `down-flags` input.
<!-- start usage -->
```yaml
- uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
- uses: hoverkraft-tech/compose-action@v0.0.0
with:
# Additional options to pass to `docker` command.
docker-flags: ""
# Description: Path to compose file(s). It can be a list of files. It can be
# absolute or relative to the current working directory (cwd).
#
# Default: ./docker-compose.yml
compose-file: ""
# Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd).
# Default: `./docker-compose.yml`
compose-file: ./docker-compose.yml
# Services to perform `docker compose up`.
# Description: Services to perform docker-compose up.
#
services: ""
# Additional options to pass to `docker compose up` command.
# Description: Additional options to pass to `docker-compose up` command.
#
# Default:
up-flags: ""
# Additional options to pass to `docker compose down` command.
# Description: Additional options to pass to `docker-compose down` command.
#
# Default:
down-flags: ""
# Additional options to pass to `docker compose` command.
# Description: Additional options to pass to `docker-compose` command.
#
# Default:
compose-flags: ""
# Current working directory
# Default: `${{ github.workspace }}`
cwd: ${{ github.workspace }}
# Description: Current working directory
#
# Default: ${{ github.workspace }}
cwd: ""
# Compose version to use.
# If null (default), it will use the current installed version.
# If "latest", it will install the latest version.
# Description: Compose version to use. If null (default), it will use the current
# installed version. If "latest", it will install the latest version.
#
compose-version: ""
# The log level used for Docker Compose service logs.
# Can be one of "debug", "info".
# Description: The GitHub token used to create an authenticated client (to fetch
# the latest version of docker-compose).
#
# Default: `debug`
services-log-level: debug
# The GitHub token used to create an authenticated client (to fetch the latest version of Docker Compose).
# Default: `${{ github.token }}`
github-token: ${{ github.token }}
# Default: ${{ github.token }}
github-token: ""
```
<!-- usage:end -->
<!-- inputs:start -->
<!-- end usage -->
## Inputs
| **Input** | **Description** | **Required** | **Default** |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------- |
| **`docker-flags`** | Additional options to pass to `docker` command. | **false** | - |
| **`compose-file`** | Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd). | **false** | `./docker-compose.yml` |
| **`services`** | Services to perform `docker compose up`. | **false** | - |
| **`up-flags`** | Additional options to pass to `docker compose up` command. | **false** | - |
| **`down-flags`** | Additional options to pass to `docker compose down` command. | **false** | - |
| **`compose-flags`** | Additional options to pass to `docker compose` command. | **false** | - |
| **`cwd`** | Current working directory | **false** | `${{ github.workspace }}` |
| **`compose-version`** | Compose version to use. | **false** | - |
| | If null (default), it will use the current installed version. | | |
| | If "latest", it will install the latest version. | | |
| **`services-log-level`** | The log level used for Docker Compose service logs. | **false** | `debug` |
| | Can be one of "debug", "info". | | |
| **`github-token`** | The GitHub token used to create an authenticated client (to fetch the latest version of Docker Compose). | **false** | `${{ github.token }}` |
<!-- start inputs -->
<!-- inputs:end -->
| **Input** | **Description** | **Default** | **Required** |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
| <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** |
<!-- secrets:start -->
<!-- secrets:end -->
<!-- outputs:start -->
<!-- outputs:end -->
<!-- examples:start -->
<!-- end inputs -->
<!-- start outputs -->
<!-- end outputs -->
## Examples
@ -136,24 +123,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.2
- uses: actions/checkout@v4
- name: Run docker compose
uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
- name: Run docker-compose
uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: "./docker/docker-compose.yml"
- name: Execute tests in the running services
run: |
docker compose exec test-app pytest
docker-compose exec test-app pytest
```
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
### Example Using environment variables
```yaml
steps:
- uses: actions/checkout@v4.2.2
- uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
- uses: actions/checkout@v4
- uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: "./docker/docker-compose.yml"
env:
@ -162,13 +152,13 @@ steps:
### Example using `services`
Perform `docker compose up` to some given service instead of all of them
Perform `docker-compose up` to some given service instead of all of them
```yaml
steps:
# need checkout before using compose-action
- uses: actions/checkout@v3
- uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
- uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: "./docker/docker-compose.yml"
services: |
@ -178,86 +168,33 @@ steps:
### Example using `up-flags`
Specify flags to pass to the `docker compose up`.
Default is none.
Can be used to pass the `--build` flag, for example, if you want persistent volumes to be deleted as well during cleanup.
A full list of flags can be found in the [Docker compose up documentation](https://docs.docker.com/compose/reference/up/).
Specify flags to pass to the `docker-compose up`. Default is none. Can be used
to pass the `--build` flag, for example, if you want persistent volumes to be
deleted as well during cleanup. A full list of flags can be found in the
[docker-compose up documentation](https://docs.docker.com/compose/reference/up/).
### Example using `down-flags`
Specify flags to pass to the `docker compose down` command during cleanup.
Default is none.
Can be used to pass the want persistent volumes to be deleted as well during cleanup.
A full list of flags can be found in the [Docker compose down documentation](https://docs.docker.com/compose/reference/down/).
Specify flags to pass to the `docker-compose down` command during cleanup.
Default is none. Can be used to pass the `--volumes` flag, for example, if you
want persistent volumes to be deleted as well during cleanup. A full list of
flags can be found in the
[docker-compose down documentation](https://docs.docker.com/compose/reference/down/).
### Example using `compose-flags`
Specify flags to pass to the `docker compose` command. Default is none.
A full list of flags can be found in the [Docker compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help).
Specify flags to pass to the `docker-compose` command. Default is none. A full
list of flags can be found in the
[docker-compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help).
```yaml
steps:
# need checkout before using compose-action
- uses: actions/checkout@v3
- uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
- uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: "./docker/docker-compose.yml"
compose-flags: "--profile profile-1"
services: |
helloworld2
helloworld3
```
Specify multiple compose files to use with the `docker compose` command.
This is useful when you have a base compose file and additional files for different environments or configurations.
```yaml
steps:
# need checkout before using compose-action
- uses: actions/checkout@v3
- uses: hoverkraft-tech/compose-action@05da55b2bb8a5a759d1c4732095044bd9018c050 # v2.4.3
with:
compose-file: |
./docker/docker-compose.yml
./docker/docker-compose.ci.yml
```
<!-- examples:end -->
<!-- contributing:start -->
## Contributing
Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/compose-action/blob/main/CONTRIBUTING.md) for more details.
<!-- contributing:end -->
<!-- security:start -->
<!-- security:end -->
<!-- license:start -->
## License
This project is licensed under the MIT License.
SPDX-License-Identifier: MIT
Copyright © 2026 hoverkraft
For more details, see the [license](http://choosealicense.com/licenses/mit/).
<!-- license:end -->
<!-- generated:start -->
---
This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor).
<!-- generated:end -->

View File

@ -1,46 +1,28 @@
# ### Action
#
# The action will run `docker compose up` to start the services defined in the given compose file(s).
# The compose file(s) can be specified using the `compose-file` input.
# Some extra options can be passed to the `docker compose up` command using the `up-flags` input.
#
# ### Post hook
#
# On post hook, the action will run `docker compose down` to clean up the services.
#
# 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.
name: "Docker Compose Action"
description: This action runs your compose file(s) and clean up before action finished
author: "hoverkraft"
description: "This action runs your docker-compose file and clean up before action finished"
author: "Hoverkraft"
branding:
icon: anchor
color: blue
color: gray-dark
inputs:
docker-flags:
description: "Additional options to pass to `docker` command."
required: false
compose-file:
description: "Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd)."
required: false
default: "./docker-compose.yml"
services:
description: "Services to perform `docker compose up`."
description: "Services to perform docker-compose up."
required: false
up-flags:
description: "Additional options to pass to `docker compose up` command."
description: "Additional options to pass to `docker-compose up` command."
required: false
default: ""
down-flags:
description: "Additional options to pass to `docker compose down` command."
description: "Additional options to pass to `docker-compose down` command."
required: false
default: ""
compose-flags:
description: "Additional options to pass to `docker compose` command."
description: "Additional options to pass to `docker-compose` command."
required: false
default: ""
cwd:
@ -53,14 +35,8 @@ inputs:
If null (default), it will use the current installed version.
If "latest", it will install the latest version.
required: false
services-log-level:
description: |
The log level used for Docker Compose service logs.
Can be one of "debug", "info".
required: false
default: "debug"
github-token:
description: The GitHub token used to create an authenticated client (to fetch the latest version of Docker Compose).
description: The GitHub token used to create an authenticated client (to fetch the latest version of docker-compose).
default: ${{ github.token }}
required: false

5598
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

13
dist/licenses.txt generated vendored
View File

@ -625,6 +625,19 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
uuid
MIT
The MIT License (MIT)
Copyright (c) 2010-2020 Robert Kieffer and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
wrappy
ISC
The ISC License

3524
dist/post.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +0,0 @@
import { default as tsDevToolsCore } from "@ts-dev-tools/core/dist/eslint-plugin-ts-dev-tools/index.js";
export default tsDevToolsCore.default;

7899
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,9 @@
"name": "compose-action",
"description": "Docker Compose Action",
"version": "0.0.0",
"author": "hoverkraft",
"license": "MIT",
"homepage": "https://github.com/hoverkraft-tech/compose-action",
"author": "",
"private": true,
"homepage": "https://github.com/hoverkraft-tech/compose-action",
"repository": {
"type": "git",
"url": "git+https://github.com/hoverkraft-tech/compose-action.git"
@ -23,36 +22,23 @@
"engines": {
"node": ">=20"
},
"dependencies": {
"@actions/core": "^2.0.1",
"@actions/github": "^6.0.1",
"@actions/tool-cache": "^2.0.2",
"@octokit/action": "^8.0.4",
"docker-compose": "^1.3.0"
},
"devDependencies": {
"@ts-dev-tools/core": "^1.9.14",
"@vercel/ncc": "^0.38.4",
"eslint-plugin-github": "^6.0.0",
"eslint-plugin-jsonc": "^2.21.0"
},
"scripts": {
"package": "npm run package:index && npm run package:post",
"package:index": "ncc build src/index.ts -o dist --license licenses.txt",
"package:post": "ncc build src/post.ts -o dist/post && mv dist/post/index.js dist/post.js && rm -rf dist/post",
"package:watch": "npm run package -- --watch",
"lint": "eslint \"src/**/*.{ts,tsx}\"",
"lint:ci": "npm run lint -- --output-file eslint-report.json --format json",
"all": "npm run format && npm run lint:ci && npm run test:ci && npm run package",
"all": "npm run format && npm run lint && npm run test && npm run package",
"build": "tsc --noEmit",
"format": "prettier --cache --write .",
"format": "prettier --cache --write '**/*.ts'",
"jest": "jest --detectOpenHandles --forceExit",
"test": "npm run jest -- --maxWorkers=50%",
"test:watch": "npm run jest --watch -- --maxWorkers=25%",
"test:cov": "npm run test -- --coverage",
"test:ci": "npm run jest -- --coverage --runInBand",
"test": "npm run jest --maxWorkers=50%",
"test:watch": "npm run jest --watch --maxWorkers=25%",
"test:cov": "npm run test --coverage",
"test:ci": "npm run test:cov --runInBand",
"prepare": "ts-dev-tools install"
},
"license": "MIT",
"jest": {
"preset": "ts-jest",
"verbose": true,
@ -85,11 +71,56 @@
"**/src/**/*.[jt]s?(x)"
]
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1",
"@octokit/action": "^7.0.0",
"docker-compose": "^1.1.0"
},
"devDependencies": {
"@ts-dev-tools/core": "^1.6.2",
"@vercel/ncc": "^0.38.1",
"eslint-plugin-github": "^5.0.1",
"eslint-plugin-jsonc": "^2.14.1"
},
"eslintConfig": {
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier"
],
"env": {
"es2021": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"settings": {
"jest": {
"version": "detect"
}
},
"ignorePatterns": [
"dist",
"node_modules"
]
},
"prettier": {
"semi": true,
"printWidth": 100,
"trailingComma": "es5",
"plugins": []
"trailingComma": "es5"
},
"commitlint": {
"extends": [
@ -108,6 +139,6 @@
}
},
"tsDevTools": {
"version": "20250623095600-remove-prettier-oxc"
"version": "20220617100200-prettier-cache"
}
}

View File

@ -1,19 +1,19 @@
import * as core from "@actions/core";
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 * as indexRunner from "./index-runner";
import { DockerComposeService } from "./services/docker-compose.service";
describe("run", () => {
// Mock the external libraries and services used by the action
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
// Mock the external libraries and services used by the action
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
describe("run", () => {
beforeEach(() => {
jest.clearAllMocks();
@ -28,7 +28,6 @@ describe("run", () => {
it("should install docker compose with specified version", async () => {
// Arrange
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
@ -37,7 +36,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: "1.29.2",
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
installMock.mockResolvedValue("1.29.2");
@ -51,7 +49,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,"serviceLogLevel":"debug"}'
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
);
expect(installMock).toHaveBeenCalledWith({
@ -61,13 +59,11 @@ describe("run", () => {
});
expect(upMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
upFlags: [],
services: [],
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
@ -76,7 +72,6 @@ describe("run", () => {
it("should bring up docker compose services", async () => {
// Arrange
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
@ -85,7 +80,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
// Act
@ -93,13 +87,11 @@ describe("run", () => {
// Assert
expect(upMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
upFlags: [],
services: ["web"],
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
});
@ -110,7 +102,6 @@ describe("run", () => {
upMock.mockRejectedValue(error);
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
@ -119,7 +110,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
// Act
@ -135,7 +125,6 @@ describe("run", () => {
upMock.mockRejectedValue(error);
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
@ -144,7 +133,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
// Act

View File

@ -36,13 +36,11 @@ export async function run(): Promise<void> {
loggerService.info("Bringing up docker compose service(s)");
await dockerComposeService.up({
dockerFlags: inputs.dockerFlags,
composeFiles: inputs.composeFiles,
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
upFlags: inputs.upFlags,
services: inputs.services,
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
});
loggerService.info("docker compose service(s) are up");
} catch (error) {

View File

@ -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, LogLevel } from "./services/logger.service";
import { LoggerService } from "./services/logger.service";
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
@ -25,7 +25,6 @@ describe("index", () => {
it("calls run when imported", async () => {
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
@ -34,7 +33,6 @@ describe("index", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
installMock.mockResolvedValue("1.2.3");
@ -50,19 +48,17 @@ 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,"serviceLogLevel":"debug"}'
'inputs: {"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(upMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();

View File

@ -3,4 +3,5 @@
*/
import { run } from "./index-runner";
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();

View File

@ -1,6 +1,6 @@
import * as core from "@actions/core";
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 { DockerComposeService } from "./services/docker-compose.service";
@ -27,7 +27,6 @@ describe("run", () => {
it("should bring down docker compose service(s) and log output", async () => {
// Arrange
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
@ -36,7 +35,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
logsMock.mockResolvedValue({ error: "", output: "test logs" });
@ -48,21 +46,17 @@ describe("run", () => {
// Assert
expect(logsMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
services: [],
serviceLogger: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
serviceLogger: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
@ -75,7 +69,6 @@ describe("run", () => {
it("should log docker composer errors if any", async () => {
// Arrange
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
@ -84,7 +77,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
logsMock.mockResolvedValue({
@ -102,18 +94,14 @@ describe("run", () => {
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
dockerFlags: [],
services: [],
serviceLogger: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
dockerFlags: [],
downFlags: [],
serviceLogger: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
@ -141,7 +129,6 @@ describe("run", () => {
downMock.mockRejectedValue(error);
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
@ -150,7 +137,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
// Act
@ -166,7 +152,6 @@ describe("run", () => {
downMock.mockRejectedValue(error);
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
@ -175,7 +160,6 @@ describe("run", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
// Act

View File

@ -16,12 +16,10 @@ export async function run(): Promise<void> {
const inputs = inputService.getInputs();
const { error, output } = await dockerComposeService.logs({
dockerFlags: inputs.dockerFlags,
composeFiles: inputs.composeFiles,
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
});
if (error) {
@ -31,12 +29,10 @@ export async function run(): Promise<void> {
loggerService.debug("docker compose logs:\n" + output);
await dockerComposeService.down({
dockerFlags: inputs.dockerFlags,
composeFiles: inputs.composeFiles,
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
downFlags: inputs.downFlags,
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
});
loggerService.info("docker compose is down");

View File

@ -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, LogLevel } from "./services/logger.service";
import { LoggerService } from "./services/logger.service";
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
@ -24,7 +24,6 @@ describe("post", () => {
it("calls run when imported", async () => {
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
@ -33,7 +32,6 @@ describe("post", () => {
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
logsMock.mockResolvedValue({ error: "", output: "test logs" });
@ -44,21 +42,17 @@ describe("post", () => {
await new Promise((resolve) => setTimeout(resolve, 0));
expect(logsMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
services: [],
serviceLogger: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
serviceLogger: debugMock,
});
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");

View File

@ -3,4 +3,5 @@
*/
import { run } from "./post-runner";
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();

View File

@ -25,13 +25,11 @@ describe("DockerComposeService", () => {
describe("up", () => {
it("should call up with correct options", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
await service.up(upInputs);
@ -40,62 +38,18 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: [],
config: ["docker-compose.yml"],
executable: {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
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";
if (callback) {
callback(Buffer.from(message));
}
expect(upInputs.serviceLogger).toHaveBeenCalledWith("test log output");
});
it("should call up with specific docker flags", async () => {
const upInputs: UpInputs = {
dockerFlags: ["--context", "dev"],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
await service.up(upInputs);
expect(upAllMock).toHaveBeenCalledWith({
composeOptions: [],
commandOptions: [],
config: ["docker-compose.yml"],
executable: {
executablePath: "docker",
options: ["--context", "dev"],
},
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
it("should call up with specific services", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["helloworld2", "helloworld3"],
composeFlags: [],
upFlags: ["--build"],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
await service.up(upInputs);
@ -104,149 +58,19 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: ["--build"],
config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
executable: {
executablePath: "docker",
options: [],
},
});
});
it("should throw formatted error when upAll fails with docker-compose result", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const dockerComposeError = {
exitCode: 1,
err: "Error: unable to pull image\nfailed to resolve reference",
out: "",
};
upAllMock.mockRejectedValue(dockerComposeError);
await expect(service.up(upInputs)).rejects.toThrow(
"Docker Compose command failed with exit code 1"
);
await expect(service.up(upInputs)).rejects.toThrow("unable to pull image");
});
it("should throw formatted error when upMany fails with docker-compose result", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: ["web"],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const dockerComposeError = {
exitCode: 1,
err: "Service 'web' failed to start",
out: "Starting web...",
};
upManyMock.mockRejectedValue(dockerComposeError);
await expect(service.up(upInputs)).rejects.toThrow(
"Docker Compose command failed with exit code 1"
);
await expect(service.up(upInputs)).rejects.toThrow("Service 'web' failed to start");
await expect(service.up(upInputs)).rejects.toThrow("Starting web...");
});
it("should pass through docker-compose result without exit code", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const dockerComposeError = {
exitCode: null,
err: "Some error without exit code",
out: "",
};
upAllMock.mockRejectedValue(dockerComposeError);
await expect(service.up(upInputs)).rejects.toThrow("Some error without exit code");
});
it("should pass through standard Error objects", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const standardError = new Error("Standard error message");
upAllMock.mockRejectedValue(standardError);
await expect(service.up(upInputs)).rejects.toThrow("Standard error message");
});
it("should pass through error strings", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const unknownError = "Some unknown error";
upAllMock.mockRejectedValue(unknownError);
await expect(service.up(upInputs)).rejects.toThrow("Some unknown error");
});
it("should handle unknown error types gracefully", async () => {
const upInputs: UpInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const unknownError = { unexpected: "error format" };
upAllMock.mockRejectedValue(unknownError);
await expect(service.up(upInputs)).rejects.toThrow(JSON.stringify(unknownError));
});
});
describe("down", () => {
it("should call down with correct options", async () => {
const downInputs: DownInputs = {
dockerFlags: [],
composeFiles: [],
composeFlags: [],
downFlags: ["--volumes", "--remove-orphans"],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
await service.down(downInputs);
@ -255,50 +79,19 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: ["--volumes", "--remove-orphans"],
config: [],
executable: {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
it("should throw formatted error when down fails with docker-compose result", async () => {
const downInputs: DownInputs = {
dockerFlags: [],
composeFiles: [],
composeFlags: [],
downFlags: [],
cwd: "/current/working/dir",
serviceLogger: jest.fn(),
};
const dockerComposeError = {
exitCode: 1,
err: "Error stopping containers",
out: "",
};
downMock.mockRejectedValue(dockerComposeError);
await expect(service.down(downInputs)).rejects.toThrow(
"Docker Compose command failed with exit code 1"
);
await expect(service.down(downInputs)).rejects.toThrow("Error stopping containers");
});
});
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",
serviceLogger: debugMock,
};
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
@ -308,13 +101,9 @@ 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

@ -2,7 +2,6 @@ import {
down,
IDockerComposeLogOptions,
IDockerComposeOptions,
IDockerComposeResult,
logs,
upAll,
upMany,
@ -10,11 +9,9 @@ import {
import { Inputs } from "./input.service";
type OptionsInputs = {
dockerFlags: Inputs["dockerFlags"];
composeFiles: Inputs["composeFiles"];
composeFlags: Inputs["composeFlags"];
cwd: Inputs["cwd"];
serviceLogger: (message: string) => void;
};
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
@ -28,16 +25,12 @@ export class DockerComposeService {
commandOptions: upFlags,
};
try {
if (services.length > 0) {
await upMany(services, options);
return;
}
await upAll(options);
} catch (error) {
throw this.formatDockerComposeError(error);
if (services.length > 0) {
await upMany(services, options);
return;
}
await upAll(options);
}
async down({ downFlags, ...optionsInputs }: DownInputs): Promise<void> {
@ -46,11 +39,7 @@ export class DockerComposeService {
commandOptions: downFlags,
};
try {
await down(options);
} catch (error) {
throw this.formatDockerComposeError(error);
}
await down(options);
}
async logs({ services, ...optionsInputs }: LogsInputs): Promise<{
@ -71,78 +60,15 @@ export class DockerComposeService {
}
private getCommonOptions({
dockerFlags,
composeFiles,
composeFlags,
cwd,
serviceLogger,
}: OptionsInputs): IDockerComposeOptions {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => serviceLogger(chunk.toString()),
executable: {
executablePath: "docker",
options: dockerFlags,
},
};
}
/**
* Formats docker-compose errors into proper Error objects with readable messages
*/
private formatDockerComposeError(error: unknown): Error {
// If it's already an Error, return it
if (error instanceof Error) {
return error;
}
// Handle docker-compose result objects
if (this.isDockerComposeResult(error)) {
const parts: string[] = [];
// Add exit code information
if (error.exitCode !== null) {
parts.push(`Docker Compose command failed with exit code ${error.exitCode}`);
} else {
parts.push("Docker Compose command failed");
}
// Add error stream output if available
if (error.err && error.err.trim()) {
parts.push("\nError output:");
parts.push(error.err.trim());
}
// Add standard output if available and different from error output
if (error.out && error.out.trim() && error.out !== error.err) {
parts.push("\nStandard output:");
parts.push(error.out.trim());
}
return new Error(parts.join("\n"));
}
// Handle string errors
if (typeof error === "string") {
return new Error(error);
}
// Fallback for unknown error types
return new Error(JSON.stringify(error));
}
/**
* Type guard to check if an object is a docker-compose result
*/
private isDockerComposeResult(error: unknown): error is IDockerComposeResult {
return (
typeof error === "object" &&
error !== null &&
"exitCode" in error &&
"err" in error &&
"out" in error
);
}
}

View File

@ -1,7 +1,14 @@
import * as core from "@actions/core";
import fs from "fs";
import { InputService, InputNames } from "./input.service";
import { LogLevel } from "./logger.service";
import * as core from "@actions/core";
import * as fs from "fs";
jest.mock("fs", () => ({
existsSync: jest.fn(),
promises: {
access: jest.fn(),
},
}));
jest.mock("@actions/core");
describe("InputService", () => {
let service: InputService;
@ -10,22 +17,11 @@ describe("InputService", () => {
let existsSyncMock: jest.SpiedFunction<typeof fs.existsSync>;
beforeEach(() => {
jest.clearAllMocks();
service = new InputService();
existsSyncMock = jest.spyOn(fs, "existsSync").mockImplementation();
getInputMock = jest.spyOn(core, "getInput").mockImplementation();
getMultilineInputMock = jest.spyOn(core, "getMultilineInput").mockImplementation();
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
service = new InputService();
});
afterEach(() => {
@ -33,35 +29,6 @@ describe("InputService", () => {
});
describe("getInputs", () => {
describe("docker-flags", () => {
it("should return given docker-flags input", () => {
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.DockerFlags:
return "docker-flag1 docker-flag2";
default:
return "";
}
});
existsSyncMock.mockReturnValue(true);
const inputs = service.getInputs();
expect(inputs.dockerFlags).toEqual(["docker-flag1", "docker-flag2"]);
});
it("should return empty array when no docker-flags input", () => {
getInputMock.mockReturnValue("");
existsSyncMock.mockReturnValue(true);
const inputs = service.getInputs();
expect(inputs.dockerFlags).toEqual([]);
});
});
describe("composeFiles", () => {
it("should return given composeFiles input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
@ -141,6 +108,15 @@ describe("InputService", () => {
describe("compose-flags", () => {
it("should return given compose-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFlags:
@ -158,6 +134,15 @@ describe("InputService", () => {
});
it("should return empty array when no compose-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockReturnValue("");
existsSyncMock.mockReturnValue(true);
@ -170,6 +155,15 @@ describe("InputService", () => {
describe("up-flags", () => {
it("should return given up-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.UpFlags:
@ -187,6 +181,15 @@ describe("InputService", () => {
});
it("should return empty array when no up-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockReturnValue("");
existsSyncMock.mockReturnValue(true);
@ -199,6 +202,15 @@ describe("InputService", () => {
describe("down-flags", () => {
it("should return given down-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.DownFlags:
@ -216,6 +228,15 @@ describe("InputService", () => {
});
it("should return empty array when no down-flags input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockReturnValue("");
existsSyncMock.mockReturnValue(true);
@ -227,6 +248,14 @@ describe("InputService", () => {
describe("cwd", () => {
it("should return given cwd input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.Cwd:
@ -245,6 +274,14 @@ describe("InputService", () => {
describe("compose-version", () => {
it("should return given compose-version input", () => {
getMultilineInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeFile:
return ["file1"];
default:
return [];
}
});
getInputMock.mockImplementation((inputName) => {
switch (inputName) {
case InputNames.ComposeVersion:
@ -260,53 +297,5 @@ describe("InputService", () => {
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,10 +1,8 @@
import { getInput, getMultilineInput } from "@actions/core";
import { existsSync } from "fs";
import { join } from "path";
import { LogLevel } from "./logger.service";
export type Inputs = {
dockerFlags: string[];
composeFiles: string[];
services: string[];
composeFlags: string[];
@ -13,11 +11,9 @@ export type Inputs = {
cwd: string;
composeVersion: string | null;
githubToken: string | null;
serviceLogLevel: LogLevel;
};
export enum InputNames {
DockerFlags = "docker-flags",
ComposeFile = "compose-file",
Services = "services",
ComposeFlags = "compose-flags",
@ -26,7 +22,6 @@ export enum InputNames {
Cwd = "cwd",
ComposeVersion = "compose-version",
GithubToken = "github-token",
ServiceLogLevel = "services-log-level",
}
export const COMPOSE_VERSION_LATEST = "latest";
@ -34,7 +29,6 @@ export const COMPOSE_VERSION_LATEST = "latest";
export class InputService {
getInputs(): Inputs {
return {
dockerFlags: this.getDockerFlags(),
composeFiles: this.getComposeFiles(),
services: this.getServices(),
composeFlags: this.getComposeFlags(),
@ -43,14 +37,9 @@ export class InputService {
cwd: this.getCwd(),
composeVersion: this.getComposeVersion(),
githubToken: this.getGithubToken(),
serviceLogLevel: this.getServiceLogLevel(),
};
}
private getDockerFlags(): string[] {
return this.parseFlags(getInput(InputNames.DockerFlags));
}
private getComposeFiles(): string[] {
const cwd = this.getCwd();
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
@ -119,14 +108,4 @@ export class InputService {
}) || 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, LogLevel } from "./logger.service";
import { LoggerService } from "./logger.service";
import { debug, info, warning } from "@actions/core";
jest.mock("@actions/core", () => ({
@ -43,21 +43,4 @@ describe("LoggerService", () => {
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,20 +12,4 @@ export class LoggerService {
debug(message: string) {
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",
}