118 lines
3.2 KiB
JavaScript
Executable File
118 lines
3.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const fs = require('fs');
|
|
const yaml = require('js-yaml');
|
|
const logger = require('winston');
|
|
|
|
let essentials = yaml.safeLoad(fs.readFileSync('./essentials.yaml'));
|
|
let uc = JSON.parse(fs.readFileSync('./update-center.json'));
|
|
|
|
let ingest = {
|
|
timestamp: (new Date()).toISOString(),
|
|
core: {
|
|
url: 'http://mirrors.jenkins.io/war/latest/jenkins.war',
|
|
checksum: {
|
|
type: 'sha256',
|
|
signature: 'latest',
|
|
}
|
|
},
|
|
plugins: [
|
|
/*
|
|
* Hard-coding configuration as code until it hits the main update center
|
|
*/
|
|
{
|
|
groupId: 'org.jenkins-ci.plugins',
|
|
artifactId: 'configuration-as-code',
|
|
url: 'https://repo.jenkins-ci.org/incrementals/io/jenkins/configuration-as-code/0.11-alpha-rc362.942711740b07/configuration-as-code-0.11-alpha-rc362.942711740b07.hpi',
|
|
checksum: {
|
|
type: 'sha512',
|
|
signature: '4faefcc46299557efaa1c896835a2413ad0646201e40938b4207dbd4cfecf33303cf5f28fd1f53cb71146c45d12c7fa34d2d87d312acf9fd7964c08506d2278d',
|
|
},
|
|
},
|
|
{
|
|
groupId: 'io.jenkins.plugins',
|
|
artifactId: 'essentials',
|
|
url: 'https://repo.jenkins-ci.org/incrementals/io/jenkins/plugins/essentials/0.3-rc22.db3e99966ef0/essentials-0.3-rc22.db3e99966ef0.hpi',
|
|
checksum: {
|
|
type: 'sha512',
|
|
signature: 'e1cdf271eabed428c2198c4f7a49c5dea7fc8850987bcf63b87b74936a3cc426896a4b7c9c974f0fe3abd61071ea5a2238538af9f9266f2d37696856809d697a',
|
|
},
|
|
},
|
|
],
|
|
environments: {
|
|
},
|
|
};
|
|
|
|
/*
|
|
* Recursively grab the non-optional dependencies
|
|
*/
|
|
let resolveFor = function(pluginName, graph) {
|
|
let depends = [];
|
|
graph.plugins[pluginName].dependencies.forEach((dependency) => {
|
|
if (!dependency.optional) {
|
|
depends.push(dependency.name);
|
|
resolveFor(dependency.name, graph).forEach(d => depends.push(d));
|
|
}
|
|
});
|
|
// de-duplicate
|
|
return [...new Set(depends)];
|
|
};
|
|
|
|
/*
|
|
* Convert a given plugin name to the ingest.yaml representation of it
|
|
*/
|
|
let pluginToRecord = function(plugin, graph) {
|
|
let gav = graph.plugins[plugin].gav;
|
|
return {
|
|
groupId: gav.split(':', 1)[0],
|
|
artifactId: plugin,
|
|
url: graph.plugins[plugin].url,
|
|
checksum: {
|
|
type: 'sha256',
|
|
signature: graph.plugins[plugin].sha256,
|
|
},
|
|
};
|
|
};
|
|
|
|
/*
|
|
* Populate the foundational plugins
|
|
*/
|
|
let plugins = [];
|
|
essentials.spec.plugins.forEach((plugin) => {
|
|
let name = plugin.artifactId;
|
|
if (uc.plugins[name]) {
|
|
logger.info(`Processing dependencies for ${name}`);
|
|
plugins.push(name);
|
|
resolveFor(name, uc).forEach(p => plugins.push(p));
|
|
}
|
|
});
|
|
plugins = [...new Set(plugins)];
|
|
plugins.forEach((plugin) => {
|
|
ingest.plugins.push(pluginToRecord(plugin, uc));
|
|
});
|
|
|
|
/*
|
|
* Handle the environments
|
|
*/
|
|
essentials.spec.environments.forEach((env) => {
|
|
let record = {
|
|
plugins: [],
|
|
};
|
|
|
|
env.plugins.forEach((plugin) => {
|
|
record.plugins.push(pluginToRecord(plugin.artifactId, uc));
|
|
resolveFor(plugin.artifactId, uc).forEach((envPluginName) => {
|
|
if (!plugins.includes(envPluginName)) {
|
|
record.plugins.push(pluginToRecord(envPluginName, uc));
|
|
}
|
|
});
|
|
});
|
|
record.plugins = [...new Set(record.plugins)];
|
|
|
|
ingest.environments[env.name] = record;
|
|
});
|
|
|
|
fs.writeFileSync('ingest.json', JSON.stringify(ingest, undefined, 2));
|
|
|
|
// vim: ft=javascript
|