mirror of
https://github.com/gradle/actions.git
synced 2025-11-26 17:09:10 +08:00
Allow a task name to be specified for dependency-submission
Fixes: #125
This commit is contained in:
@@ -5,7 +5,13 @@ import * as gradle from '../execution/gradle'
|
||||
import * as dependencyGraph from '../dependency-graph'
|
||||
|
||||
import {parseArgsStringToArgv} from 'string-argv'
|
||||
import {BuildScanConfig, CacheConfig, DependencyGraphConfig, DependencyGraphOption} from '../input-params'
|
||||
import {
|
||||
BuildScanConfig,
|
||||
CacheConfig,
|
||||
DependencyGraphConfig,
|
||||
DependencyGraphOption,
|
||||
GradleExecutionConfig
|
||||
} from '../input-params'
|
||||
|
||||
/**
|
||||
* The main entry point for the action, called by Github Actions for the step.
|
||||
@@ -25,16 +31,22 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
// Only execute if arguments have been provided
|
||||
const additionalArgs = core.getInput('additional-arguments')
|
||||
const executionConfig = new GradleExecutionConfig()
|
||||
const taskList = executionConfig.getDependencyResolutionTask()
|
||||
const additionalArgs = executionConfig.getAdditionalArguments()
|
||||
const executionArgs = `
|
||||
-Dorg.gradle.configureondemand=false
|
||||
-Dorg.gradle.dependency.verification=off
|
||||
-Dorg.gradle.unsafe.isolated-projects=false
|
||||
:ForceDependencyResolutionPlugin_resolveAllDependencies
|
||||
${taskList}
|
||||
${additionalArgs}
|
||||
`
|
||||
const args: string[] = parseArgsStringToArgv(executionArgs)
|
||||
await gradle.provisionAndMaybeExecute(args)
|
||||
await gradle.provisionAndMaybeExecute(
|
||||
executionConfig.getGradleVersion(),
|
||||
executionConfig.getBuildRootDirectory(),
|
||||
args
|
||||
)
|
||||
|
||||
await dependencyGraph.complete(config)
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as path from 'path'
|
||||
|
||||
import * as params from '../input-params'
|
||||
import * as provisioner from './provision'
|
||||
import * as gradlew from './gradlew'
|
||||
import {getWorkspaceDirectory} from '../input-params'
|
||||
|
||||
export async function provisionAndMaybeExecute(args: string[]): Promise<void> {
|
||||
export async function provisionAndMaybeExecute(
|
||||
gradleVersion: string,
|
||||
buildRootDirectory: string,
|
||||
args: string[]
|
||||
): Promise<void> {
|
||||
// Download and install Gradle if required
|
||||
const executable = await provisioner.provisionGradle()
|
||||
const executable = await provisioner.provisionGradle(gradleVersion)
|
||||
|
||||
// Only execute if arguments have been provided
|
||||
if (args.length > 0) {
|
||||
await executeGradleBuild(executable, buildRootDirectory(), args)
|
||||
await executeGradleBuild(executable, buildRootDirectory, args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +31,3 @@ async function executeGradleBuild(executable: string | undefined, root: string,
|
||||
core.setFailed(`Gradle build failed: see console output for details`)
|
||||
}
|
||||
}
|
||||
|
||||
function buildRootDirectory(): string {
|
||||
const baseDirectory = getWorkspaceDirectory()
|
||||
const buildRootDirectoryInput = params.getBuildRootDirectory()
|
||||
const resolvedBuildRootDirectory =
|
||||
buildRootDirectoryInput === ''
|
||||
? path.resolve(baseDirectory)
|
||||
: path.resolve(baseDirectory, buildRootDirectoryInput)
|
||||
return resolvedBuildRootDirectory
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as cache from '@actions/cache'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
|
||||
import * as gradlew from './gradlew'
|
||||
import * as params from '../input-params'
|
||||
import {handleCacheFailure} from '../caching/cache-utils'
|
||||
import {CacheConfig} from '../input-params'
|
||||
|
||||
@@ -17,8 +16,7 @@ const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||
* Install any configured version of Gradle, adding the executable to the PATH.
|
||||
* @return Installed Gradle executable or undefined if no version configured.
|
||||
*/
|
||||
export async function provisionGradle(): Promise<string | undefined> {
|
||||
const gradleVersion = params.getGradleVersion()
|
||||
export async function provisionGradle(gradleVersion: string): Promise<string | undefined> {
|
||||
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
|
||||
return addToPath(await installGradle(gradleVersion))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as cache from '@actions/cache'
|
||||
import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary'
|
||||
|
||||
import {parseArgsStringToArgv} from 'string-argv'
|
||||
import path from 'path'
|
||||
|
||||
export class DependencyGraphConfig {
|
||||
getDependencyGraphOption(): DependencyGraphOption {
|
||||
@@ -218,17 +219,33 @@ export class BuildScanConfig {
|
||||
}
|
||||
}
|
||||
|
||||
export function getGradleVersion(): string {
|
||||
return core.getInput('gradle-version')
|
||||
}
|
||||
export class GradleExecutionConfig {
|
||||
getGradleVersion(): string {
|
||||
return core.getInput('gradle-version')
|
||||
}
|
||||
|
||||
export function getBuildRootDirectory(): string {
|
||||
return core.getInput('build-root-directory')
|
||||
}
|
||||
getBuildRootDirectory(): string {
|
||||
const baseDirectory = getWorkspaceDirectory()
|
||||
const buildRootDirectoryInput = core.getInput('build-root-directory')
|
||||
const resolvedBuildRootDirectory =
|
||||
buildRootDirectoryInput === ''
|
||||
? path.resolve(baseDirectory)
|
||||
: path.resolve(baseDirectory, buildRootDirectoryInput)
|
||||
return resolvedBuildRootDirectory
|
||||
}
|
||||
|
||||
export function getArguments(): string[] {
|
||||
const input = core.getInput('arguments')
|
||||
return parseArgsStringToArgv(input)
|
||||
getArguments(): string[] {
|
||||
const input = core.getInput('arguments')
|
||||
return parseArgsStringToArgv(input)
|
||||
}
|
||||
|
||||
getDependencyResolutionTask(): string {
|
||||
return core.getInput('dependency-resolution-task') || ':ForceDependencyResolutionPlugin_resolveAllDependencies'
|
||||
}
|
||||
|
||||
getAdditionalArguments(): string {
|
||||
return core.getInput('additional-arguments')
|
||||
}
|
||||
}
|
||||
|
||||
// Internal parameters
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as core from '@actions/core'
|
||||
import * as setupGradle from '../setup-gradle'
|
||||
import * as gradle from '../execution/gradle'
|
||||
import * as dependencyGraph from '../dependency-graph'
|
||||
import {BuildScanConfig, CacheConfig, DependencyGraphConfig, getArguments} from '../input-params'
|
||||
import {BuildScanConfig, CacheConfig, DependencyGraphConfig, GradleExecutionConfig} from '../input-params'
|
||||
|
||||
/**
|
||||
* The main entry point for the action, called by Github Actions for the step.
|
||||
@@ -16,8 +16,12 @@ export async function run(): Promise<void> {
|
||||
// Configure the dependency graph submission
|
||||
await dependencyGraph.setup(new DependencyGraphConfig())
|
||||
|
||||
const args: string[] = getArguments()
|
||||
await gradle.provisionAndMaybeExecute(args)
|
||||
const config = new GradleExecutionConfig()
|
||||
await gradle.provisionAndMaybeExecute(
|
||||
config.getGradleVersion(),
|
||||
config.getBuildRootDirectory(),
|
||||
config.getArguments()
|
||||
)
|
||||
} catch (error) {
|
||||
core.setFailed(String(error))
|
||||
if (error instanceof Error && error.stack) {
|
||||
|
||||
Reference in New Issue
Block a user