Skip to content

Commit

Permalink
fix: support absolute path for compose-file input
Browse files Browse the repository at this point in the history
Signed-off-by: Emilien Escalle <[email protected]>
  • Loading branch information
neilime committed Sep 20, 2024
1 parent ce6f83d commit 4d0cecc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/__check-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions dist/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/services/input.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
);
});

Expand Down
12 changes: 8 additions & 4 deletions src/services/input.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4d0cecc

Please sign in to comment.