mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 09:02:50 +00:00
Extract github actions utils
This commit is contained in:
parent
059f2e7791
commit
fcc1683d01
2 changed files with 15 additions and 13 deletions
9
src/github-utils.ts
Normal file
9
src/github-utils.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import * as core from '@actions/core'
|
||||
|
||||
export function inputOrNull(name: string): string | null {
|
||||
const inputString = core.getInput(name, {required: false})
|
||||
if (inputString.length === 0) {
|
||||
return null
|
||||
}
|
||||
return inputString
|
||||
}
|
19
src/main.ts
19
src/main.ts
|
@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
|||
import * as path from 'path'
|
||||
import {parseArgsStringToArgv} from 'string-argv'
|
||||
|
||||
import * as github from './github-utils'
|
||||
import * as cacheWrapper from './cache-wrapper'
|
||||
import * as execution from './execution'
|
||||
import * as gradlew from './gradlew'
|
||||
|
@ -33,12 +34,12 @@ export async function run(): Promise<void> {
|
|||
run()
|
||||
|
||||
async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
||||
const gradleVersion = inputOrNull('gradle-version')
|
||||
const gradleVersion = github.inputOrNull('gradle-version')
|
||||
if (gradleVersion !== null && gradleVersion !== 'wrapper') {
|
||||
return path.resolve(await provision.gradleVersion(gradleVersion))
|
||||
}
|
||||
|
||||
const gradleExecutable = inputOrNull('gradle-executable')
|
||||
const gradleExecutable = github.inputOrNull('gradle-executable')
|
||||
if (gradleExecutable !== null) {
|
||||
if (gradleExecutable.endsWith(gradlew.wrapperFilename())) {
|
||||
await cacheWrapper.restoreCachedWrapperDist(
|
||||
|
@ -48,7 +49,7 @@ async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
|||
return path.resolve(baseDirectory, gradleExecutable)
|
||||
}
|
||||
|
||||
const wrapperDirectory = inputOrNull('wrapper-directory')
|
||||
const wrapperDirectory = github.inputOrNull('wrapper-directory')
|
||||
const gradlewDirectory =
|
||||
wrapperDirectory !== null
|
||||
? path.join(baseDirectory, wrapperDirectory)
|
||||
|
@ -60,7 +61,7 @@ async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
|||
}
|
||||
|
||||
function resolveBuildRootDirectory(baseDirectory: string): string {
|
||||
const buildRootDirectory = inputOrNull('build-root-directory')
|
||||
const buildRootDirectory = github.inputOrNull('build-root-directory')
|
||||
const resolvedBuildRootDirectory =
|
||||
buildRootDirectory === null
|
||||
? path.resolve(baseDirectory)
|
||||
|
@ -69,14 +70,6 @@ function resolveBuildRootDirectory(baseDirectory: string): string {
|
|||
}
|
||||
|
||||
function parseCommandLineArguments(): string[] {
|
||||
const input = inputOrNull('arguments')
|
||||
const input = github.inputOrNull('arguments')
|
||||
return input === null ? [] : parseArgsStringToArgv(input)
|
||||
}
|
||||
|
||||
function inputOrNull(name: string): string | null {
|
||||
const inputString = core.getInput(name)
|
||||
if (inputString.length === 0) {
|
||||
return null
|
||||
}
|
||||
return inputString
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue