mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-11 23:23:06 +08:00
fix: support absolute path for compose-file input
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
parent
ce6f83d4fb
commit
4d0ceccdad
22
.github/workflows/__check-action.yml
vendored
22
.github/workflows/__check-action.yml
vendored
@ -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-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
|
(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:
|
test-abort-on-container-exit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Test with --abort-on-container-exit
|
name: Test with --abort-on-container-exit
|
||||||
|
|||||||
@ -7,7 +7,7 @@ branding:
|
|||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
compose-file:
|
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
|
required: false
|
||||||
default: "./docker-compose.yml"
|
default: "./docker-compose.yml"
|
||||||
services:
|
services:
|
||||||
|
|||||||
11
dist/index.js
generated
vendored
11
dist/index.js
generated
vendored
@ -26266,13 +26266,16 @@ class InputService {
|
|||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.trim().length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
|
const possiblePaths = [(0, path_1.join)(cwd, composeFile), composeFile];
|
||||||
throw new Error(`${composeFile} does not exist in ${cwd}`);
|
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) {
|
if (!composeFiles.length) {
|
||||||
throw new Error("No compose files found");
|
throw new Error("No compose files found");
|
||||||
|
|||||||
11
dist/post.js
generated
vendored
11
dist/post.js
generated
vendored
@ -26266,13 +26266,16 @@ class InputService {
|
|||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.trim().length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
|
const possiblePaths = [(0, path_1.join)(cwd, composeFile), composeFile];
|
||||||
throw new Error(`${composeFile} does not exist in ${cwd}`);
|
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) {
|
if (!composeFiles.length) {
|
||||||
throw new Error("No compose files found");
|
throw new Error("No compose files found");
|
||||||
|
|||||||
@ -71,7 +71,7 @@ describe("InputService", () => {
|
|||||||
existsSyncMock.mockImplementation((file) => file === "/current/working/directory/file1");
|
existsSyncMock.mockImplementation((file) => file === "/current/working/directory/file1");
|
||||||
|
|
||||||
expect(() => service.getInputs()).toThrow(
|
expect(() => service.getInputs()).toThrow(
|
||||||
"file2 does not exist in /current/working/directory"
|
'Compose file not found in "/current/working/directory/file2", "file2"'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -35,15 +35,19 @@ export class InputService {
|
|||||||
private getComposeFiles(): string[] {
|
private getComposeFiles(): string[] {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.trim().length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(join(cwd, composeFile))) {
|
const possiblePaths = [join(cwd, composeFile), composeFile];
|
||||||
throw new Error(`${composeFile} does not exist in ${cwd}`);
|
|
||||||
|
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) {
|
if (!composeFiles.length) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user