mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-08-31 23:52:49 +08:00
Some checks failed
Internal - Main - Continuous Integration / ci (push) Has been cancelled
Need fix to Issue / main (push) Has been cancelled
Prepare release / release (push) Has been cancelled
Internal - Main - Continuous Integration / prepare-docs (push) Has been cancelled
Internal - Main - Continuous Integration / sync-docs (push) Has been cancelled
Mark stale issues and pull requests / main (push) Has been cancelled
Bumps the github-actions-dependencies group with 6 updates: --- updated-dependencies: - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
148 lines
3.3 KiB
TypeScript
148 lines
3.3 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) => {
|
|
const trimmedComposeFile = composeFile.trim();
|
|
|
|
if (!trimmedComposeFile.length) {
|
|
return false;
|
|
}
|
|
|
|
if (trimmedComposeFile.startsWith("oci://")) {
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|