mirror of
				https://github.com/actions/checkout.git
				synced 2025-11-04 04:44:21 +08:00 
			
		
		
		
	* Add support for sparse checkouts * sparse-checkout: optionally turn off cone mode While it _is_ true that cone mode is the default nowadays (mainly for performance reasons: code mode is much faster than non-cone mode), there _are_ legitimate use cases where non-cone mode is really useful. Let's add a flag to optionally disable cone mode. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> * Verify minimum Git version for sparse checkout The `git sparse-checkout` command is available only since Git version v2.25.0. The `actions/checkout` Action actually supports older Git versions than that; As of time of writing, the minimum version is v2.18.0. Instead of raising this minimum version even for users who do not require a sparse checkout, only check for this minimum version specifically when a sparse checkout was asked for. Suggested-by: Tingluo Huang <tingluohuang@github.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> * Support sparse checkout/LFS better Instead of fetching all the LFS objects present in the current revision in a sparse checkout, whether they are needed inside the sparse cone or not, let's instead only pull the ones that are actually needed. To do that, let's avoid running that preemptive `git lfs fetch` call in case of a sparse checkout. An alternative that was considered during the development of this patch (and ultimately rejected) was to use `git lfs pull --include <path>...`, but it turned out to be too inflexible because it requires exact paths, not the patterns that are available via the sparse checkout definition, and that risks running into command-line length limitations. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --------- Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Co-authored-by: Daniel <daniel.fernandez@feverup.com>
		
			
				
	
	
		
			146 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			146 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import * as core from '@actions/core'
 | 
						|
import * as fsHelper from './fs-helper'
 | 
						|
import * as github from '@actions/github'
 | 
						|
import * as path from 'path'
 | 
						|
import * as workflowContextHelper from './workflow-context-helper'
 | 
						|
import {IGitSourceSettings} from './git-source-settings'
 | 
						|
 | 
						|
export async function getInputs(): Promise<IGitSourceSettings> {
 | 
						|
  const result = ({} as unknown) as IGitSourceSettings
 | 
						|
 | 
						|
  // GitHub workspace
 | 
						|
  let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
 | 
						|
  if (!githubWorkspacePath) {
 | 
						|
    throw new Error('GITHUB_WORKSPACE not defined')
 | 
						|
  }
 | 
						|
  githubWorkspacePath = path.resolve(githubWorkspacePath)
 | 
						|
  core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
 | 
						|
  fsHelper.directoryExistsSync(githubWorkspacePath, true)
 | 
						|
 | 
						|
  // Qualified repository
 | 
						|
  const qualifiedRepository =
 | 
						|
    core.getInput('repository') ||
 | 
						|
    `${github.context.repo.owner}/${github.context.repo.repo}`
 | 
						|
  core.debug(`qualified repository = '${qualifiedRepository}'`)
 | 
						|
  const splitRepository = qualifiedRepository.split('/')
 | 
						|
  if (
 | 
						|
    splitRepository.length !== 2 ||
 | 
						|
    !splitRepository[0] ||
 | 
						|
    !splitRepository[1]
 | 
						|
  ) {
 | 
						|
    throw new Error(
 | 
						|
      `Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.`
 | 
						|
    )
 | 
						|
  }
 | 
						|
  result.repositoryOwner = splitRepository[0]
 | 
						|
  result.repositoryName = splitRepository[1]
 | 
						|
 | 
						|
  // Repository path
 | 
						|
  result.repositoryPath = core.getInput('path') || '.'
 | 
						|
  result.repositoryPath = path.resolve(
 | 
						|
    githubWorkspacePath,
 | 
						|
    result.repositoryPath
 | 
						|
  )
 | 
						|
  if (
 | 
						|
    !(result.repositoryPath + path.sep).startsWith(
 | 
						|
      githubWorkspacePath + path.sep
 | 
						|
    )
 | 
						|
  ) {
 | 
						|
    throw new Error(
 | 
						|
      `Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`
 | 
						|
    )
 | 
						|
  }
 | 
						|
 | 
						|
  // Workflow repository?
 | 
						|
  const isWorkflowRepository =
 | 
						|
    qualifiedRepository.toUpperCase() ===
 | 
						|
    `${github.context.repo.owner}/${github.context.repo.repo}`.toUpperCase()
 | 
						|
 | 
						|
  // Source branch, source version
 | 
						|
  result.ref = core.getInput('ref')
 | 
						|
  if (!result.ref) {
 | 
						|
    if (isWorkflowRepository) {
 | 
						|
      result.ref = github.context.ref
 | 
						|
      result.commit = github.context.sha
 | 
						|
 | 
						|
      // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
 | 
						|
      // the ref is unqualifed like "main" instead of "refs/heads/main".
 | 
						|
      if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
 | 
						|
        result.ref = `refs/heads/${result.ref}`
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  // SHA?
 | 
						|
  else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
 | 
						|
    result.commit = result.ref
 | 
						|
    result.ref = ''
 | 
						|
  }
 | 
						|
  core.debug(`ref = '${result.ref}'`)
 | 
						|
  core.debug(`commit = '${result.commit}'`)
 | 
						|
 | 
						|
  // Clean
 | 
						|
  result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
 | 
						|
  core.debug(`clean = ${result.clean}`)
 | 
						|
 | 
						|
  // Sparse checkout
 | 
						|
  const sparseCheckout = core.getMultilineInput('sparse-checkout')
 | 
						|
  if (sparseCheckout.length) {
 | 
						|
    result.sparseCheckout = sparseCheckout
 | 
						|
    core.debug(`sparse checkout = ${result.sparseCheckout}`)
 | 
						|
  }
 | 
						|
 | 
						|
  result.sparseCheckoutConeMode =
 | 
						|
    (core.getInput('sparse-checkout-cone-mode') || 'true').toUpperCase() ===
 | 
						|
    'TRUE'
 | 
						|
 | 
						|
  // Fetch depth
 | 
						|
  result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'))
 | 
						|
  if (isNaN(result.fetchDepth) || result.fetchDepth < 0) {
 | 
						|
    result.fetchDepth = 0
 | 
						|
  }
 | 
						|
  core.debug(`fetch depth = ${result.fetchDepth}`)
 | 
						|
 | 
						|
  // LFS
 | 
						|
  result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
 | 
						|
  core.debug(`lfs = ${result.lfs}`)
 | 
						|
 | 
						|
  // Submodules
 | 
						|
  result.submodules = false
 | 
						|
  result.nestedSubmodules = false
 | 
						|
  const submodulesString = (core.getInput('submodules') || '').toUpperCase()
 | 
						|
  if (submodulesString == 'RECURSIVE') {
 | 
						|
    result.submodules = true
 | 
						|
    result.nestedSubmodules = true
 | 
						|
  } else if (submodulesString == 'TRUE') {
 | 
						|
    result.submodules = true
 | 
						|
  }
 | 
						|
  core.debug(`submodules = ${result.submodules}`)
 | 
						|
  core.debug(`recursive submodules = ${result.nestedSubmodules}`)
 | 
						|
 | 
						|
  // Auth token
 | 
						|
  result.authToken = core.getInput('token', {required: true})
 | 
						|
 | 
						|
  // SSH
 | 
						|
  result.sshKey = core.getInput('ssh-key')
 | 
						|
  result.sshKnownHosts = core.getInput('ssh-known-hosts')
 | 
						|
  result.sshStrict =
 | 
						|
    (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'
 | 
						|
 | 
						|
  // Persist credentials
 | 
						|
  result.persistCredentials =
 | 
						|
    (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'
 | 
						|
 | 
						|
  // Workflow organization ID
 | 
						|
  result.workflowOrganizationId = await workflowContextHelper.getOrganizationId()
 | 
						|
 | 
						|
  // Set safe.directory in git global config.
 | 
						|
  result.setSafeDirectory =
 | 
						|
    (core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE'
 | 
						|
 | 
						|
  // Determine the GitHub URL that the repository is being hosted from
 | 
						|
  result.githubServerUrl = core.getInput('github-server-url')
 | 
						|
  core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
 | 
						|
 | 
						|
  return result
 | 
						|
}
 |