Skip to content

Commit edac78e

Browse files
v2.2.0
1 parent e412bfd commit edac78e

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

dist/index.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3939
});
4040
};
4141
Object.defineProperty(exports, "__esModule", ({ value: true }));
42-
exports.runCleanup = exports.runAction = exports.forceUseCache = exports.getContainerId = exports.runCompose = exports.ComposeError = void 0;
42+
exports.runCleanup = exports.runAction = exports.forceUseCache = exports.getContainerId = exports.runCompose = exports.composeCommand = exports.ComposeError = void 0;
4343
const core = __importStar(__nccwpck_require__(2186));
4444
const exec = __importStar(__nccwpck_require__(1514));
4545
const transform_1 = __nccwpck_require__(1644);
@@ -50,6 +50,42 @@ class ComposeError extends Error {
5050
}
5151
}
5252
exports.ComposeError = ComposeError;
53+
class ComposeCommand {
54+
constructor() {
55+
// Not using a constructor as the singleton implementation due to await, constructors can't be async.
56+
this.initialised = false;
57+
this.composeCommand = 'docker-compose';
58+
}
59+
/**
60+
* Checks docker-compose availability, using docker compose as fallback.
61+
*
62+
* @returns {Promise<string>} 'docker-compose' or 'docker compose'
63+
*/
64+
get() {
65+
return __awaiter(this, void 0, void 0, function* () {
66+
if (!this.initialised) {
67+
this.initialised = true;
68+
try {
69+
yield exec.exec('docker-compose', ['--version']);
70+
}
71+
catch (error) {
72+
console.warn('docker-compose not available, falling back to docker compose');
73+
this.composeCommand = 'docker compose';
74+
}
75+
}
76+
return this.composeCommand;
77+
});
78+
}
79+
init() {
80+
this.initialised = true;
81+
this.composeCommand = 'docker-compose';
82+
}
83+
reset() {
84+
this.initialised = false;
85+
this.composeCommand = 'docker-compose';
86+
}
87+
}
88+
exports.composeCommand = new ComposeCommand();
5389
function runCompose(command, args, context, execOptions) {
5490
return __awaiter(this, void 0, void 0, function* () {
5591
const composeArgs = [];
@@ -63,7 +99,8 @@ function runCompose(command, args, context, execOptions) {
6399
for (const part of args) {
64100
composeArgs.push(part);
65101
}
66-
return yield exec.exec('docker-compose', composeArgs, execOptions);
102+
const dockerCompose = yield exports.composeCommand.get();
103+
return yield exec.exec(dockerCompose, composeArgs, execOptions);
67104
});
68105
}
69106
exports.runCompose = runCompose;

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docker-compose-action",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"private": true,
55
"description": "Run docker-compose and enforce cleanup after the job finished",
66
"main": "lib/main.js",

0 commit comments

Comments
 (0)