prototype fpm build with docker action
All checks were successful
Docker Build / docker-build (push) Successful in 1m9s

This commit is contained in:
David Hiendl 2023-12-24 14:46:48 +01:00
parent 83e68509ce
commit 126c9089bf
6 changed files with 79609 additions and 0 deletions

17
action.yml Normal file
View File

@ -0,0 +1,17 @@
name: 'Docker'
description: 'Build and publish docker images'
inputs:
fpm_args:
description: "list of args to pass to fpm"
default: ""
required: false
debug_log_github_context:
description: "Log github.context as JSON for debugging purposes"
default: "false"
runs:
using: "node20"
main: ./dist/index.js

61909
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

17574
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

38
package.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "docker",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"bundle": "npm run package",
"ci-test": "jest",
"format:write": "prettier --write **/*.js",
"format:check": "prettier --check **/*.js",
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
"package": "ncc build src/action.js",
"package:watch": "npm run package -- --watch",
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
"all": "npm run format:write && npm run lint && npm run test && npm run package"
},
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"information": "file:../information",
"js-base64": "^3.7.5"
},
"devDependencies": {
"@babel/core": "^7.23.5",
"@babel/eslint-parser": "^7.23.3",
"@babel/preset-env": "^7.23.5",
"@vercel/ncc": "^0.38.1",
"babel-preset-jest": "^29.6.3",
"eslint": "^8.54.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.0",
"jest": "^29.7.0",
"make-coverage-badge": "^1.2.0",
"prettier": "^3.1.0"
}
}

29
src/action.js Normal file
View File

@ -0,0 +1,29 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import * as action_information from 'information';
import {
executeFpmBuild,
isTrueString, prepareFpmArgs
} from './lib';
try {
if (isTrueString(core.getBooleanInput('debug_log_github_context'))) {
console.log(JSON.stringify(github.context, null, 2));
}
const information = action_information.collect_all(true, false);
const debug = isTrueString(process.env['ACTIONS_STEP_DEBUG']);
const fpmArgs = prepareFpmArgs();
if (debug) {
console.log('fpmArgs:', JSON.stringify(fpmArgs, null, 2));
}
executeFpmBuild(fpmArgs);
}
catch (error) {
console.log('Failed to fpm packages', error);
core.setFailed(error.message);
process.exit(1);
}

42
src/lib.js Normal file
View File

@ -0,0 +1,42 @@
import * as core from '@actions/core';
import child_process from 'child_process';
export function prepareFpmArgs() {
return '';
}
export function executeFpmBuild(computedFpmArgs) {
const userFpmArgs = core.getInput('fpm_args');
const dockerCmd = 'docker run --rm -i'
+ ' -v ' + process.cwd() + ':/workspace/source'
+ ' -w /workspace/source'
+ 'gitea.dhswt.de/actions/fpm:latest'
+ ' ' + computedFpmArgs
+ ' ' + userFpmArgs;
const proc = child_process.spawnSync(dockerCmd, {
shell: true,
stdio: 'inherit',
cwd : process.cwd()
});
if (proc.status != null && proc.status > 0) {
throw new Error('fpm build failed');
}
if (proc.error != null) {
throw proc.error;
}
}
function isNonEmptyStr(str) {
return str != null && str !== 'false' && str.length > 0;
}
export function isTrueString(str) {
return str === '1'
|| str === 'true'
|| str === 'True'
|| str === 'TRUE';
}