diff --git a/.github/workflows/publish_executables.yml b/.github/workflows/publish_executables.yml new file mode 100644 index 0000000..ba4cb1e --- /dev/null +++ b/.github/workflows/publish_executables.yml @@ -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/* \ No newline at end of file diff --git a/cli/maven-dependency-submission-linux-x64 b/cli/maven-dependency-submission-linux-x64 deleted file mode 100755 index 43119c0..0000000 Binary files a/cli/maven-dependency-submission-linux-x64 and /dev/null differ diff --git a/package.json b/package.json index eafcde3..6dba631 100644 --- a/package.json +++ b/package.json @@ -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" } -} +} \ No newline at end of file diff --git a/src/executable/cli.ts b/src/executable/cli.ts index aa43fb6..6a0067b 100644 --- a/src/executable/cli.ts +++ b/src/executable/cli.ts @@ -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 ', 'GitHub access token'); program.requiredOption('-r --repository ', 'GitHub repository, owner/repo_name format'); -program.requiredOption('-b --branch-ref ', 'GitHub repository branch reference, e.g. /refs/heads/main'); +program.requiredOption('-b --branch-ref ', 'GitHub repository branch reference, e.g. refs/heads/main'); program.requiredOption('-s --sha ', 'GitHub repository commit SHA'); program.option('-d --directory ', 'the directory containing the Maven POM file', '.'); +program.option('--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 ', 'additional arguments to pass to Maven'); program.option('--github-api-url ', 'GitHub API URL', 'https://api.github.com'); program.option('-j --job-name ', 'Optional name for the activity creating and submitting the graph', 'maven-dependency-submission-cli'); program.option('-i --run-id ', '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);