main.ts 1.1 KB

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