Convert dependency-submission action to Typescript

Instead of being a thin wrapper over `setup-gradle`, the `dependency-submission`
action is now a fully-fledged action sharing implementation with `setup-gradle`.
This commit is contained in:
daz
2024-04-06 16:35:03 -06:00
parent 4214607904
commit ebf4d13461
8 changed files with 299 additions and 35 deletions

View File

@@ -58,6 +58,11 @@ function maybeExportVariable(variableName: string, value: unknown): void {
}
export async function complete(option: DependencyGraphOption): Promise<void> {
if (isRunningInActEnvironment()) {
core.info('Dependency graph upload and submit not supported in the ACT environment.')
return
}
try {
switch (option) {
case DependencyGraphOption.Disabled:
@@ -96,6 +101,11 @@ async function uploadDependencyGraphs(dependencyGraphFiles: string[]): Promise<v
}
async function downloadAndSubmitDependencyGraphs(): Promise<void> {
if (isRunningInActEnvironment()) {
core.info('Dependency graph download and submit not supported in the ACT environment.')
return
}
try {
await submitDependencyGraphs(await downloadDependencyGraphs())
} catch (e) {
@@ -242,3 +252,7 @@ function sanitize(value: string): string {
.replace(/\s+/g, '_')
.toLowerCase()
}
function isRunningInActEnvironment(): boolean {
return process.env.ACT !== undefined
}

View File

@@ -0,0 +1,58 @@
import * as core from '@actions/core'
import * as setupGradle from '../setup-gradle'
import * as execution from '../execution'
import * as provisioner from '../provision'
import * as layout from '../repository-layout'
import {parseArgsStringToArgv} from 'string-argv'
import {DependencyGraphOption, getDependencyGraphOption} from '../input-params'
/**
* The main entry point for the action, called by Github Actions for the step.
*/
export async function run(): Promise<void> {
try {
if (process.env['GRADLE_BUILD_ACTION_SETUP_COMPLETED']) {
core.setFailed(
'The dependency-submission action cannot be used in the same Job as the setup-gradle action. Please use a separate Job for dependency submission.'
)
return
}
// Configure Gradle environment (Gradle User Home)
await setupGradle.setup()
if (getDependencyGraphOption() === DependencyGraphOption.DownloadAndSubmit) {
// No execution to perform
return
}
// Download and install Gradle if required
const executable = await provisioner.provisionGradle()
// Only execute if arguments have been provided
const additionalArgs = core.getInput('additional-arguments')
const executionArgs = `
-Dorg.gradle.configureondemand=false
-Dorg.gradle.dependency.verification=off
-Dorg.gradle.unsafe.isolated-projects=false
:ForceDependencyResolutionPlugin_resolveAllDependencies
${additionalArgs}
`
const args: string[] = parseArgsStringToArgv(executionArgs)
core.info(args.join('!!!'))
const buildRootDirectory = layout.buildRootDirectory()
await execution.executeGradleBuild(executable, buildRootDirectory, args)
} catch (error) {
core.setFailed(String(error))
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
}
// Explicit process.exit() to prevent waiting for hanging promises.
process.exit()
}
run()

View File

@@ -0,0 +1,35 @@
import * as core from '@actions/core'
import * as setupGradle from '../setup-gradle'
import {PostActionJobFailure} from '../errors'
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
process.on('uncaughtException', e => handleFailure(e))
/**
* The post-execution entry point for the action, called by Github Actions after completing all steps for the Job.
*/
export async function run(): Promise<void> {
try {
await setupGradle.complete()
} catch (error) {
if (error instanceof PostActionJobFailure) {
core.setFailed(String(error))
} else {
handleFailure(error)
}
}
// Explicit process.exit() to prevent waiting for promises left hanging by `@actions/cache` on save.
process.exit()
}
function handleFailure(error: unknown): void {
core.warning(`Unhandled error in Gradle post-action - job will continue: ${error}`)
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
}
run()