mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-09 14:13:06 +08:00
feat: make docker-compose cwd aware
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
parent
43a233a413
commit
9e48869ba4
24
.github/workflows/__check-action.yml
vendored
24
.github/workflows/__check-action.yml
vendored
@ -104,3 +104,27 @@ jobs:
|
|||||||
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | grep docker-helloworld4-1
|
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | grep docker-helloworld4-1
|
||||||
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | (grep docker-helloworld-1 && echo "Unexpected service is running" && exit 1) || true
|
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | (grep docker-helloworld-1 && echo "Unexpected service is running" && exit 1) || true
|
||||||
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | (grep docker-helloworld3-1 && echo "Unexpected service is running" && exit 1) || true
|
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.ci.yml ps | (grep docker-helloworld3-1 && echo "Unexpected service is running" && exit 1) || true
|
||||||
|
|
||||||
|
test-action-with-cwd:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Test with cwd
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: hoverkraft-tech/ci-github-nodejs/actions/setup-node@0.4.2
|
||||||
|
|
||||||
|
- name: Act
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
compose-file: "docker-compose.yml"
|
||||||
|
cwd: "./docker"
|
||||||
|
services: |
|
||||||
|
helloworld2
|
||||||
|
helloworld3
|
||||||
|
|
||||||
|
- name: "Assert: only expected services are running"
|
||||||
|
run: |
|
||||||
|
docker-compose -f ./docker/docker-compose.yml ps
|
||||||
|
|
||||||
|
docker-compose -f ./docker/docker-compose.yml ps | grep docker-helloworld2-1
|
||||||
|
docker-compose -f ./docker/docker-compose.yml ps | grep docker-helloworld3-1
|
||||||
|
docker-compose -f ./docker/docker-compose.yml ps | (grep docker-helloworld-1 && echo "Unexpected service helloworld is running" && exit 1) || true
|
||||||
|
|||||||
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
dist
|
||||||
29
action.yml
29
action.yml
@ -1,31 +1,34 @@
|
|||||||
name: 'Docker Compose Action'
|
name: "Docker Compose Action"
|
||||||
description:
|
description: "This action runs your docker-compose file and clean up before action finished"
|
||||||
'This action runs your docker-compose file and clean up before action finished'
|
author: "Hoverkraft"
|
||||||
author: 'Hoverkraft'
|
|
||||||
branding:
|
branding:
|
||||||
icon: anchor
|
icon: anchor
|
||||||
color: gray-dark
|
color: gray-dark
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
compose-file:
|
compose-file:
|
||||||
description: 'Relative path to compose file(s). It can be a list of files.'
|
description: "Relative path to compose file(s). It can be a list of files."
|
||||||
required: false
|
required: false
|
||||||
default: './docker-compose.yml'
|
default: "./docker-compose.yml"
|
||||||
services:
|
services:
|
||||||
description: 'Services to perform docker-compose up.'
|
description: "Services to perform docker-compose up."
|
||||||
required: false
|
required: false
|
||||||
up-flags:
|
up-flags:
|
||||||
description: 'Additional options to pass to `docker-compose up` command.'
|
description: "Additional options to pass to `docker-compose up` command."
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ""
|
||||||
down-flags:
|
down-flags:
|
||||||
description: 'Additional options to pass to `docker-compose down` command.'
|
description: "Additional options to pass to `docker-compose down` command."
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ""
|
||||||
compose-flags:
|
compose-flags:
|
||||||
description: 'Additional options to pass to `docker-compose` command.'
|
description: "Additional options to pass to `docker-compose` command."
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ""
|
||||||
|
cwd:
|
||||||
|
description: "Current working directory"
|
||||||
|
required: false
|
||||||
|
default: ${{ github.workspace }}
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
|||||||
12
dist/index.js
generated
vendored
12
dist/index.js
generated
vendored
@ -26002,6 +26002,7 @@ class DockerComposeService {
|
|||||||
config: inputs.composeFiles,
|
config: inputs.composeFiles,
|
||||||
log: true,
|
log: true,
|
||||||
composeOptions: inputs.composeFlags,
|
composeOptions: inputs.composeFlags,
|
||||||
|
cwd: inputs.cwd,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26019,6 +26020,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.InputService = exports.InputNames = void 0;
|
exports.InputService = exports.InputNames = void 0;
|
||||||
const core_1 = __nccwpck_require__(2186);
|
const core_1 = __nccwpck_require__(2186);
|
||||||
const fs_1 = __nccwpck_require__(7147);
|
const fs_1 = __nccwpck_require__(7147);
|
||||||
|
const path_1 = __nccwpck_require__(1017);
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
InputNames["ComposeFile"] = "compose-file";
|
InputNames["ComposeFile"] = "compose-file";
|
||||||
@ -26026,6 +26028,7 @@ var InputNames;
|
|||||||
InputNames["ComposeFlags"] = "compose-flags";
|
InputNames["ComposeFlags"] = "compose-flags";
|
||||||
InputNames["UpFlags"] = "up-flags";
|
InputNames["UpFlags"] = "up-flags";
|
||||||
InputNames["DownFlags"] = "down-flags";
|
InputNames["DownFlags"] = "down-flags";
|
||||||
|
InputNames["Cwd"] = "cwd";
|
||||||
})(InputNames || (exports.InputNames = InputNames = {}));
|
})(InputNames || (exports.InputNames = InputNames = {}));
|
||||||
class InputService {
|
class InputService {
|
||||||
logger;
|
logger;
|
||||||
@ -26039,15 +26042,17 @@ class InputService {
|
|||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
upFlags: this.getUpFlags(),
|
upFlags: this.getUpFlags(),
|
||||||
downFlags: this.getDownFlags(),
|
downFlags: this.getDownFlags(),
|
||||||
|
cwd: this.getCwd(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
|
const cwd = this.getCwd();
|
||||||
return (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
return (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(0, fs_1.existsSync)(composeFile)) {
|
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
|
||||||
this.logger.warn(`${composeFile} not exists`);
|
this.logger.warn(`${composeFile} does not exist in ${cwd}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -26071,6 +26076,9 @@ class InputService {
|
|||||||
}
|
}
|
||||||
return flags.trim().split(" ");
|
return flags.trim().split(" ");
|
||||||
}
|
}
|
||||||
|
getCwd() {
|
||||||
|
return (0, core_1.getInput)(InputNames.Cwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.InputService = InputService;
|
exports.InputService = InputService;
|
||||||
|
|
||||||
|
|||||||
12
dist/post.js
generated
vendored
12
dist/post.js
generated
vendored
@ -26002,6 +26002,7 @@ class DockerComposeService {
|
|||||||
config: inputs.composeFiles,
|
config: inputs.composeFiles,
|
||||||
log: true,
|
log: true,
|
||||||
composeOptions: inputs.composeFlags,
|
composeOptions: inputs.composeFlags,
|
||||||
|
cwd: inputs.cwd,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26019,6 +26020,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.InputService = exports.InputNames = void 0;
|
exports.InputService = exports.InputNames = void 0;
|
||||||
const core_1 = __nccwpck_require__(2186);
|
const core_1 = __nccwpck_require__(2186);
|
||||||
const fs_1 = __nccwpck_require__(7147);
|
const fs_1 = __nccwpck_require__(7147);
|
||||||
|
const path_1 = __nccwpck_require__(1017);
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
InputNames["ComposeFile"] = "compose-file";
|
InputNames["ComposeFile"] = "compose-file";
|
||||||
@ -26026,6 +26028,7 @@ var InputNames;
|
|||||||
InputNames["ComposeFlags"] = "compose-flags";
|
InputNames["ComposeFlags"] = "compose-flags";
|
||||||
InputNames["UpFlags"] = "up-flags";
|
InputNames["UpFlags"] = "up-flags";
|
||||||
InputNames["DownFlags"] = "down-flags";
|
InputNames["DownFlags"] = "down-flags";
|
||||||
|
InputNames["Cwd"] = "cwd";
|
||||||
})(InputNames || (exports.InputNames = InputNames = {}));
|
})(InputNames || (exports.InputNames = InputNames = {}));
|
||||||
class InputService {
|
class InputService {
|
||||||
logger;
|
logger;
|
||||||
@ -26039,15 +26042,17 @@ class InputService {
|
|||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
upFlags: this.getUpFlags(),
|
upFlags: this.getUpFlags(),
|
||||||
downFlags: this.getDownFlags(),
|
downFlags: this.getDownFlags(),
|
||||||
|
cwd: this.getCwd(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
|
const cwd = this.getCwd();
|
||||||
return (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
return (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(0, fs_1.existsSync)(composeFile)) {
|
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, composeFile))) {
|
||||||
this.logger.warn(`${composeFile} not exists`);
|
this.logger.warn(`${composeFile} does not exist in ${cwd}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -26071,6 +26076,9 @@ class InputService {
|
|||||||
}
|
}
|
||||||
return flags.trim().split(" ");
|
return flags.trim().split(" ");
|
||||||
}
|
}
|
||||||
|
getCwd() {
|
||||||
|
return (0, core_1.getInput)(InputNames.Cwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.InputService = InputService;
|
exports.InputService = InputService;
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await main.run(main.RunAction.UP);
|
await main.run(main.RunAction.UP);
|
||||||
@ -52,7 +53,7 @@ describe("run", () => {
|
|||||||
// Verify that all of the functions were called correctly
|
// Verify that all of the functions were called correctly
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(
|
expect(debugMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'inputs: {"composeFiles":[],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[]}'
|
'inputs: {"composeFiles":[],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||||
);
|
);
|
||||||
expect(warnMock).toHaveBeenNthCalledWith(1, "no compose files found");
|
expect(warnMock).toHaveBeenNthCalledWith(1, "no compose files found");
|
||||||
expect(upMock).not.toHaveBeenCalled();
|
expect(upMock).not.toHaveBeenCalled();
|
||||||
@ -66,6 +67,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
upMock.mockResolvedValueOnce();
|
upMock.mockResolvedValueOnce();
|
||||||
@ -76,7 +78,7 @@ describe("run", () => {
|
|||||||
// Verify that all of the functions were called correctly
|
// Verify that all of the functions were called correctly
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(
|
expect(debugMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[]}'
|
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(upMock).toHaveBeenCalledWith({
|
expect(upMock).toHaveBeenCalledWith({
|
||||||
@ -85,6 +87,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(setFailedMock).not.toHaveBeenCalled();
|
expect(setFailedMock).not.toHaveBeenCalled();
|
||||||
@ -98,6 +101,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
upMock.mockRejectedValueOnce(new Error("unkown error"));
|
upMock.mockRejectedValueOnce(new Error("unkown error"));
|
||||||
@ -116,6 +120,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
downMock.mockResolvedValueOnce();
|
downMock.mockResolvedValueOnce();
|
||||||
@ -126,7 +131,7 @@ describe("run", () => {
|
|||||||
// Verify that all of the functions were called correctly
|
// Verify that all of the functions were called correctly
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(
|
expect(debugMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[]}'
|
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
@ -135,6 +140,7 @@ describe("run", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(setFailedMock).not.toHaveBeenCalled();
|
expect(setFailedMock).not.toHaveBeenCalled();
|
||||||
|
|||||||
@ -29,6 +29,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.up(inputs);
|
await service.up(inputs);
|
||||||
@ -38,6 +39,7 @@ describe("DockerComposeService", () => {
|
|||||||
commandOptions: [],
|
commandOptions: [],
|
||||||
config: ["docker-compose.yml"],
|
config: ["docker-compose.yml"],
|
||||||
log: true,
|
log: true,
|
||||||
|
cwd: "/current/working/dir",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: ["--build"],
|
upFlags: ["--build"],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.up(inputs);
|
await service.up(inputs);
|
||||||
@ -57,6 +60,7 @@ describe("DockerComposeService", () => {
|
|||||||
commandOptions: ["--build"],
|
commandOptions: ["--build"],
|
||||||
config: ["docker-compose.yml"],
|
config: ["docker-compose.yml"],
|
||||||
log: true,
|
log: true,
|
||||||
|
cwd: "/current/working/dir",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -69,6 +73,7 @@ describe("DockerComposeService", () => {
|
|||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
upFlags: [],
|
upFlags: [],
|
||||||
downFlags: ["--volumes", "--remove-orphans"],
|
downFlags: ["--volumes", "--remove-orphans"],
|
||||||
|
cwd: "/current/working/dir",
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.down(inputs);
|
await service.down(inputs);
|
||||||
@ -78,6 +83,7 @@ describe("DockerComposeService", () => {
|
|||||||
commandOptions: ["--volumes", "--remove-orphans"],
|
commandOptions: ["--volumes", "--remove-orphans"],
|
||||||
config: [],
|
config: [],
|
||||||
log: true,
|
log: true,
|
||||||
|
cwd: "/current/working/dir",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,6 +30,7 @@ export class DockerComposeService {
|
|||||||
config: inputs.composeFiles,
|
config: inputs.composeFiles,
|
||||||
log: true,
|
log: true,
|
||||||
composeOptions: inputs.composeFlags,
|
composeOptions: inputs.composeFlags,
|
||||||
|
cwd: inputs.cwd,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,7 @@ describe("InputService", () => {
|
|||||||
expect(inputs.composeFiles).toEqual(["file1"]);
|
expect(inputs.composeFiles).toEqual(["file1"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("services", () => {
|
describe("services", () => {
|
||||||
it("should return given services input", () => {
|
it("should return given services input", () => {
|
||||||
getMultilineInputMock.mockImplementation((inputName) => {
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
@ -89,6 +90,7 @@ describe("InputService", () => {
|
|||||||
expect(inputs.services).toEqual(["service1", "service2"]);
|
expect(inputs.services).toEqual(["service1", "service2"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("compose-flags", () => {
|
describe("compose-flags", () => {
|
||||||
it("should return given compose-flags input", () => {
|
it("should return given compose-flags input", () => {
|
||||||
getMultilineInputMock.mockReturnValue([]);
|
getMultilineInputMock.mockReturnValue([]);
|
||||||
@ -116,6 +118,7 @@ describe("InputService", () => {
|
|||||||
expect(inputs.composeFlags).toEqual([]);
|
expect(inputs.composeFlags).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("up-flags", () => {
|
describe("up-flags", () => {
|
||||||
it("should return given up-flags input", () => {
|
it("should return given up-flags input", () => {
|
||||||
getMultilineInputMock.mockReturnValue([]);
|
getMultilineInputMock.mockReturnValue([]);
|
||||||
@ -143,6 +146,7 @@ describe("InputService", () => {
|
|||||||
expect(inputs.upFlags).toEqual([]);
|
expect(inputs.upFlags).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("down-flags", () => {
|
describe("down-flags", () => {
|
||||||
it("should return given down-flags input", () => {
|
it("should return given down-flags input", () => {
|
||||||
getMultilineInputMock.mockReturnValue([]);
|
getMultilineInputMock.mockReturnValue([]);
|
||||||
@ -170,5 +174,23 @@ describe("InputService", () => {
|
|||||||
expect(inputs.downFlags).toEqual([]);
|
expect(inputs.downFlags).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("cwd", () => {
|
||||||
|
it("should return given cwd input", () => {
|
||||||
|
getMultilineInputMock.mockReturnValue([]);
|
||||||
|
getInputMock.mockImplementation((inputName) => {
|
||||||
|
switch (inputName) {
|
||||||
|
case InputNames.Cwd:
|
||||||
|
return "cwd";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const inputs = service.getInputs();
|
||||||
|
|
||||||
|
expect(inputs.cwd).toEqual("cwd");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { getInput, getMultilineInput } from "@actions/core";
|
import { getInput, getMultilineInput } from "@actions/core";
|
||||||
import { LoggerService } from "./logger.service";
|
import { LoggerService } from "./logger.service";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
|
import { join } from "path";
|
||||||
|
|
||||||
export type Inputs = {
|
export type Inputs = {
|
||||||
composeFiles: string[];
|
composeFiles: string[];
|
||||||
@ -8,6 +9,7 @@ export type Inputs = {
|
|||||||
composeFlags: string[];
|
composeFlags: string[];
|
||||||
upFlags: string[];
|
upFlags: string[];
|
||||||
downFlags: string[];
|
downFlags: string[];
|
||||||
|
cwd: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum InputNames {
|
export enum InputNames {
|
||||||
@ -16,6 +18,7 @@ export enum InputNames {
|
|||||||
ComposeFlags = "compose-flags",
|
ComposeFlags = "compose-flags",
|
||||||
UpFlags = "up-flags",
|
UpFlags = "up-flags",
|
||||||
DownFlags = "down-flags",
|
DownFlags = "down-flags",
|
||||||
|
Cwd = "cwd",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InputService {
|
export class InputService {
|
||||||
@ -28,17 +31,19 @@ export class InputService {
|
|||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
upFlags: this.getUpFlags(),
|
upFlags: this.getUpFlags(),
|
||||||
downFlags: this.getDownFlags(),
|
downFlags: this.getDownFlags(),
|
||||||
|
cwd: this.getCwd(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private getComposeFiles(): string[] {
|
private getComposeFiles(): string[] {
|
||||||
|
const cwd = this.getCwd();
|
||||||
return getMultilineInput(InputNames.ComposeFile).filter((composeFile) => {
|
return getMultilineInput(InputNames.ComposeFile).filter((composeFile) => {
|
||||||
if (!composeFile.length) {
|
if (!composeFile.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(composeFile)) {
|
if (!existsSync(join(cwd, composeFile))) {
|
||||||
this.logger.warn(`${composeFile} not exists`);
|
this.logger.warn(`${composeFile} does not exist in ${cwd}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,4 +74,8 @@ export class InputService {
|
|||||||
|
|
||||||
return flags.trim().split(" ");
|
return flags.trim().split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getCwd(): string {
|
||||||
|
return getInput(InputNames.Cwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user