Skip to content
Open
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
1 change: 1 addition & 0 deletions src/configurator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lint: build
.PHONY: build
build:
docker build -t ${DOCKER_IMAGE} .
docker tag ${DOCKER_IMAGE} docker.pkg.github.com/dogmatic69/actions/configurator

.PHONY: publish
publish: build
Expand Down
42 changes: 30 additions & 12 deletions src/configurator/files/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

const libs = require('./libs');

const getConfig = (config, key) => (config && config[key] ? config[key] : null);
const getConfig = (config, key) => (config && config[key] !== 'undefined' ? config[key] : null);

module.exports = (configuration) => ({
name: configuration.name,
on: configuration.on,
env: configuration.env || {},
jobs: {

...libs.collector('Project Done', {
Expand All @@ -27,6 +28,7 @@ module.exports = (configuration) => ({
}),

...((config) => {
console.log('config: ', config)
if (config === false) {
return {};
}
Expand All @@ -51,6 +53,7 @@ module.exports = (configuration) => ({
}
return libs.job({
name: 'File Lint',
needs: config.needs || [],
steps: [
libs.checkout(),
...libs.fileChecks(config.checks),
Expand All @@ -66,6 +69,7 @@ module.exports = (configuration) => ({

return libs.job({
name: 'Git Lint',
needs: config.needs || [],
steps: [
libs.checkout(0),
...(config.checks || []).map((check) => ({
Expand All @@ -86,21 +90,23 @@ module.exports = (configuration) => ({
}
return libs.job({
name: 'Audit Trivy',
needs: config.needs || [],
strategy: {
matrix: config.matrix,
},
steps: [
libs.checkout(),
...(config.before || []),
libs.run('Build', [
'docker build -t ${{ matrix.image }} ./${{ matrix.image }}',
]),
config.build || 'docker build -t ${{ matrix.image }} ./${{ matrix.image }}'
], config.if),
{
name: 'Trivy Scan ${{ matrix.image }}',
uses: 'dogmatic69/actions/docker/audit/trivy@master',
if: config.if || true,
with: {
token: '${{ secrets.GITHUB_TOKEN }}',
image: '${{ matrix.image }}',
path: './${{ matrix.image }}',
},
},
],
Expand All @@ -113,6 +119,7 @@ module.exports = (configuration) => ({
}
return libs.job({
name: 'Dockerfile lint',
needs: config.needs || [],
steps: [
libs.checkout(),
{
Expand All @@ -127,15 +134,20 @@ module.exports = (configuration) => ({
if (!config) {
return {};
}
const checks = config.checks || [
libs.run('lint', 'make -C ${{ matrix.image }} lint'),
libs.run('test', 'make -C ${{ matrix.image }} test'),
];

return libs.job({
name: 'Project Checks',
needs: config.needs || [],
strategy: {
matrix: config.matrix,
},
steps: [
libs.checkout(),
libs.run('lint', 'make -C ${{ matrix.image }} lint'),
libs.run('test', 'make -C ${{ matrix.image }} test'),
...checks,
],
});
})(getConfig(configuration, 'project')),
Expand All @@ -147,6 +159,7 @@ module.exports = (configuration) => ({

return libs.job({
name: 'Project Checks TF',
needs: config.needs || [],
strategy: {
matrix: config.matrix,
},
Expand All @@ -165,16 +178,17 @@ module.exports = (configuration) => ({
const target = config.target || 'github';
const steps = [
libs.checkout(),
libs.run('fetch', 'git fetch'),
libs.fetch(),
...(config.before || []),
libs.fetch(config.if),
];

if (target === 'gcp') {
steps.push({
name: 'GCloud Setup',
if: config.if || true,
uses: 'GoogleCloudPlatform/github-actions/setup-gcloud@master',
with: {
version: config ? config['gcloud-version'] : null,
version: config['gcloud-version'] || '290.0.1',
service_account_email: '${{ secrets.GCP_SA_EMAIL }}',
service_account_key: '${{ secrets.GCP_SA_KEY }}',
export_default_credentials: true,
Expand All @@ -183,16 +197,20 @@ module.exports = (configuration) => ({
steps.push(libs.run('Docker Login', [
'echo "${{ secrets.GCP_SA_KEY }}" | base64 --decode |',
'docker login -u _json_key --password-stdin https://eu.gcr.io',
].join('\\\n')));
].join('\\\n'), config.if));
}

steps.push(
libs.run('Publish', `make -C \${{ matrix.service }} publish DOCKER_USER=\${{ github.actor }} DOCKER_TOKEN=\${{ secrets.GITHUB_TOKEN }} ENVIRONMENT=${config.environment || 'dev'}`),
libs.run(
'Publish',
config.publish || `make -C \${{ matrix.service }} publish DOCKER_USER=\${{ github.actor }} DOCKER_TOKEN=\${{ secrets.GITHUB_TOKEN }} ENVIRONMENT=${config.environment || 'dev'}`,
config.if
),
);

return libs.job({
name: 'Publish',
needs: ['all-done'],
needs: config.needs !== 'undefined' ? (config.needs || []) : ['all-done'],
strategy: {
matrix: config.matrix,
},
Expand Down
14 changes: 10 additions & 4 deletions src/configurator/files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ const extend = async (template) => {

const template = await extend(config);
const output = build(template);

output.name = (output.name || process.argv[2].replace('-', ' '));
await fs.writeFile(
`${process.env.ROOT_DIR}/.github/workflows/${process.argv[2]}.yml`,
yaml.safeDump(output),
);
try {
await fs.writeFile(
`${process.env.ROOT_DIR}/.github/workflows/${process.argv[2]}.yml`,
yaml.safeDump(output),
);
} catch(e) {
console.log(e);
return process.exit(1);
}
})();
12 changes: 9 additions & 3 deletions src/configurator/files/src/libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ module.exports = (() => {
});
};

self.run = (name, commands) => {
self.run = (name, commands, condition) => {
const run = Array.isArray(commands) ? commands : [commands];
run.push('');
return {

const ret = {
name,
run: run.join('\n'),
};

if (condition) {
ret.if = condition;
}
return ret;
};

self.checkout = (depth) => ({
Expand All @@ -44,7 +50,7 @@ module.exports = (() => {
},
});

self.fetch = () => self.run('Git Fetch', 'git fetch');
self.fetch = (condition) => self.run('Git Fetch', 'git fetch', condition);

self.fileChecks = (config) => Object.keys(config).map((name) => {
const conf = {
Expand Down