mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-07-04 12:42:51 +08:00
Bumps the npm-actions-dependencies group with 3 updates: - [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) - [@actions/github](https://github.com/actions/toolkit/tree/HEAD/packages/github) - [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache) Updates `@actions/core` from 2.0.2 to 3.0.0 - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Updates `@actions/github` from 7.0.0 to 9.0.0 - [Changelog](https://github.com/actions/toolkit/blob/main/packages/github/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/github) Updates `@actions/tool-cache` from 3.0.0 to 4.0.0 - [Changelog](https://github.com/actions/toolkit/blob/main/packages/tool-cache/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/@actions/cache@4.0.0/packages/tool-cache) --- updated-dependencies: - dependency-name: "@actions/core" dependency-version: 3.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: npm-actions-dependencies - dependency-name: "@actions/github" dependency-version: 9.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: npm-actions-dependencies - dependency-name: "@actions/tool-cache" dependency-version: 4.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: npm-actions-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
133 lines
3.4 KiB
TypeScript
133 lines
3.4 KiB
TypeScript
import { getInput, getMultilineInput } from "@actions/core";
|
|
import { existsSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { LogLevel } from "./logger.service.js";
|
|
|
|
export type Inputs = {
|
|
dockerFlags: string[];
|
|
composeFiles: string[];
|
|
services: string[];
|
|
composeFlags: string[];
|
|
upFlags: string[];
|
|
downFlags: string[];
|
|
cwd: string;
|
|
composeVersion: string | null;
|
|
githubToken: string | null;
|
|
serviceLogLevel: LogLevel;
|
|
};
|
|
|
|
export enum InputNames {
|
|
DockerFlags = "docker-flags",
|
|
ComposeFile = "compose-file",
|
|
Services = "services",
|
|
ComposeFlags = "compose-flags",
|
|
UpFlags = "up-flags",
|
|
DownFlags = "down-flags",
|
|
Cwd = "cwd",
|
|
ComposeVersion = "compose-version",
|
|
GithubToken = "github-token",
|
|
ServiceLogLevel = "services-log-level",
|
|
}
|
|
|
|
export const COMPOSE_VERSION_LATEST = "latest";
|
|
|
|
export class InputService {
|
|
getInputs(): Inputs {
|
|
return {
|
|
dockerFlags: this.getDockerFlags(),
|
|
composeFiles: this.getComposeFiles(),
|
|
services: this.getServices(),
|
|
composeFlags: this.getComposeFlags(),
|
|
upFlags: this.getUpFlags(),
|
|
downFlags: this.getDownFlags(),
|
|
cwd: this.getCwd(),
|
|
composeVersion: this.getComposeVersion(),
|
|
githubToken: this.getGithubToken(),
|
|
serviceLogLevel: this.getServiceLogLevel(),
|
|
};
|
|
}
|
|
|
|
private getDockerFlags(): string[] {
|
|
return this.parseFlags(getInput(InputNames.DockerFlags));
|
|
}
|
|
|
|
private getComposeFiles(): string[] {
|
|
const cwd = this.getCwd();
|
|
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
|
if (!composeFile.trim().length) {
|
|
return false;
|
|
}
|
|
|
|
const possiblePaths = [join(cwd, composeFile), composeFile];
|
|
|
|
for (const path of possiblePaths) {
|
|
if (existsSync(path)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
throw new Error(`Compose file not found in "${possiblePaths.join('", "')}"`);
|
|
});
|
|
|
|
if (!composeFiles.length) {
|
|
throw new Error("No compose files found");
|
|
}
|
|
|
|
return composeFiles;
|
|
}
|
|
|
|
private getServices(): string[] {
|
|
return getMultilineInput(InputNames.Services, { required: false });
|
|
}
|
|
|
|
private getComposeFlags(): string[] {
|
|
return this.parseFlags(getInput(InputNames.ComposeFlags));
|
|
}
|
|
|
|
private getUpFlags(): string[] {
|
|
return this.parseFlags(getInput(InputNames.UpFlags));
|
|
}
|
|
|
|
private getDownFlags(): string[] {
|
|
return this.parseFlags(getInput(InputNames.DownFlags));
|
|
}
|
|
|
|
private parseFlags(flags: string | null): string[] {
|
|
if (!flags) {
|
|
return [];
|
|
}
|
|
|
|
return flags.trim().split(" ");
|
|
}
|
|
|
|
private getCwd(): string {
|
|
return getInput(InputNames.Cwd);
|
|
}
|
|
|
|
private getComposeVersion(): string | null {
|
|
return (
|
|
getInput(InputNames.ComposeVersion, {
|
|
required: false,
|
|
}) || null
|
|
);
|
|
}
|
|
|
|
private getGithubToken(): string | null {
|
|
return (
|
|
getInput(InputNames.GithubToken, {
|
|
required: false,
|
|
}) || null
|
|
);
|
|
}
|
|
|
|
private getServiceLogLevel(): LogLevel {
|
|
const configuredLevel = getInput(InputNames.ServiceLogLevel, { required: false });
|
|
if (configuredLevel && !Object.values(LogLevel).includes(configuredLevel as LogLevel)) {
|
|
throw new Error(
|
|
`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(LogLevel).join(", ")}`
|
|
);
|
|
}
|
|
return (configuredLevel as LogLevel) || LogLevel.Debug;
|
|
}
|
|
}
|