Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class Job {
predefinedVariables["CI_JOB_NAME_SLUG"] = `${this.name.replace(/[^a-z\d]+/ig, "-").replace(/^-/, "").slice(0, 63).replace(/-$/, "").toLowerCase()}`;
predefinedVariables["CI_JOB_STAGE"] = `${this.stage}`;
predefinedVariables["CI_PROJECT_DIR"] = ciProjectDir;
predefinedVariables["CI_JOB_URL"] = `https://${gitData.remote.host}/${gitData.remote.group}/${gitData.remote.project}/-/jobs/${this.jobId}`; // Changes on rerun.
predefinedVariables["CI_PIPELINE_URL"] = `https://${gitData.remote.host}/${gitData.remote.group}/${gitData.remote.project}/pipelines/${this.pipelineIid}`;
predefinedVariables["CI_JOB_URL"] = `${predefinedVariables["CI_SERVER_URL"]}/${gitData.remote.group}/${gitData.remote.project}/-/jobs/${this.jobId}`; // Changes on rerun.
predefinedVariables["CI_PIPELINE_URL"] = `${predefinedVariables["CI_SERVER_URL"]}/${gitData.remote.group}/${gitData.remote.project}/pipelines/${this.pipelineIid}`;
predefinedVariables["CI_ENVIRONMENT_NAME"] = this.environment?.name ?? "";
predefinedVariables["CI_ENVIRONMENT_SLUG"] = this.environment?.name?.replace(/[^a-z\d]+/ig, "-").replace(/^-/, "").slice(0, 23).replace(/-$/, "").toLowerCase() ?? "";
predefinedVariables["CI_ENVIRONMENT_URL"] = this.environment?.url ?? "";
Expand Down
11 changes: 6 additions & 5 deletions src/parser-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ export class ParserIncludes {
includeDatas = includeDatas.concat(await this.init(fileDoc, opts));
}
} else if (value["component"]) {
const {domain, projectPath, componentName, ref} = this.parseIncludeComponent(value["component"]);
const {domain, port, projectPath, componentName, ref} = this.parseIncludeComponent(value["component"]);
// converts component to project
const files = [`${componentName}.yml`, `${componentName}/template.yml`, null];

for (const f of files) {
assert(f !== null, `This GitLab CI configuration is invalid: component: \`${value["component"]}\`. One of the file [${files}] must exists in \`${domain}/${projectPath}\``);
assert(f !== null, `This GitLab CI configuration is invalid: component: \`${value["component"]}\`. One of the files [${files}] must exist in \`${domain}:${port}/${projectPath}\``);

const isLocalComponent = projectPath === `${gitData.remote.group}/${gitData.remote.project}` && ref === gitData.commit.SHA;
if (isLocalComponent) {
Expand Down Expand Up @@ -199,15 +199,16 @@ export class ParserIncludes {
};
}

static parseIncludeComponent (component: string): {domain: string; projectPath: string; componentName: string; ref: string} {
static parseIncludeComponent (component: string): {domain: string; port: string; projectPath: string; componentName: string; ref: string} {
assert(!component.includes("://"), `This GitLab CI configuration is invalid: component: \`${component}\` should not contain protocol`);
// eslint-disable-next-line no-useless-escape
const pattern = /(?<domain>[^/\s]+)\/(?<projectPath>.+)\/(?<componentName>[^@]+)@(?<ref>.+)/; // regexr.com/7v7hm
const pattern = /(?<domain>[^/:\s]+)(:(?<port>[0-9]+))?\/(?<projectPath>.+)\/(?<componentName>[^@]+)@(?<ref>.+)/; // https://regexr.com/86q5d
const gitRemoteMatch = pattern.exec(component);

if (gitRemoteMatch?.groups == null) throw new Error(`This is a bug, please create a github issue if this is something you're expecting to work. input: ${component}`);
return {
domain: gitRemoteMatch.groups["domain"],
port: gitRemoteMatch.groups["port"],
projectPath: gitRemoteMatch.groups["projectPath"],
componentName: `templates/${gitRemoteMatch.groups["componentName"]}`,
ref: gitRemoteMatch.groups["ref"],
Expand Down Expand Up @@ -239,7 +240,7 @@ export class ParserIncludes {
await Utils.bash(`
cd ${cwd}/${stateDir} \\
&& git clone --branch "${ref}" -n --depth=1 --filter=tree:0 \\
${remote.schema}://${remote.host}/${project}.git \\
${remote.schema}://${remote.host}:${remote.port}/${project}.git \\
${cwd}/${target}.${ext} \\
&& cd ${cwd}/${target}.${ext} \\
&& git sparse-checkout set --no-cone ${normalizedFile} \\
Expand Down
32 changes: 23 additions & 9 deletions src/predefined-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@
// 1. gitlab variables files
// 2. values derieved implicitly from `git remote -v`
// 3. default value
const CI_SERVER_PROTOCOL = envMatchedVariables["CI_SERVER_PROTOCOL"]
?? ((gitData.remote.schema === "http" || gitData.remote.schema === "https")
? gitData.remote.schema

Check failure on line 18 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
: "https");

Check failure on line 19 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
const CI_SERVER_PORT = envMatchedVariables["CI_SERVER_PORT"]
?? (gitData.remote.schema === "http" || gitData.remote.schema === "https")
?? ((gitData.remote.schema === "http" || gitData.remote.schema === "https")
? gitData.remote.port

Check failure on line 22 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
: "443";
: "443");

Check failure on line 23 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
const CI_SERVER_SHELL_SSH_PORT = envMatchedVariables["CI_SERVER_SHELL_SSH_PORT"]
?? (gitData.remote.schema === "ssh")
?? ((gitData.remote.schema === "ssh")
? gitData.remote.port

Check failure on line 26 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
: "22";
: "22");

Check failure on line 27 in src/predefined-variables.ts

View workflow job for this annotation

GitHub Actions / eslint

Expected indentation of 10 spaces but found 8
const CI_SERVER_HOST = envMatchedVariables["CI_SERVER_HOST"]
?? `${gitData.remote.host}`;
const CI_SERVER_FQDN = envMatchedVariables["CI_SERVER_FQDN"]
?? (CI_SERVER_PORT == "443"
? gitData.remote.host
: `${gitData.remote.host}:${CI_SERVER_PORT}`);
const CI_SERVER_URL = envMatchedVariables["CI_SERVER_URL"]
?? `${CI_SERVER_PROTOCOL}://${CI_SERVER_FQDN}`;
const CI_PROJECT_ROOT_NAMESPACE = gitData.remote.group.split("/")[0];
const CI_PROJECT_NAMESPACE = gitData.remote.group;

const CI_SERVER_URL = `https://${gitData.remote.host}:${CI_SERVER_PORT}`;
const predefinedVariables: {[key: string]: string} = {
CI: "true",
GITLAB_USER_LOGIN: gitData.user["GITLAB_USER_LOGIN"],
Expand All @@ -35,7 +48,8 @@
CI_PROJECT_TITLE: `${camelCase(gitData.remote.project)}`,
CI_PROJECT_PATH: `${gitData.remote.group}/${gitData.remote.project}`,
CI_PROJECT_PATH_SLUG: `${gitData.remote.group.replace(/\//g, "-")}-${gitData.remote.project}`.toLowerCase(),
CI_PROJECT_NAMESPACE: `${gitData.remote.group}`,
CI_PROJECT_ROOT_NAMESPACE: CI_PROJECT_ROOT_NAMESPACE,
CI_PROJECT_NAMESPACE: CI_PROJECT_NAMESPACE,
CI_PROJECT_VISIBILITY: "internal",
CI_PROJECT_ID: "1217",
CI_COMMIT_REF_PROTECTED: "false",
Expand All @@ -50,12 +64,12 @@
CI_COMMIT_DESCRIPTION: "More commit text",
CI_DEFAULT_BRANCH: gitData.branches.default,
CI_PIPELINE_SOURCE: "push",
CI_SERVER_FQDN: `${gitData.remote.host}:${CI_SERVER_PORT}`,
CI_SERVER_HOST: `${gitData.remote.host}`,
CI_SERVER_FQDN: CI_SERVER_FQDN,
CI_SERVER_HOST: CI_SERVER_HOST,
CI_SERVER_PORT: CI_SERVER_PORT,
CI_SERVER_SHELL_SSH_PORT: CI_SERVER_SHELL_SSH_PORT,
CI_SERVER_URL: CI_SERVER_URL,
CI_SERVER_PROTOCOL: "https",
CI_SERVER_PROTOCOL: CI_SERVER_PROTOCOL,
CI_API_V4_URL: `${CI_SERVER_URL}/api/v4`,
CI_PROJECT_URL: `${CI_SERVER_URL}/${gitData.remote.group}/${gitData.remote.project}`,
CI_TEMPLATE_REGISTRY_HOST: "registry.gitlab.com",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ ${evalStr}
case "http":
case "https": {
try {
const {status} = await axios.get(`${protocol}://${domain}/${projectPath}/-/raw/${ref}/${file}`);
const {status} = await axios.get(`${protocol}://${domain}:${port}/${projectPath}/-/raw/${ref}/${file}`);
return (status === 200);
} catch (e) {
return false;
Expand Down
Loading