Updating building of executables to use pkg

This commit is contained in:
Peter Murray
2022-10-26 18:04:32 +00:00
committed by GitHub
parent ebac6e3727
commit 5cadb03be1
4 changed files with 73 additions and 16 deletions
+24
View File
@@ -0,0 +1,24 @@
name: Publish Executables
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build executables
run: |
npm run base-build
npm run build-exe
- name: Attach artifacts
uses: actions/upload-artifacts@v3
with:
name: executables
path: cli/*
Binary file not shown.
+18 -4
View File
@@ -1,13 +1,12 @@
{
"name": "maven-dependency-tree-action",
"name": "maven-dependency-tree-submission",
"version": "3.0.0",
"description": "",
"main": "index.js",
"scripts": {
"base-build": "npm ci && tsc",
"build": "npm run base-build && npm exec -- @vercel/ncc build --source-map lib/src/index.js",
"pre-build-exe": "npm run base-build && npm exec -- @vercel/ncc build lib/src/executable/cli.js -o runtime",
"build-exe-linux-x64": "npm run pre-build-exe && nexe -i runtime/index.js -t linux-x64-14.15.3 -o cli/maven-dependency-submission-linux-x64",
"build-exe": "pkg package.json --compress Gzip",
"test": "jest"
},
"repository": {
@@ -33,9 +32,24 @@
"@vercel/ncc": "^0.34.0",
"chai": "^4.3.6",
"jest": "^28.1.3",
"nexe": "^4.0.0-rc.1",
"pkg": "^5.8.0",
"ts-jest": "^28.0.7",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"bin": {
"cli": "lib/src/executable/cli.js"
},
"pkg": {
"targets": [
"node16-linux-x64",
"node16-win-x64",
"node16-macos-x64"
],
"assets": [
"package.json"
],
"publicPackages": "*",
"outputPath": "cli"
}
}
+30 -11
View File
@@ -1,31 +1,45 @@
import { Snapshot, submitSnapshot } from '@github/dependency-submission-toolkit';
import { generateSnapshot } from '../snapshot-generator';
import pkg from '../../package.json';
const { program } = require('commander');
program.name('maven-dependency-submission');
program.name(pkg.name);
program.version(pkg.version);
program.requiredOption('-t, --token <token>', 'GitHub access token');
program.requiredOption('-r --repository <repository>', 'GitHub repository, owner/repo_name format');
program.requiredOption('-b --branch-ref <ref>', 'GitHub repository branch reference, e.g. /refs/heads/main');
program.requiredOption('-b --branch-ref <ref>', 'GitHub repository branch reference, e.g. refs/heads/main');
program.requiredOption('-s --sha <commitSha>', 'GitHub repository commit SHA');
program.option('-d --directory <maven-project-directory>', 'the directory containing the Maven POM file', '.');
program.option('--settings-file <settings-file>', 'path to the Maven settings file');
program.option('--ignore-maven-wrapper', 'ingore Maven wrappers, if present, and use Maven from the PATH');
program.option('--maven-args <maven-args>', 'additional arguments to pass to Maven');
program.option('--github-api-url <url>', 'GitHub API URL', 'https://api.github.com');
program.option('-j --job-name <jobName>', 'Optional name for the activity creating and submitting the graph', 'maven-dependency-submission-cli');
program.option('-i --run-id <jobName>', 'Optional Run ID number for the activity that is providing the graph');
program.parse(process.argv);
const opts = program.opts();
// Inject some required environment variables like the Actions INPUTs and special environment variables
process.env['INPUT_TOKEN'] = opts.token;
process.env['GITHUB_REPOSITORY'] = opts.repository;
process.env['GITHUB_API_URL'] = opts.githubApiUrl;
// The above injection of environment variables is required before the submission APIs are imported
import { Snapshot, submitSnapshot } from '@github/dependency-submission-toolkit';
import { generateSnapshot } from '../snapshot-generator';
async function execute() {
const opts = program.opts();
// Inject some required environment variables like the Actions INPUTs and special environment variables
process.env['INPUT_TOKEN'] = opts.token;
process.env['GITHUB_REPOSITORY'] = opts.repository;
let snapshot: Snapshot | undefined;
// The dependency submission API requires a formatted ref reference so check early fo now
if (`/^refs\//`.match(opts.branchRef) === null) {
console.error(`Branch reference must be in path form, e.g. 'refs/heads/main' for the 'main' branch.`);
program.help({ error: true });
process.exit(1);
}
try {
// Build a fake GitHub Actions context so that values for the submission APIs can be retrieved
const context = {
@@ -38,7 +52,12 @@ async function execute() {
id: `${opts.runId || Date.now()}`
};
const mvnConfig = {};
const mvnConfig = {
directory: opts.directory,
settingsFile: opts.settingsFile,
ignoreMavenWrapper: opts.ignoreMavenWrapper,
mavenArgs: opts.mavenArgs
};
snapshot = await generateSnapshot(opts.directory, mvnConfig, context, job);