mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-25 17:51:02 -05:00
Use core functionality to access action inputs
- Specify default values in action.yaml definition where appropriate - Replace custom methods with core functions: - getInputBoolean() with core.getBooleanInput() - inputOrNull() with core.getInput() - inputArrayOrNull() with core.getMultilineInput() - Remove github-utils.js
This commit is contained in:
parent
b9684c0cf5
commit
02d4f46354
7 changed files with 26 additions and 54 deletions
|
@ -24,28 +24,34 @@ inputs:
|
||||||
distributions-cache-enabled:
|
distributions-cache-enabled:
|
||||||
description: Whether caching downloaded Gradle distributions is enabled or not, default to 'true'
|
description: Whether caching downloaded Gradle distributions is enabled or not, default to 'true'
|
||||||
required: false
|
required: false
|
||||||
|
default: true
|
||||||
wrapper-cache-enabled:
|
wrapper-cache-enabled:
|
||||||
description: Whether caching wrapper installation is enabled or not, default to 'true'
|
description: Whether caching wrapper installation is enabled or not, default to 'true'
|
||||||
required: false
|
required: false
|
||||||
|
default: true
|
||||||
deprecationMessage: Replaced by 'distributions-cache-enabled' which enables caching for all downloaded Gradle distributions
|
deprecationMessage: Replaced by 'distributions-cache-enabled' which enables caching for all downloaded Gradle distributions
|
||||||
dependencies-cache-enabled:
|
dependencies-cache-enabled:
|
||||||
description: Whether caching dependencies is enabled or not, default to 'false'
|
description: Whether caching dependencies is enabled or not, default to 'false'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
dependencies-cache-key:
|
dependencies-cache-key:
|
||||||
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
||||||
required: false
|
required: false
|
||||||
dependencies-cache-exact:
|
dependencies-cache-exact:
|
||||||
description: Whether to restore only if exact match, default to 'false'
|
description: Whether to restore only if exact match, default to 'false'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
configuration-cache-enabled:
|
configuration-cache-enabled:
|
||||||
description: Whether caching build configuration is enabled or not, default to 'false'
|
description: Whether caching build configuration is enabled or not, default to 'false'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
configuration-cache-key:
|
configuration-cache-key:
|
||||||
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
||||||
required: false
|
required: false
|
||||||
configuration-cache-exact:
|
configuration-cache-exact:
|
||||||
description: Whether to restore only if exact match, default to 'false'
|
description: Whether to restore only if exact match, default to 'false'
|
||||||
required: false
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
build-scan-url:
|
build-scan-url:
|
||||||
|
|
|
@ -4,7 +4,6 @@ import fs from 'fs'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
|
|
||||||
import * as github from './github-utils'
|
|
||||||
import * as crypto from './crypto-utils'
|
import * as crypto from './crypto-utils'
|
||||||
|
|
||||||
import {inputCacheKeyGlobs, tryDeleteFiles} from './cache-dependencies'
|
import {inputCacheKeyGlobs, tryDeleteFiles} from './cache-dependencies'
|
||||||
|
@ -22,7 +21,7 @@ export async function restoreCachedConfiguration(
|
||||||
if (fs.existsSync(cachePath)) return
|
if (fs.existsSync(cachePath)) return
|
||||||
core.saveState(CONFIGURATION_CACHE_PATH, cachePath)
|
core.saveState(CONFIGURATION_CACHE_PATH, cachePath)
|
||||||
|
|
||||||
const inputCacheExact = github.inputBoolean('configuration-cache-exact')
|
const inputCacheExact = core.getBooleanInput('configuration-cache-exact')
|
||||||
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
|
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
|
||||||
|
|
||||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||||
|
@ -93,5 +92,5 @@ export async function cacheConfiguration(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isConfigurationCacheDisabled(): boolean {
|
function isConfigurationCacheDisabled(): boolean {
|
||||||
return !github.inputBoolean('configuration-cache-enabled', false)
|
return !core.getBooleanInput('configuration-cache-enabled')
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as os from 'os'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
|
|
||||||
import * as github from './github-utils'
|
|
||||||
import * as crypto from './crypto-utils'
|
import * as crypto from './crypto-utils'
|
||||||
|
|
||||||
const DEPENDENCIES_CACHE_PATH = 'DEPENDENCIES_CACHE_PATH'
|
const DEPENDENCIES_CACHE_PATH = 'DEPENDENCIES_CACHE_PATH'
|
||||||
|
@ -21,7 +20,7 @@ export async function restoreCachedDependencies(
|
||||||
if (fs.existsSync(cachePath)) return
|
if (fs.existsSync(cachePath)) return
|
||||||
core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)
|
core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)
|
||||||
|
|
||||||
const inputCacheExact = github.inputBoolean('dependencies-cache-exact')
|
const inputCacheExact = core.getBooleanInput('dependencies-cache-exact')
|
||||||
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
|
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
|
||||||
|
|
||||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||||
|
@ -104,12 +103,12 @@ export function tryDeleteFiles(filePaths: string[]): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDependenciesCacheDisabled(): boolean {
|
function isDependenciesCacheDisabled(): boolean {
|
||||||
return !github.inputBoolean('dependencies-cache-enabled', false)
|
return !core.getBooleanInput('dependencies-cache-enabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function inputCacheKeyGlobs(input: string): string[] {
|
export function inputCacheKeyGlobs(input: string): string[] {
|
||||||
const inputValue = github.inputArrayOrNull(input)
|
const inputValue = core.getMultilineInput(input)
|
||||||
return inputValue
|
return inputValue.length > 0
|
||||||
? inputValue
|
? inputValue
|
||||||
: [
|
: [
|
||||||
'**/*.gradle',
|
'**/*.gradle',
|
||||||
|
|
|
@ -5,8 +5,6 @@ import * as os from 'os'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
|
|
||||||
import * as github from './github-utils'
|
|
||||||
|
|
||||||
const WRAPPER_SLUG = 'WRAPPER_SLUG'
|
const WRAPPER_SLUG = 'WRAPPER_SLUG'
|
||||||
|
|
||||||
export async function restoreCachedWrapperDist(
|
export async function restoreCachedWrapperDist(
|
||||||
|
@ -108,13 +106,9 @@ export function extractGradleWrapperSlugFromDistUri(
|
||||||
|
|
||||||
function isWrapperCacheDisabled(): boolean {
|
function isWrapperCacheDisabled(): boolean {
|
||||||
// Check if either 'distributions' or 'wrapper' cache has been disabled
|
// Check if either 'distributions' or 'wrapper' cache has been disabled
|
||||||
const wrapperCacheEnabled = github.inputBoolean(
|
const wrapperCacheEnabled = core.getBooleanInput('wrapper-cache-enabled')
|
||||||
'wrapper-cache-enabled',
|
const distributionsCacheEnabled = core.getBooleanInput(
|
||||||
true
|
'distributions-cache-enabled'
|
||||||
)
|
|
||||||
const distributionsCacheEnabled = github.inputBoolean(
|
|
||||||
'distributions-cache-enabled',
|
|
||||||
true
|
|
||||||
)
|
)
|
||||||
return !wrapperCacheEnabled || !distributionsCacheEnabled
|
return !wrapperCacheEnabled || !distributionsCacheEnabled
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inputArrayOrNull(name: string): string[] | null {
|
|
||||||
const string = inputOrNull(name)
|
|
||||||
if (!string) return null
|
|
||||||
return string
|
|
||||||
.split('\n')
|
|
||||||
.map(s => s.trim())
|
|
||||||
.filter(s => s !== '')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inputBoolean(name: string, defaultValue = false): boolean {
|
|
||||||
const string = inputOrNull(name)
|
|
||||||
if (!string) return defaultValue
|
|
||||||
return string === 'true'
|
|
||||||
}
|
|
21
src/main.ts
21
src/main.ts
|
@ -2,7 +2,6 @@ import * as core from '@actions/core'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {parseArgsStringToArgv} from 'string-argv'
|
import {parseArgsStringToArgv} from 'string-argv'
|
||||||
|
|
||||||
import * as github from './github-utils'
|
|
||||||
import * as cacheWrapper from './cache-wrapper'
|
import * as cacheWrapper from './cache-wrapper'
|
||||||
import * as execution from './execution'
|
import * as execution from './execution'
|
||||||
import * as gradlew from './gradlew'
|
import * as gradlew from './gradlew'
|
||||||
|
@ -41,13 +40,13 @@ async function resolveGradleExecutable(
|
||||||
workspaceDirectory: string,
|
workspaceDirectory: string,
|
||||||
buildRootDirectory: string
|
buildRootDirectory: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const gradleVersion = github.inputOrNull('gradle-version')
|
const gradleVersion = core.getInput('gradle-version')
|
||||||
if (gradleVersion !== null && gradleVersion !== 'wrapper') {
|
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
|
||||||
return path.resolve(await provision.gradleVersion(gradleVersion))
|
return path.resolve(await provision.gradleVersion(gradleVersion))
|
||||||
}
|
}
|
||||||
|
|
||||||
const gradleExecutable = github.inputOrNull('gradle-executable')
|
const gradleExecutable = core.getInput('gradle-executable')
|
||||||
if (gradleExecutable !== null) {
|
if (gradleExecutable !== '') {
|
||||||
if (gradleExecutable.endsWith(gradlew.wrapperFilename())) {
|
if (gradleExecutable.endsWith(gradlew.wrapperFilename())) {
|
||||||
await cacheWrapper.restoreCachedWrapperDist(
|
await cacheWrapper.restoreCachedWrapperDist(
|
||||||
path.resolve(gradleExecutable, '..')
|
path.resolve(gradleExecutable, '..')
|
||||||
|
@ -56,9 +55,9 @@ async function resolveGradleExecutable(
|
||||||
return path.resolve(workspaceDirectory, gradleExecutable)
|
return path.resolve(workspaceDirectory, gradleExecutable)
|
||||||
}
|
}
|
||||||
|
|
||||||
const wrapperDirectory = github.inputOrNull('wrapper-directory')
|
const wrapperDirectory = core.getInput('wrapper-directory')
|
||||||
const gradlewDirectory =
|
const gradlewDirectory =
|
||||||
wrapperDirectory !== null
|
wrapperDirectory !== ''
|
||||||
? path.resolve(workspaceDirectory, wrapperDirectory)
|
? path.resolve(workspaceDirectory, wrapperDirectory)
|
||||||
: buildRootDirectory
|
: buildRootDirectory
|
||||||
|
|
||||||
|
@ -69,15 +68,15 @@ async function resolveGradleExecutable(
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveBuildRootDirectory(baseDirectory: string): string {
|
function resolveBuildRootDirectory(baseDirectory: string): string {
|
||||||
const buildRootDirectory = github.inputOrNull('build-root-directory')
|
const buildRootDirectory = core.getInput('build-root-directory')
|
||||||
const resolvedBuildRootDirectory =
|
const resolvedBuildRootDirectory =
|
||||||
buildRootDirectory === null
|
buildRootDirectory === ''
|
||||||
? path.resolve(baseDirectory)
|
? path.resolve(baseDirectory)
|
||||||
: path.resolve(baseDirectory, buildRootDirectory)
|
: path.resolve(baseDirectory, buildRootDirectory)
|
||||||
return resolvedBuildRootDirectory
|
return resolvedBuildRootDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCommandLineArguments(): string[] {
|
function parseCommandLineArguments(): string[] {
|
||||||
const input = github.inputOrNull('arguments')
|
const input = core.getInput('arguments')
|
||||||
return input === null ? [] : parseArgsStringToArgv(input)
|
return parseArgsStringToArgv(input)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import * as cache from '@actions/cache'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
|
|
||||||
import * as gradlew from './gradlew'
|
import * as gradlew from './gradlew'
|
||||||
import * as github from './github-utils'
|
|
||||||
|
|
||||||
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ async function httpGetString(url: string): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDistributionsCacheDisabled(): boolean {
|
function isDistributionsCacheDisabled(): boolean {
|
||||||
return !github.inputBoolean('distributions-cache-enabled', true)
|
return !core.getBooleanInput('distributions-cache-enabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GradleVersionInfo {
|
interface GradleVersionInfo {
|
||||||
|
|
Loading…
Reference in a new issue