fix: support absolute path for compose-file input

Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
Emilien Escalle 2024-09-20 08:11:27 +02:00 committed by Emilien Escalle
parent ce6f83d4fb
commit 4d0ceccdad
6 changed files with 46 additions and 14 deletions

View File

@ -127,6 +127,28 @@ jobs:
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

View File

@ -7,7 +7,7 @@ branding:
inputs:
compose-file:
description: "Relative path to compose file(s). It can be a list of files."
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:

11
dist/index.js generated vendored
View File

@ -26266,13 +26266,16 @@ class InputService {
getComposeFiles() {
const cwd = this.getCwd();
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
if (!composeFile.length) {
if (!composeFile.trim().length) {
return false;
}
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
throw new Error(`${composeFile} does not exist in ${cwd}`);
const possiblePaths = [(0, path_1.join)(cwd, composeFile), composeFile];
for (const path of possiblePaths) {
if ((0, fs_1.existsSync)(path)) {
return true;
}
}
return true;
throw new Error(`Compose file not found in "${possiblePaths.join('", "')}"`);
});
if (!composeFiles.length) {
throw new Error("No compose files found");

11
dist/post.js generated vendored
View File

@ -26266,13 +26266,16 @@ class InputService {
getComposeFiles() {
const cwd = this.getCwd();
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
if (!composeFile.length) {
if (!composeFile.trim().length) {
return false;
}
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
throw new Error(`${composeFile} does not exist in ${cwd}`);
const possiblePaths = [(0, path_1.join)(cwd, composeFile), composeFile];
for (const path of possiblePaths) {
if ((0, fs_1.existsSync)(path)) {
return true;
}
}
return true;
throw new Error(`Compose file not found in "${possiblePaths.join('", "')}"`);
});
if (!composeFiles.length) {
throw new Error("No compose files found");

View File

@ -71,7 +71,7 @@ describe("InputService", () => {
existsSyncMock.mockImplementation((file) => file === "/current/working/directory/file1");
expect(() => service.getInputs()).toThrow(
"file2 does not exist in /current/working/directory"
'Compose file not found in "/current/working/directory/file2", "file2"'
);
});

View File

@ -35,15 +35,19 @@ export class InputService {
private getComposeFiles(): string[] {
const cwd = this.getCwd();
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
if (!composeFile.length) {
if (!composeFile.trim().length) {
return false;
}
if (!existsSync(join(cwd, composeFile))) {
throw new Error(`${composeFile} does not exist in ${cwd}`);
const possiblePaths = [join(cwd, composeFile), composeFile];
for (const path of possiblePaths) {
if (existsSync(path)) {
return true;
}
}
return true;
throw new Error(`Compose file not found in "${possiblePaths.join('", "')}"`);
});
if (!composeFiles.length) {