state-helper.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import * as core from '@actions/core'
  2. /**
  3. * Indicates whether the POST action is running
  4. */
  5. export const IsPost = !!core.getState('isPost')
  6. /**
  7. * The repository path for the POST action. The value is empty during the MAIN action.
  8. */
  9. export const RepositoryPath = core.getState('repositoryPath')
  10. /**
  11. * The set-safe-directory for the POST action. The value is set if input: 'safe-directory' is set during the MAIN action.
  12. */
  13. export const PostSetSafeDirectory = core.getState('setSafeDirectory') === 'true'
  14. /**
  15. * The SSH key path for the POST action. The value is empty during the MAIN action.
  16. */
  17. export const SshKeyPath = core.getState('sshKeyPath')
  18. /**
  19. * The SSH known hosts path for the POST action. The value is empty during the MAIN action.
  20. */
  21. export const SshKnownHostsPath = core.getState('sshKnownHostsPath')
  22. /**
  23. * Save the repository path so the POST action can retrieve the value.
  24. */
  25. export function setRepositoryPath(repositoryPath: string) {
  26. core.saveState('repositoryPath', repositoryPath)
  27. }
  28. /**
  29. * Save the SSH key path so the POST action can retrieve the value.
  30. */
  31. export function setSshKeyPath(sshKeyPath: string) {
  32. core.saveState('sshKeyPath', sshKeyPath)
  33. }
  34. /**
  35. * Save the SSH known hosts path so the POST action can retrieve the value.
  36. */
  37. export function setSshKnownHostsPath(sshKnownHostsPath: string) {
  38. core.saveState('sshKnownHostsPath', sshKnownHostsPath)
  39. }
  40. /**
  41. * Save the set-safe-directory input so the POST action can retrieve the value.
  42. */
  43. export function setSafeDirectory() {
  44. core.saveState('setSafeDirectory', 'true')
  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. core.saveState('isPost', 'true')
  50. }