@@ -39,6 +39,14 @@ inputs:
|
||||
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
committed:
|
||||
description: Whether the action has created a commit.
|
||||
pushed:
|
||||
description: Whether the action has pushed to the remote.
|
||||
tagged:
|
||||
description: Whether the action has created a tag.
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
main: lib/index.js
|
||||
|
||||
9814
lib/index.js
9814
lib/index.js
File diff suppressed because one or more lines are too long
67
src/main.ts
67
src/main.ts
@@ -1,29 +1,15 @@
|
||||
import {
|
||||
info,
|
||||
setFailed,
|
||||
getInput as getInputCore,
|
||||
warning,
|
||||
debug,
|
||||
startGroup,
|
||||
endGroup,
|
||||
error
|
||||
endGroup
|
||||
} from '@actions/core'
|
||||
import axios from 'axios'
|
||||
import path from 'path'
|
||||
import simpleGit, { Response } from 'simple-git'
|
||||
|
||||
type Input =
|
||||
| 'add'
|
||||
| 'author_name'
|
||||
| 'author_email'
|
||||
| 'branch'
|
||||
| 'cwd'
|
||||
| 'message'
|
||||
| 'pull_strategy'
|
||||
| 'push'
|
||||
| 'remove'
|
||||
| 'signoff'
|
||||
| 'tag'
|
||||
import { getInput, Input, log, outputs, parseBool, setOutput } from './util'
|
||||
|
||||
const baseDir = path.join(process.cwd(), getInput('cwd') || '')
|
||||
const git = simpleGit({ baseDir })
|
||||
@@ -92,12 +78,18 @@ console.log(`Running in ${baseDir}`)
|
||||
}
|
||||
: {})
|
||||
},
|
||||
log
|
||||
(err, data?) => {
|
||||
if (data) setOutput('committed', 'true')
|
||||
return log(err, data)
|
||||
}
|
||||
)
|
||||
|
||||
if (getInput('tag')) {
|
||||
info('> Tagging commit...')
|
||||
await git.tag(getInput('tag').split(' '), log)
|
||||
await git.tag(getInput('tag').split(' '), (err, data?) => {
|
||||
if (data) setOutput('tagged', 'true')
|
||||
return log(err, data)
|
||||
})
|
||||
} else info('> No tag info provided.')
|
||||
|
||||
if (getInput('push')) {
|
||||
@@ -106,7 +98,10 @@ console.log(`Running in ${baseDir}`)
|
||||
'origin',
|
||||
getInput('branch'),
|
||||
{ '--set-upstream': null },
|
||||
log
|
||||
(err, data?) => {
|
||||
if (data) setOutput('pushed', 'true')
|
||||
return log(err, data)
|
||||
}
|
||||
)
|
||||
|
||||
if (getInput('tag')) {
|
||||
@@ -139,10 +134,13 @@ console.log(`Running in ${baseDir}`)
|
||||
endGroup()
|
||||
info('> Working tree clean. Nothing to commit.')
|
||||
}
|
||||
})().catch((e) => {
|
||||
endGroup()
|
||||
setFailed(e)
|
||||
})
|
||||
})()
|
||||
.then(logOutputs)
|
||||
.catch((e) => {
|
||||
endGroup()
|
||||
logOutputs()
|
||||
setFailed(e)
|
||||
})
|
||||
|
||||
async function checkInputs() {
|
||||
function setInput(input: Input, value: string | undefined) {
|
||||
@@ -286,23 +284,6 @@ async function checkInputs() {
|
||||
}
|
||||
// #endregion
|
||||
}
|
||||
|
||||
function getInput(name: Input) {
|
||||
return getInputCore(name)
|
||||
}
|
||||
|
||||
function parseBool(value: any) {
|
||||
try {
|
||||
const parsed = JSON.parse(value)
|
||||
if (typeof parsed == 'boolean') return parsed
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function log(err: any | Error, data?: any) {
|
||||
if (data) console.log(data)
|
||||
if (err) error(err)
|
||||
}
|
||||
|
||||
function add({
|
||||
logWarning = true,
|
||||
ignoreErrors = false
|
||||
@@ -342,3 +323,9 @@ function remove({
|
||||
else throw e
|
||||
})
|
||||
}
|
||||
|
||||
function logOutputs() {
|
||||
startGroup('Outputs:')
|
||||
info(JSON.stringify(outputs))
|
||||
endGroup()
|
||||
}
|
||||
|
||||
42
src/util.ts
Normal file
42
src/util.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import core from '@actions/core'
|
||||
|
||||
export type Input =
|
||||
| 'add'
|
||||
| 'author_name'
|
||||
| 'author_email'
|
||||
| 'branch'
|
||||
| 'cwd'
|
||||
| 'message'
|
||||
| 'pull_strategy'
|
||||
| 'push'
|
||||
| 'remove'
|
||||
| 'signoff'
|
||||
| 'tag'
|
||||
|
||||
export const outputs = {
|
||||
committed: 'false',
|
||||
pushed: 'false',
|
||||
tagged: 'false'
|
||||
}
|
||||
export type Output = keyof typeof outputs
|
||||
|
||||
export function getInput(name: Input) {
|
||||
return core.getInput(name)
|
||||
}
|
||||
|
||||
export function log(err: any | Error, data?: any) {
|
||||
if (data) console.log(data)
|
||||
if (err) core.error(err)
|
||||
}
|
||||
|
||||
export function parseBool(value: any) {
|
||||
try {
|
||||
const parsed = JSON.parse(value)
|
||||
if (typeof parsed == 'boolean') return parsed
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function setOutput(name: Output, value: 'true' | 'false') {
|
||||
core.setOutput(name, value)
|
||||
}
|
||||
for (const key in outputs) setOutput(key as Output, outputs[key])
|
||||
Reference in New Issue
Block a user