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