Unverified Commit 02d4f463 authored by Daz DeBoer's avatar Daz DeBoer
Browse files

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
parent b9684c0c
Loading
Loading
Loading
Loading
+6
Changes for action.yml: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -24,28 +24,34 @@ inputs:
  distributions-cache-enabled:
    description: Whether caching downloaded Gradle distributions is enabled or not, default to 'true'
    required: false
    default: true
  wrapper-cache-enabled:
    description: Whether caching wrapper installation is enabled or not, default to 'true'
    required: false
    default: true
    deprecationMessage: Replaced by 'distributions-cache-enabled' which enables caching for all downloaded Gradle distributions
  dependencies-cache-enabled:
    description: Whether caching dependencies is enabled or not, default to 'false'
    required: false
    default: false
  dependencies-cache-key:
    description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
    required: false
  dependencies-cache-exact:
    description: Whether to restore only if exact match, default to 'false'
    required: false
    default: false
  configuration-cache-enabled:
    description: Whether caching build configuration is enabled or not, default to 'false'
    required: false
    default: false
  configuration-cache-key:
    description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
    required: false
  configuration-cache-exact:
    description: Whether to restore only if exact match, default to 'false'
    required: false
    default: false

outputs:
  build-scan-url:
+2 −3
Changes for src/cache-configuration.ts: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import fs from 'fs'
import * as core from '@actions/core'
import * as cache from '@actions/cache'

import * as github from './github-utils'
import * as crypto from './crypto-utils'

import {inputCacheKeyGlobs, tryDeleteFiles} from './cache-dependencies'
@@ -22,7 +21,7 @@ export async function restoreCachedConfiguration(
    if (fs.existsSync(cachePath)) return
    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 hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
@@ -93,5 +92,5 @@ export async function cacheConfiguration(): Promise<void> {
}

function isConfigurationCacheDisabled(): boolean {
    return !github.inputBoolean('configuration-cache-enabled', false)
    return !core.getBooleanInput('configuration-cache-enabled')
}
+4 −5
Changes for src/cache-dependencies.ts: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import * as os from 'os'
import * as core from '@actions/core'
import * as cache from '@actions/cache'

import * as github from './github-utils'
import * as crypto from './crypto-utils'

const DEPENDENCIES_CACHE_PATH = 'DEPENDENCIES_CACHE_PATH'
@@ -21,7 +20,7 @@ export async function restoreCachedDependencies(
    if (fs.existsSync(cachePath)) return
    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 hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
@@ -104,12 +103,12 @@ export function tryDeleteFiles(filePaths: string[]): boolean {
}

function isDependenciesCacheDisabled(): boolean {
    return !github.inputBoolean('dependencies-cache-enabled', false)
    return !core.getBooleanInput('dependencies-cache-enabled')
}

export function inputCacheKeyGlobs(input: string): string[] {
    const inputValue = github.inputArrayOrNull(input)
    return inputValue
    const inputValue = core.getMultilineInput(input)
    return inputValue.length > 0
        ? inputValue
        : [
              '**/*.gradle',
+3 −9
Changes for src/cache-wrapper.ts: 3 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -5,8 +5,6 @@ import * as os from 'os'
import * as core from '@actions/core'
import * as cache from '@actions/cache'

import * as github from './github-utils'

const WRAPPER_SLUG = 'WRAPPER_SLUG'

export async function restoreCachedWrapperDist(
@@ -108,13 +106,9 @@ export function extractGradleWrapperSlugFromDistUri(

function isWrapperCacheDisabled(): boolean {
    // Check if either 'distributions' or 'wrapper' cache has been disabled
    const wrapperCacheEnabled = github.inputBoolean(
        'wrapper-cache-enabled',
        true
    )
    const distributionsCacheEnabled = github.inputBoolean(
        'distributions-cache-enabled',
        true
    const wrapperCacheEnabled = core.getBooleanInput('wrapper-cache-enabled')
    const distributionsCacheEnabled = core.getBooleanInput(
        'distributions-cache-enabled'
    )
    return !wrapperCacheEnabled || !distributionsCacheEnabled
}
−24

File deleted.

Loading