main.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as core from '@actions/core'
  2. import * as gitSourceProvider from './git-source-provider.js'
  3. import * as inputHelper from './input-helper.js'
  4. import * as path from 'path'
  5. import * as stateHelper from './state-helper.js'
  6. import {fileURLToPath} from 'url'
  7. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  8. async function run(): Promise<void> {
  9. try {
  10. const sourceSettings = await inputHelper.getInputs()
  11. try {
  12. // Register problem matcher
  13. core.info(
  14. `::add-matcher::${path.join(__dirname, 'problem-matcher.json')}`
  15. )
  16. // Get sources
  17. await gitSourceProvider.getSource(sourceSettings)
  18. core.setOutput('ref', sourceSettings.ref)
  19. } finally {
  20. // Unregister problem matcher
  21. core.info('::remove-matcher owner=checkout-git::')
  22. }
  23. } catch (error) {
  24. core.setFailed(`${(error as any)?.message ?? error}`)
  25. }
  26. }
  27. async function cleanup(): Promise<void> {
  28. try {
  29. await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
  30. } catch (error) {
  31. core.warning(`${(error as any)?.message ?? error}`)
  32. }
  33. }
  34. // Main
  35. if (!stateHelper.IsPost) {
  36. run()
  37. }
  38. // Post
  39. else {
  40. cleanup()
  41. }