main.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 = 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. } finally {
  20. // Unregister problem matcher
  21. coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')
  22. }
  23. } catch (error) {
  24. core.setFailed(error.message)
  25. }
  26. }
  27. async function cleanup(): Promise<void> {
  28. try {
  29. await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
  30. } catch (error) {
  31. core.warning(error.message)
  32. }
  33. }
  34. // Main
  35. if (!stateHelper.IsPost) {
  36. run()
  37. }
  38. // Post
  39. else {
  40. cleanup()
  41. }