2019-12-03 22:28:59 +07:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as coreCommand from '@actions/core/lib/command'
|
|
|
|
import * as gitSourceProvider from './git-source-provider'
|
|
|
|
import * as inputHelper from './input-helper'
|
|
|
|
import * as path from 'path'
|
2019-12-13 01:16:16 +07:00
|
|
|
import * as stateHelper from './state-helper'
|
2019-12-03 22:28:59 +07:00
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
2021-11-01 23:43:18 +07:00
|
|
|
const sourceSettings = await inputHelper.getInputs()
|
2019-12-03 22:28:59 +07:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Register problem matcher
|
|
|
|
coreCommand.issueCommand(
|
|
|
|
'add-matcher',
|
|
|
|
{},
|
|
|
|
path.join(__dirname, 'problem-matcher.json')
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get sources
|
|
|
|
await gitSourceProvider.getSource(sourceSettings)
|
2024-09-05 22:57:13 +07:00
|
|
|
core.setOutput('ref', sourceSettings.ref)
|
2019-12-03 22:28:59 +07:00
|
|
|
} finally {
|
|
|
|
// Unregister problem matcher
|
|
|
|
coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-10-19 21:52:57 +07:00
|
|
|
core.setFailed(`${(error as any)?.message ?? error}`)
|
2019-12-03 22:28:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function cleanup(): Promise<void> {
|
|
|
|
try {
|
2019-12-13 01:16:16 +07:00
|
|
|
await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
|
2019-12-03 22:28:59 +07:00
|
|
|
} catch (error) {
|
2021-10-19 21:52:57 +07:00
|
|
|
core.warning(`${(error as any)?.message ?? error}`)
|
2019-12-03 22:28:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main
|
2019-12-13 01:16:16 +07:00
|
|
|
if (!stateHelper.IsPost) {
|
2019-12-03 22:28:59 +07:00
|
|
|
run()
|
|
|
|
}
|
|
|
|
// Post
|
|
|
|
else {
|
|
|
|
cleanup()
|
|
|
|
}
|