detect branch and parse semver
This commit is contained in:
parent
5add488dc0
commit
29c27575d5
48
action.js
48
action.js
@ -5,8 +5,7 @@ import * as semverParser from 'semver-parser';
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// `who-to-greet` input defined in action metadata file
|
const stripTagPrefix = core.getInput('strip_tag_prefix');
|
||||||
const stripTaxPrefix = core.getBooleanInput('strip_tag_prefix');
|
|
||||||
|
|
||||||
console.log(JSON.stringify(github.context))
|
console.log(JSON.stringify(github.context))
|
||||||
console.log("github.context.ref=" + github.context.ref)
|
console.log("github.context.ref=" + github.context.ref)
|
||||||
@ -14,16 +13,55 @@ try {
|
|||||||
const isTag = github.context.ref.startsWith("refs/tags/")
|
const isTag = github.context.ref.startsWith("refs/tags/")
|
||||||
core.setOutput("git_is_tag", isTag ? "true" : "false")
|
core.setOutput("git_is_tag", isTag ? "true" : "false")
|
||||||
|
|
||||||
|
const defaultBranch = github.context.payload?.repository?.defaultBranch
|
||||||
|
core.setOutput("git_default_branch", defaultBranch)
|
||||||
|
|
||||||
if(!isTag) {
|
const isPullRequest = github.context.payload.pull_request != null
|
||||||
const baseRef = github.context.payload?.pull_request?.base?.ref || process.env.BODY_REF
|
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
|
const headRef = github.context.payload?.pull_request?.head?.ref || process.env.HEAD_REF
|
||||||
console.log("baseRef=" + baseRef)
|
console.log("baseRef=" + baseRef)
|
||||||
console.log("headRef=" + headRef)
|
console.log("headRef=" + headRef)
|
||||||
|
|
||||||
|
} else if(!isTag) {
|
||||||
|
if(!github.context.ref.startsWith("refs/head/")) {
|
||||||
|
throw new Error("Failed to determine branch for non-PR and non-Tag action")
|
||||||
|
}
|
||||||
|
const currentBranch = github.context.ref.slice("refs/head/".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")
|
||||||
|
}
|
||||||
|
|
||||||
// const parsed = semverParser.parseSemVer("1.1.1+abc")
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
name: Branch Names
|
name: Branch Names
|
||||||
description: Retrieve github branch or tag information without the /ref/* prefix
|
description: Retrieve github branch or tag information without the /ref/* prefix
|
||||||
author: tj-actions
|
author: David Hiendl
|
||||||
inputs:
|
inputs:
|
||||||
strip_tag_prefix:
|
strip_tag_prefix:
|
||||||
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
|
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
|
||||||
default: "false"
|
default: ""
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
@ -36,6 +36,10 @@ outputs:
|
|||||||
description: "Semver minor version"
|
description: "Semver minor version"
|
||||||
semver_patch:
|
semver_patch:
|
||||||
description: "Semver patch version"
|
description: "Semver patch version"
|
||||||
|
semver_build:
|
||||||
|
description: "Semver build string"
|
||||||
|
semver_pre:
|
||||||
|
description: "Semver pre-release version"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node20"
|
||||||
|
|||||||
1
node_modules/.bin/uuid
generated
vendored
1
node_modules/.bin/uuid
generated
vendored
@ -1 +0,0 @@
|
|||||||
../uuid/dist/bin/uuid
|
|
||||||
2
node_modules/.bin/uuid
generated
vendored
Executable file
2
node_modules/.bin/uuid
generated
vendored
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
require('../uuid-bin');
|
||||||
Loading…
Reference in New Issue
Block a user