debian-mirror-gitlab/app/assets/javascripts/ci/runner/components/registration/utils.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import {
DEFAULT_PLATFORM,
LINUX_PLATFORM,
MACOS_PLATFORM,
WINDOWS_PLATFORM,
DOWNLOAD_LOCATIONS,
} from '../../constants';
import linuxInstall from './scripts/linux/install.sh?raw';
import osxInstall from './scripts/osx/install.sh?raw';
import windowsInstall from './scripts/windows/install.ps1?raw';
const OS = {
[LINUX_PLATFORM]: {
shell: 'bash',
commandPrompt: '$',
executable: 'gitlab-runner',
},
[MACOS_PLATFORM]: {
shell: 'bash',
commandPrompt: '$',
executable: 'gitlab-runner',
},
[WINDOWS_PLATFORM]: {
shell: 'powershell',
commandPrompt: '>',
executable: '.\\gitlab-runner.exe',
},
};
export const commandPrompt = ({ platform }) => {
return (OS[platform] || OS[DEFAULT_PLATFORM]).commandPrompt;
};
export const executable = ({ platform }) => {
return (OS[platform] || OS[DEFAULT_PLATFORM]).executable;
};
2023-06-20 00:43:36 +05:30
export const registerCommand = ({ platform, url = gon.gitlab_url, token }) => {
const lines = [`${executable({ platform })} register`]; // eslint-disable-line @gitlab/require-i18n-strings
2023-05-27 22:25:52 +05:30
if (url) {
lines.push(` --url ${url}`);
}
2023-06-20 00:43:36 +05:30
if (token) {
lines.push(` --token ${token}`);
2023-05-27 22:25:52 +05:30
}
return lines;
};
export const runCommand = ({ platform }) => {
2023-06-20 00:43:36 +05:30
return `${executable({ platform })} run`; // eslint-disable-line @gitlab/require-i18n-strings
2023-05-27 22:25:52 +05:30
};
const importInstallScript = ({ platform = DEFAULT_PLATFORM }) => {
switch (platform) {
case LINUX_PLATFORM:
return linuxInstall;
case MACOS_PLATFORM:
return osxInstall;
case WINDOWS_PLATFORM:
return windowsInstall;
default:
return '';
}
};
export const platformArchitectures = ({ platform }) => {
return DOWNLOAD_LOCATIONS[platform].map(({ arch }) => arch);
};
export const installScript = ({ platform, architecture }) => {
const downloadLocation = DOWNLOAD_LOCATIONS[platform].find(({ arch }) => arch === architecture)
.url;
return importInstallScript({ platform })
.replace(
// eslint-disable-next-line no-template-curly-in-string
'${GITLAB_CI_RUNNER_DOWNLOAD_LOCATION}',
downloadLocation,
)
.trim();
};