test
This commit is contained in:
parent
1aa38e5236
commit
29553a2742
63
action.js
63
action.js
@ -4,65 +4,6 @@ import * as process from 'process';
|
||||
import * as semverParser from 'semver-parser';
|
||||
|
||||
|
||||
try {
|
||||
const stripTagPrefix = core.getInput('strip_tag_prefix');
|
||||
import * as gather from './gather';
|
||||
|
||||
console.log(JSON.stringify(github.context))
|
||||
console.log("github.context.ref=" + github.context.ref)
|
||||
|
||||
const isTag = github.context.ref.startsWith("refs/tags/")
|
||||
core.setOutput("git_is_tag", isTag ? "true" : "false")
|
||||
|
||||
const defaultBranch = github.context.payload?.repository?.defaultBranch
|
||||
core.setOutput("git_default_branch", defaultBranch)
|
||||
|
||||
const isPullRequest = github.context.payload.pull_request != null
|
||||
core.setOutput("git_is_pull_request", isPullRequest)
|
||||
|
||||
if(isPullRequest) {
|
||||
const baseRef = github.context.baseRef || process.env.BODY_REF
|
||||
const headRef = github.context.payload?.pull_request?.head?.ref || process.env.HEAD_REF
|
||||
console.log("baseRef=" + baseRef)
|
||||
console.log("headRef=" + headRef)
|
||||
|
||||
} else if(!isTag) {
|
||||
if(!github.context.ref.startsWith("refs/heads/")) {
|
||||
throw new Error("Failed to determine branch for non-PR and non-Tag action")
|
||||
}
|
||||
const currentBranch = github.context.ref.slice("refs/heads/".length)
|
||||
console.log("git_current_branch=" + currentBranch)
|
||||
core.setOutput("git_current_branch", currentBranch)
|
||||
|
||||
const isDefaultBranch = currentBranch == defaultBranch
|
||||
console.log("git_current_branch=" + isDefaultBranch ? "true" : "false")
|
||||
core.setOutput("git_is_default_branch", isDefaultBranch ? "true" : "false")
|
||||
}
|
||||
|
||||
if(isTag) {
|
||||
const tag = github.context.ref.slice("refs/tags/".length)
|
||||
console.log("git_tag=" + tag)
|
||||
core.setOutput("git_tag", tag)
|
||||
|
||||
const parsed = semverParser.parseSemVer(tag)
|
||||
console.log("semver=" + JSON.stringify(parsed))
|
||||
|
||||
core.setOutput("semver_valid", parsed.matches ? "true" : "false")
|
||||
core.setOutput("semver_major", parsed.major)
|
||||
core.setOutput("semver_minor", parsed.minor)
|
||||
core.setOutput("semver_patch", parsed.patch)
|
||||
core.setOutput("semver_build", parsed.build)
|
||||
core.setOutput("semver_pre", parsed.pre)
|
||||
} else {
|
||||
core.setOutput("git_tag", "false")
|
||||
core.setOutput("semver_valid", "false")
|
||||
core.setOutput("semver_major", "false")
|
||||
core.setOutput("semver_minor", "false")
|
||||
core.setOutput("semver_patch", "false")
|
||||
core.setOutput("semver_build", "false")
|
||||
core.setOutput("semver_pre", "false")
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
gather.gather_information(true, true);
|
||||
@ -12,6 +12,8 @@ outputs:
|
||||
description: 'Returns `"true"` if the current branch is the default else `"false"`.'
|
||||
git_is_tag:
|
||||
description: 'Returns `"true"` if the current branch is a tag else `"false"`.'
|
||||
git_is_branch:
|
||||
description: 'Returns `"true"` if action is executed for a branch (not Tag, not PR), else `"false"`.'
|
||||
git_default_branch:
|
||||
description: 'The default branch name e.g `main` OR `master`'
|
||||
git_current_branch:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user