/ src / main.ts
main.ts
 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  
 8  async function run(): Promise<void> {
 9    try {
10      const sourceSettings = inputHelper.getInputs()
11  
12      try {
13        // Register problem matcher
14        coreCommand.issueCommand(
15          'add-matcher',
16          {},
17          path.join(__dirname, 'problem-matcher.json')
18        )
19  
20        // Get sources
21        await gitSourceProvider.getSource(sourceSettings)
22      } finally {
23        // Unregister problem matcher
24        coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')
25      }
26    } catch (error) {
27      core.setFailed(error.message)
28    }
29  }
30  
31  async function cleanup(): Promise<void> {
32    try {
33      await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
34    } catch (error) {
35      core.warning(error.message)
36    }
37  }
38  
39  // Main
40  if (!stateHelper.IsPost) {
41    run()
42  }
43  // Post
44  else {
45    cleanup()
46  }