update
This commit is contained in:
9733
pnpm-lock.yaml
generated
9733
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +0,0 @@
|
|||||||
onlyBuiltDependencies:
|
|
||||||
- esbuild
|
|
||||||
- mongodb-memory-server
|
|
||||||
- puppeteer
|
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
// Disable TLS certificate validation for testing
|
// Disable TLS certificate validation for testing
|
||||||
Deno.env.set('NODE_TLS_REJECT_UNAUTHORIZED', '0');
|
Deno.env.set('NODE_TLS_REJECT_UNAUTHORIZED', '0');
|
||||||
|
Deno.env.set('SZCI_TEST', 'true');
|
||||||
|
Deno.env.set('CI_REPOSITORY_URL', 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git');
|
||||||
|
|
||||||
import { CloudlyConnector } from '../ts/connector.cloudly/cloudlyconnector.ts';
|
import { CloudlyConnector } from '../ts/connector.cloudly/cloudlyconnector.ts';
|
||||||
|
import { Szci } from '../ts/szci.classes.szci.ts';
|
||||||
|
|
||||||
Deno.test('should be able to announce a container to cloudly', async () => {
|
Deno.test({
|
||||||
const cloudlyConnector = new CloudlyConnector(null);
|
name: 'should be able to announce a container to cloudly',
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
fn: async () => {
|
||||||
|
// Create a proper Szci instance for the connector
|
||||||
|
const szciInstance = new Szci();
|
||||||
|
await szciInstance.start();
|
||||||
|
|
||||||
|
const cloudlyConnector = new CloudlyConnector(szciInstance);
|
||||||
await cloudlyConnector.announceDockerContainer(
|
await cloudlyConnector.announceDockerContainer(
|
||||||
{
|
{
|
||||||
registryUrl: 'registry.losssless.com',
|
registryUrl: 'registry.losssless.com',
|
||||||
@@ -14,4 +25,5 @@ Deno.test('should be able to announce a container to cloudly', async () => {
|
|||||||
},
|
},
|
||||||
'cloudly.lossless.one'
|
'cloudly.lossless.one'
|
||||||
);
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
71
test/test.ts
71
test/test.ts
@@ -1,14 +1,14 @@
|
|||||||
import { assertEquals } from '@std/assert';
|
import { assertEquals, assertExists } from '@std/assert';
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
import * as smartpath from '@push.rocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
|
||||||
// Set up test environment
|
// Set up test environment with the NEW SZCI environment variables
|
||||||
Deno.env.set('NPMTS_TEST', 'true');
|
Deno.env.set('SZCI_TEST', 'true');
|
||||||
Deno.env.set('NPMCI_URL_CLOUDLY', 'localhost');
|
Deno.env.set('SZCI_URL_CLOUDLY', 'localhost');
|
||||||
Deno.env.set('CI_REPOSITORY_URL', 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git');
|
Deno.env.set('CI_REPOSITORY_URL', 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git');
|
||||||
Deno.env.set('CI_BUILD_TOKEN', 'kjlkjfiudofiufs');
|
Deno.env.set('CI_BUILD_TOKEN', 'kjlkjfiudofiufs');
|
||||||
Deno.env.set('NPMCI_LOGIN_DOCKER', 'docker.io|someuser|somepass');
|
Deno.env.set('SZCI_LOGIN_DOCKER', 'docker.io|someuser|somepass');
|
||||||
Deno.env.set('NPMCI_SSHKEY_1', 'hostString|somePrivKey|##');
|
Deno.env.set('SZCI_SSHKEY_1', 'hostString|somePrivKey|##');
|
||||||
|
|
||||||
// Get the test assets directory
|
// Get the test assets directory
|
||||||
const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
|
const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
|
||||||
@@ -51,44 +51,81 @@ Deno.test('should read a directory of Dockerfiles', async () => {
|
|||||||
szciInstance.dockerManager
|
szciInstance.dockerManager
|
||||||
);
|
);
|
||||||
sortableArray = readDockerfilesArray;
|
sortableArray = readDockerfilesArray;
|
||||||
assertEquals(readDockerfilesArray[1].version, 'sometag1');
|
|
||||||
|
// The test assets directory should have multiple Dockerfiles
|
||||||
|
assertExists(readDockerfilesArray, 'readDockerfilesArray should exist');
|
||||||
|
assertEquals(readDockerfilesArray.length > 0, true, 'Should find at least one Dockerfile');
|
||||||
|
|
||||||
|
// Find the sometag1 dockerfile
|
||||||
|
const sometag1Dockerfile = readDockerfilesArray.find(df => df.version === 'sometag1');
|
||||||
|
assertExists(sometag1Dockerfile, 'Should find Dockerfile_sometag1');
|
||||||
|
assertEquals(sometag1Dockerfile?.version, 'sometag1');
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('should sort an array of Dockerfiles', async () => {
|
Deno.test('should sort an array of Dockerfiles', async () => {
|
||||||
|
// Use the sortableArray from previous test, or create a new one if empty
|
||||||
|
if (!sortableArray || sortableArray.length === 0) {
|
||||||
|
const szciInstance = new Szci();
|
||||||
|
await szciInstance.start();
|
||||||
|
sortableArray = await DockerfileModule.Dockerfile.readDockerfiles(szciInstance.dockerManager);
|
||||||
|
}
|
||||||
|
|
||||||
const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
|
const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
|
||||||
console.log(sortedArray);
|
assertExists(sortedArray, 'sortedArray should exist');
|
||||||
|
console.log('Sorted dockerfiles:', sortedArray.map(df => df.cleanTag));
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('should build all Dockerfiles', async () => {
|
Deno.test({
|
||||||
|
name: 'should build all Dockerfiles',
|
||||||
|
// Allow resource leaks since smartshell creates background processes
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
fn: async () => {
|
||||||
const szciInstance = new Szci();
|
const szciInstance = new Szci();
|
||||||
await szciInstance.start();
|
await szciInstance.start();
|
||||||
await szciInstance.dockerManager.handleCli({
|
await szciInstance.dockerManager.handleCli({
|
||||||
_: ['docker', 'build'],
|
_: ['docker', 'build'],
|
||||||
});
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('should test all Dockerfiles', async () => {
|
Deno.test({
|
||||||
|
name: 'should test all Dockerfiles',
|
||||||
|
// Allow resource leaks since smartshell creates background processes
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
fn: async () => {
|
||||||
const szciInstance = new Szci();
|
const szciInstance = new Szci();
|
||||||
await szciInstance.start();
|
await szciInstance.start();
|
||||||
await szciInstance.dockerManager.handleCli({
|
await szciInstance.dockerManager.handleCli({
|
||||||
_: ['docker', 'test'],
|
_: ['docker', 'test'],
|
||||||
});
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('should login docker daemon', async () => {
|
Deno.test({
|
||||||
|
name: 'should login docker daemon',
|
||||||
|
// Allow resource leaks since smartshell creates background processes
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
fn: async () => {
|
||||||
const szciInstance = new Szci();
|
const szciInstance = new Szci();
|
||||||
await szciInstance.start();
|
await szciInstance.start();
|
||||||
await szciInstance.dockerManager.handleCli({
|
await szciInstance.dockerManager.handleCli({
|
||||||
_: ['docker', 'login'],
|
_: ['docker', 'login'],
|
||||||
});
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// ===
|
// ===
|
||||||
// SSH
|
// SSH
|
||||||
// ===
|
// ===
|
||||||
Deno.test('should prepare SSH keys', async () => {
|
Deno.test('should prepare SSH keys', async () => {
|
||||||
const npmciModSsh = await import('../ts/mod_ssh/index.ts');
|
// Ensure test mode is set so we don't actually write to disk
|
||||||
await npmciModSsh.handleCli({
|
Deno.env.set('SZCI_TEST', 'true');
|
||||||
|
|
||||||
|
const szciModSsh = await import('../ts/mod_ssh/index.ts');
|
||||||
|
await szciModSsh.handleCli({
|
||||||
_: ['ssh', 'prepare'],
|
_: ['ssh', 'prepare'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -96,7 +133,12 @@ Deno.test('should prepare SSH keys', async () => {
|
|||||||
// ====
|
// ====
|
||||||
// node
|
// node
|
||||||
// ====
|
// ====
|
||||||
Deno.test('should install a certain version of node', async () => {
|
Deno.test({
|
||||||
|
name: 'should install a certain version of node',
|
||||||
|
// Allow resource leaks for this test since nvm creates background processes
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
fn: async () => {
|
||||||
const szciInstance = new Szci();
|
const szciInstance = new Szci();
|
||||||
await szciInstance.start();
|
await szciInstance.start();
|
||||||
await szciInstance.nodejsManager.handleCli({
|
await szciInstance.nodejsManager.handleCli({
|
||||||
@@ -108,6 +150,7 @@ Deno.test('should install a certain version of node', async () => {
|
|||||||
await szciInstance.nodejsManager.handleCli({
|
await szciInstance.nodejsManager.handleCli({
|
||||||
_: ['node', 'install', 'legacy'],
|
_: ['node', 'install', 'legacy'],
|
||||||
});
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Restore original working directory after all tests
|
// Restore original working directory after all tests
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class Dockerfile {
|
|||||||
public static async readDockerfiles(
|
public static async readDockerfiles(
|
||||||
szciDockerManagerRefArg: SzciDockerManager
|
szciDockerManagerRefArg: SzciDockerManager
|
||||||
): Promise<Dockerfile[]> {
|
): Promise<Dockerfile[]> {
|
||||||
const fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*');
|
const fileTree = await plugins.smartfile.fs.listFileTree(paths.getCwd(), 'Dockerfile*');
|
||||||
|
|
||||||
// create the Dockerfile array
|
// create the Dockerfile array
|
||||||
const readDockerfilesArray: Dockerfile[] = [];
|
const readDockerfilesArray: Dockerfile[] = [];
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
import * as plugins from './mod.plugins.ts';
|
import * as plugins from './mod.plugins.ts';
|
||||||
import * as paths from '../szci.paths.ts';
|
import * as paths from '../szci.paths.ts';
|
||||||
|
import { logger } from '../szci.logging.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cleans szci config files
|
* Cleans szci config files from the project directory
|
||||||
*/
|
*/
|
||||||
export let clean = async (): Promise<void> => {
|
export const clean = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
if (plugins.smartfile.fs.fileExistsSync(paths.SzciPackageConfig)) {
|
||||||
plugins.smartfile.fs.removeSync(paths.SzciPackageConfig);
|
plugins.smartfile.fs.removeSync(paths.SzciPackageConfig);
|
||||||
return;
|
logger.log('ok', 'Cleaned szci config files');
|
||||||
|
} else {
|
||||||
|
logger.log('info', 'No szci config files to clean');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.log('error', `Failed to clean config files: ${(error as Error).message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
import * as plugins from './mod.plugins.ts';
|
|
||||||
import { bash } from '../szci.bash.ts';
|
import { bash } from '../szci.bash.ts';
|
||||||
|
import { logger } from '../szci.logging.ts';
|
||||||
|
|
||||||
export let command = async () => {
|
/**
|
||||||
let wrappedCommand: string = '';
|
* Executes a wrapped command passed via CLI arguments.
|
||||||
let argvArray = ['deno', 'mod.ts', ...Deno.args];
|
* Usage: szci command <your-command-here>
|
||||||
for (let i = 3; i < argvArray.length; i++) {
|
*
|
||||||
wrappedCommand = wrappedCommand + argvArray[i];
|
* This allows running arbitrary commands through szci's bash wrapper
|
||||||
if (i + 1 !== argvArray.length) {
|
* which handles nvm and other environment setup.
|
||||||
wrappedCommand = wrappedCommand + ' ';
|
*/
|
||||||
}
|
export const command = async (): Promise<void> => {
|
||||||
|
// Skip 'deno', 'mod.ts', 'command' and get the rest
|
||||||
|
const commandArgs = Deno.args.slice(1); // Skip 'command'
|
||||||
|
|
||||||
|
if (commandArgs.length === 0) {
|
||||||
|
logger.log('error', 'No command specified. Usage: szci command <your-command>');
|
||||||
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wrappedCommand = commandArgs.join(' ');
|
||||||
|
logger.log('info', `Executing command: ${wrappedCommand}`);
|
||||||
|
|
||||||
|
try {
|
||||||
await bash(wrappedCommand);
|
await bash(wrappedCommand);
|
||||||
return;
|
logger.log('ok', 'Command executed successfully');
|
||||||
|
} catch (error) {
|
||||||
|
logger.log('error', `Command failed: ${(error as Error).message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
import { logger } from '../szci.logging.ts';
|
import { logger } from '../szci.logging.ts';
|
||||||
import * as plugins from './mod.plugins.ts';
|
import * as plugins from './mod.plugins.ts';
|
||||||
|
|
||||||
let sshInstance: plugins.smartssh.SshInstance;
|
let sshInstance: plugins.smartssh.SshInstance;
|
||||||
|
|
||||||
export let handleCli = async (argvArg: any) => {
|
/**
|
||||||
|
* Interface for CLI arguments
|
||||||
|
*/
|
||||||
|
interface ICliArgs {
|
||||||
|
_: string[];
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle SSH CLI commands
|
||||||
|
*/
|
||||||
|
export const handleCli = async (argvArg: ICliArgs): Promise<void> => {
|
||||||
if (argvArg._.length >= 2) {
|
if (argvArg._.length >= 2) {
|
||||||
const action: string = argvArg._[1];
|
const action = argvArg._[1];
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'prepare':
|
case 'prepare':
|
||||||
await prepare();
|
await prepare();
|
||||||
@@ -20,45 +32,66 @@ export let handleCli = async (argvArg: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if not undefined
|
* Checks if a string value is defined and not a placeholder
|
||||||
*/
|
*/
|
||||||
const notUndefined = (stringArg: string) => {
|
const isValidValue = (value: string | undefined): boolean => {
|
||||||
return stringArg && stringArg !== 'undefined' && stringArg !== '##';
|
return Boolean(value && value !== 'undefined' && value !== '##');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks for ENV vars in form of SZCI_SSHKEY_* and deploys any found ones
|
* Checks for ENV vars in form of SZCI_SSHKEY_* and deploys any found ones
|
||||||
*/
|
*/
|
||||||
export let prepare = async () => {
|
export const prepare = async (): Promise<void> => {
|
||||||
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
|
sshInstance = new plugins.smartssh.SshInstance();
|
||||||
plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'SZCI_SSHKEY_*', evaluateSshEnv);
|
|
||||||
if (!Deno.env.get("SZCI_TEST")) {
|
// Get all env vars and filter for SSH keys
|
||||||
|
const envVars = Deno.env.toObject();
|
||||||
|
const sshKeyEnvVars = Object.entries(envVars).filter(([key]) =>
|
||||||
|
key.startsWith('SZCI_SSHKEY_')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Process each SSH key env var
|
||||||
|
for (const [key, value] of sshKeyEnvVars) {
|
||||||
|
logger.log('info', `Processing SSH key from ${key}`);
|
||||||
|
addSshKeyFromEnvVar(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only write to disk if not in test mode
|
||||||
|
if (!Deno.env.get('SZCI_TEST')) {
|
||||||
|
try {
|
||||||
sshInstance.writeToDisk();
|
sshInstance.writeToDisk();
|
||||||
|
logger.log('ok', 'SSH keys written to disk');
|
||||||
|
} catch (error) {
|
||||||
|
logger.log('error', `Failed to write SSH keys: ${(error as Error).message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.log('info', 'In test mode, so not storing SSH keys to disk!');
|
logger.log('info', 'In test mode, so not storing SSH keys to disk!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets called for each found SSH ENV Var and deploys it
|
* Parses an SSH key env var and adds it to the SSH instance
|
||||||
|
* Format: host|privKeyBase64|pubKeyBase64
|
||||||
*/
|
*/
|
||||||
const evaluateSshEnv = async (sshkeyEnvVarArg: string) => {
|
const addSshKeyFromEnvVar = (sshkeyEnvVarArg: string): void => {
|
||||||
const sshEnvArray = sshkeyEnvVarArg.split('|');
|
const [host, privKeyBase64, pubKeyBase64] = sshkeyEnvVarArg.split('|');
|
||||||
const sshKey = new plugins.smartssh.SshKey();
|
const sshKey = new plugins.smartssh.SshKey();
|
||||||
logger.log('info', 'Found SSH identity for ' + sshEnvArray[1]);
|
|
||||||
if (notUndefined(sshEnvArray[0])) {
|
logger.log('info', `Found SSH identity for ${host || 'unknown host'}`);
|
||||||
|
|
||||||
|
if (isValidValue(host)) {
|
||||||
logger.log('info', '---> host defined!');
|
logger.log('info', '---> host defined!');
|
||||||
sshKey.host = sshEnvArray[0];
|
sshKey.host = host;
|
||||||
}
|
}
|
||||||
if (notUndefined(sshEnvArray[1])) {
|
if (isValidValue(privKeyBase64)) {
|
||||||
logger.log('info', '---> privKey defined!');
|
logger.log('info', '---> privKey defined!');
|
||||||
sshKey.privKeyBase64 = sshEnvArray[1];
|
sshKey.privKeyBase64 = privKeyBase64;
|
||||||
}
|
}
|
||||||
if (notUndefined(sshEnvArray[2])) {
|
if (isValidValue(pubKeyBase64)) {
|
||||||
logger.log('info', '---> pubKey defined!');
|
logger.log('info', '---> pubKey defined!');
|
||||||
sshKey.pubKeyBase64 = sshEnvArray[2];
|
sshKey.pubKeyBase64 = pubKeyBase64;
|
||||||
}
|
}
|
||||||
|
|
||||||
sshInstance.addKey(sshKey);
|
sshInstance.addKey(sshKey);
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,47 +1,101 @@
|
|||||||
import * as plugins from './mod.plugins.ts';
|
import * as plugins from './mod.plugins.ts';
|
||||||
import { bash } from '../szci.bash.ts';
|
|
||||||
import { logger } from '../szci.logging.ts';
|
import { logger } from '../szci.logging.ts';
|
||||||
|
|
||||||
const triggerValueRegex =
|
/**
|
||||||
/^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
* Interface for parsed trigger configuration
|
||||||
|
*/
|
||||||
|
interface ITriggerConfig {
|
||||||
|
domain: string;
|
||||||
|
projectId: string;
|
||||||
|
triggerToken: string;
|
||||||
|
refName: string;
|
||||||
|
triggerName: string;
|
||||||
|
}
|
||||||
|
|
||||||
export let trigger = async () => {
|
/**
|
||||||
|
* Regex to parse trigger env var format:
|
||||||
|
* domain|projectId|triggerToken|refName|triggerName (optional)
|
||||||
|
*/
|
||||||
|
const TRIGGER_VALUE_REGEX =
|
||||||
|
/^([a-zA-Z0-9.]+)\|([a-zA-Z0-9.]+)\|([a-zA-Z0-9.]+)\|([a-zA-Z0-9.]+)\|?([a-zA-Z0-9.\-/]*)$/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute all configured triggers from environment variables
|
||||||
|
*/
|
||||||
|
export const trigger = async (): Promise<void> => {
|
||||||
logger.log('info', 'now running triggers');
|
logger.log('info', 'now running triggers');
|
||||||
await plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'SZCI_TRIGGER_*', evaluateTrigger);
|
|
||||||
};
|
|
||||||
|
|
||||||
const evaluateTrigger = async (triggerEnvVarArg: string) => {
|
// Get all env vars and filter for triggers
|
||||||
const triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
const envVars = Deno.env.toObject();
|
||||||
if (!triggerRegexResultArray) {
|
const triggerEnvVars = Object.entries(envVars).filter(([key]) =>
|
||||||
logger.log('error', 'malformed trigger env var...');
|
key.startsWith('SZCI_TRIGGER_')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (triggerEnvVars.length === 0) {
|
||||||
|
logger.log('info', 'no triggers configured');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const regexDomain = triggerRegexResultArray[1];
|
|
||||||
const regexProjectId = triggerRegexResultArray[2];
|
// Process each trigger
|
||||||
const regexProjectTriggerToken = triggerRegexResultArray[3];
|
for (const [key, value] of triggerEnvVars) {
|
||||||
const regexRefName = triggerRegexResultArray[4];
|
logger.log('info', `Processing trigger from ${key}`);
|
||||||
let regexTriggerName: string;
|
await executeTrigger(value);
|
||||||
if (triggerRegexResultArray.length === 6) {
|
|
||||||
regexTriggerName = triggerRegexResultArray[5];
|
|
||||||
} else {
|
|
||||||
regexTriggerName = 'Unnamed Trigger';
|
|
||||||
}
|
}
|
||||||
logger.log('info', 'Found Trigger!');
|
|
||||||
logger.log('info', 'triggering build for ref ' + regexRefName + ' of ' + regexTriggerName);
|
logger.log('ok', `executed ${triggerEnvVars.length} trigger(s)`);
|
||||||
plugins.smartrequest.postFormData(
|
};
|
||||||
'https://gitlab.com/api/v3/projects/' + regexProjectId + '/trigger/builds',
|
|
||||||
|
/**
|
||||||
|
* Parse a trigger env var string into a config object
|
||||||
|
*/
|
||||||
|
const parseTriggerConfig = (triggerEnvVar: string): ITriggerConfig | null => {
|
||||||
|
const match = TRIGGER_VALUE_REGEX.exec(triggerEnvVar);
|
||||||
|
if (!match) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
domain: match[1],
|
||||||
|
projectId: match[2],
|
||||||
|
triggerToken: match[3],
|
||||||
|
refName: match[4],
|
||||||
|
triggerName: match[5] || 'Unnamed Trigger',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a single trigger by calling the GitLab API
|
||||||
|
*/
|
||||||
|
const executeTrigger = async (triggerEnvVar: string): Promise<void> => {
|
||||||
|
const config = parseTriggerConfig(triggerEnvVar);
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
logger.log('error', 'malformed trigger env var, expected format: domain|projectId|token|ref|name');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('info', `Found Trigger: ${config.triggerName}`);
|
||||||
|
logger.log('info', `Triggering build for ref "${config.refName}" of "${config.triggerName}"`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await plugins.smartrequest.postFormData(
|
||||||
|
`https://${config.domain}/api/v3/projects/${config.projectId}/trigger/builds`,
|
||||||
{},
|
{},
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name: 'token',
|
name: 'token',
|
||||||
payload: regexProjectTriggerToken,
|
payload: config.triggerToken,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ref',
|
name: 'ref',
|
||||||
payload: regexRefName,
|
payload: config.refName,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
logger.log('ok', `Trigger "${config.triggerName}" executed successfully`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.log('error', `Failed to execute trigger: ${(error as Error).message}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
import * as plugins from './szci.plugins.ts';
|
import * as plugins from './szci.plugins.ts';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current working directory (evaluated at call time, not module load time)
|
||||||
|
*/
|
||||||
|
export const getCwd = (): string => Deno.cwd();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current working directory - use getCwd() if you need the live value after chdir
|
||||||
|
* @deprecated Use getCwd() for dynamic cwd resolution
|
||||||
|
*/
|
||||||
export const cwd = Deno.cwd();
|
export const cwd = Deno.cwd();
|
||||||
|
|
||||||
// package paths
|
// package paths
|
||||||
@@ -9,7 +18,13 @@ export const SzciPackageRoot = plugins.path.join(
|
|||||||
);
|
);
|
||||||
export const SzciPackageConfig = plugins.path.join(SzciPackageRoot, './config.json');
|
export const SzciPackageConfig = plugins.path.join(SzciPackageRoot, './config.json');
|
||||||
|
|
||||||
// project paths
|
// project paths - use functions for dynamic resolution
|
||||||
|
export const getSzciProjectDir = (): string => getCwd();
|
||||||
|
export const getSzciProjectNogitDir = (): string => plugins.path.join(getCwd(), './.nogit');
|
||||||
|
export const getSzciTestDir = (): string => plugins.path.join(getCwd(), './test');
|
||||||
|
export const getSzciCacheDir = (): string => plugins.path.join(getCwd(), './.szci_cache');
|
||||||
|
|
||||||
|
// Static paths (for backwards compatibility - captured at module load)
|
||||||
export const SzciProjectDir = cwd;
|
export const SzciProjectDir = cwd;
|
||||||
export const SzciProjectNogitDir = plugins.path.join(SzciProjectDir, './.nogit');
|
export const SzciProjectNogitDir = plugins.path.join(SzciProjectDir, './.nogit');
|
||||||
export const SzciTestDir = plugins.path.join(cwd, './test');
|
export const SzciTestDir = plugins.path.join(cwd, './test');
|
||||||
|
|||||||
Reference in New Issue
Block a user