@@ -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)
|
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
|
||||||
required: false
|
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:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
main: lib/index.js
|
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 {
|
import {
|
||||||
info,
|
info,
|
||||||
setFailed,
|
setFailed,
|
||||||
getInput as getInputCore,
|
|
||||||
warning,
|
warning,
|
||||||
debug,
|
debug,
|
||||||
startGroup,
|
startGroup,
|
||||||
endGroup,
|
endGroup
|
||||||
error
|
|
||||||
} from '@actions/core'
|
} from '@actions/core'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import simpleGit, { Response } from 'simple-git'
|
import simpleGit, { Response } from 'simple-git'
|
||||||
|
import { getInput, Input, log, outputs, parseBool, setOutput } from './util'
|
||||||
type Input =
|
|
||||||
| 'add'
|
|
||||||
| 'author_name'
|
|
||||||
| 'author_email'
|
|
||||||
| 'branch'
|
|
||||||
| 'cwd'
|
|
||||||
| 'message'
|
|
||||||
| 'pull_strategy'
|
|
||||||
| 'push'
|
|
||||||
| 'remove'
|
|
||||||
| 'signoff'
|
|
||||||
| 'tag'
|
|
||||||
|
|
||||||
const baseDir = path.join(process.cwd(), getInput('cwd') || '')
|
const baseDir = path.join(process.cwd(), getInput('cwd') || '')
|
||||||
const git = simpleGit({ baseDir })
|
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')) {
|
if (getInput('tag')) {
|
||||||
info('> Tagging commit...')
|
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.')
|
} else info('> No tag info provided.')
|
||||||
|
|
||||||
if (getInput('push')) {
|
if (getInput('push')) {
|
||||||
@@ -106,7 +98,10 @@ console.log(`Running in ${baseDir}`)
|
|||||||
'origin',
|
'origin',
|
||||||
getInput('branch'),
|
getInput('branch'),
|
||||||
{ '--set-upstream': null },
|
{ '--set-upstream': null },
|
||||||
log
|
(err, data?) => {
|
||||||
|
if (data) setOutput('pushed', 'true')
|
||||||
|
return log(err, data)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (getInput('tag')) {
|
if (getInput('tag')) {
|
||||||
@@ -139,10 +134,13 @@ console.log(`Running in ${baseDir}`)
|
|||||||
endGroup()
|
endGroup()
|
||||||
info('> Working tree clean. Nothing to commit.')
|
info('> Working tree clean. Nothing to commit.')
|
||||||
}
|
}
|
||||||
})().catch((e) => {
|
})()
|
||||||
endGroup()
|
.then(logOutputs)
|
||||||
setFailed(e)
|
.catch((e) => {
|
||||||
})
|
endGroup()
|
||||||
|
logOutputs()
|
||||||
|
setFailed(e)
|
||||||
|
})
|
||||||
|
|
||||||
async function checkInputs() {
|
async function checkInputs() {
|
||||||
function setInput(input: Input, value: string | undefined) {
|
function setInput(input: Input, value: string | undefined) {
|
||||||
@@ -286,23 +284,6 @@ async function checkInputs() {
|
|||||||
}
|
}
|
||||||
// #endregion
|
// #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({
|
function add({
|
||||||
logWarning = true,
|
logWarning = true,
|
||||||
ignoreErrors = false
|
ignoreErrors = false
|
||||||
@@ -342,3 +323,9 @@ function remove({
|
|||||||
else throw e
|
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