Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/input-helper.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2019-12-03 10:28:59 -0500
committerGitHub <noreply@github.com>2019-12-03 10:28:59 -0500
commite404ba5989baa550f631fb1262539d1375a856b7 (patch)
tree4cc911589e7c9a4c976bc99eb4dcb886d2b2d8a8 /src/input-helper.ts
parent6a11491f2eea6739d1296d604c5402cffa43a1f1 (diff)
Convert checkout to a regular action (#70)
Diffstat (limited to 'src/input-helper.ts')
-rw-r--r--src/input-helper.ts104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/input-helper.ts b/src/input-helper.ts
new file mode 100644
index 0000000..d7d8779
--- /dev/null
+++ b/src/input-helper.ts
@@ -0,0 +1,104 @@
+import * as core from '@actions/core'
+import * as fsHelper from './fs-helper'
+import * as github from '@actions/github'
+import * as path from 'path'
+import {ISourceSettings} from './git-source-provider'
+
+export function getInputs(): ISourceSettings {
+ const result = ({} as unknown) as ISourceSettings
+
+ // 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
+ }
+
+ if (!result.ref && !result.commit) {
+ result.ref = 'refs/heads/master'
+ }
+ }
+ // 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}`)
+
+ // Submodules
+ if (core.getInput('submodules')) {
+ throw new Error(
+ "The input 'submodules' is not supported in actions/checkout@v2"
+ )
+ }
+
+ // 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}`)
+
+ // Access token
+ result.accessToken = core.getInput('token')
+
+ return result
+}