diff --git a/.github/workflows/__check-action.yml b/.github/workflows/__check-action.yml index 195dabc..d69b772 100644 --- a/.github/workflows/__check-action.yml +++ b/.github/workflows/__check-action.yml @@ -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 diff --git a/action.yml b/action.yml index d596a83..bfa9262 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/dist/index.js b/dist/index.js index bbe0985..bf3921e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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"); diff --git a/dist/post.js b/dist/post.js index 2131416..b95a224 100644 --- a/dist/post.js +++ b/dist/post.js @@ -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"); diff --git a/src/services/input.service.test.ts b/src/services/input.service.test.ts index 9181904..444084d 100644 --- a/src/services/input.service.test.ts +++ b/src/services/input.service.test.ts @@ -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"' ); }); diff --git a/src/services/input.service.ts b/src/services/input.service.ts index 48e97b1..752852c 100644 --- a/src/services/input.service.ts +++ b/src/services/input.service.ts @@ -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) {