state-helper.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import * as coreCommand from '@actions/core/lib/command'
  2. /**
  3. * Indicates whether the POST action is running
  4. */
  5. export const IsPost = !!process.env['STATE_isPost']
  6. /**
  7. * The repository path for the POST action. The value is empty during the MAIN action.
  8. */
  9. export const RepositoryPath =
  10. (process.env['STATE_repositoryPath'] as string) || ''
  11. /**
  12. * The SSH key path for the POST action. The value is empty during the MAIN action.
  13. */
  14. export const SshKeyPath = (process.env['STATE_sshKeyPath'] as string) || ''
  15. /**
  16. * The SSH known hosts path for the POST action. The value is empty during the MAIN action.
  17. */
  18. export const SshKnownHostsPath =
  19. (process.env['STATE_sshKnownHostsPath'] as string) || ''
  20. /**
  21. * Save the repository path so the POST action can retrieve the value.
  22. */
  23. export function setRepositoryPath(repositoryPath: string) {
  24. coreCommand.issueCommand(
  25. 'save-state',
  26. {name: 'repositoryPath'},
  27. repositoryPath
  28. )
  29. }
  30. /**
  31. * Save the SSH key path so the POST action can retrieve the value.
  32. */
  33. export function setSshKeyPath(sshKeyPath: string) {
  34. coreCommand.issueCommand('save-state', {name: 'sshKeyPath'}, sshKeyPath)
  35. }
  36. /**
  37. * Save the SSH known hosts path so the POST action can retrieve the value.
  38. */
  39. export function setSshKnownHostsPath(sshKnownHostsPath: string) {
  40. coreCommand.issueCommand(
  41. 'save-state',
  42. {name: 'sshKnownHostsPath'},
  43. sshKnownHostsPath
  44. )
  45. }
  46. // Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
  47. // This is necessary since we don't have a separate entry point.
  48. if (!IsPost) {
  49. coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true')
  50. }