getsentry-dispatch.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* eslint-env node */
  2. /**
  3. * List of workflows to dispatch to `getsentry`
  4. *
  5. * `pathFilterName` refers to the path filters in `.github/file-filters.yml` (`getsentry/paths-filter` action)
  6. *
  7. * TODO(billy): Refactor workflow files to be an enum so that we can integration test them. Otherwise if they are
  8. * deleted/renamed in `getsentry`, this will fail
  9. */
  10. const DISPATCHES = [
  11. {
  12. workflow: 'js-build-and-lint.yml',
  13. pathFilterName: 'frontend',
  14. },
  15. {
  16. workflow: 'backend.yml',
  17. pathFilterName: 'backend_src',
  18. },
  19. ];
  20. module.exports = {
  21. dispatch: async ({github, context, core, fileChanges, mergeCommitSha}) => {
  22. core.startGroup('Dispatching request to getsentry.');
  23. const shouldSkip = {
  24. frontend: fileChanges.frontend_all !== 'true',
  25. backend_dependencies: fileChanges.backend_dependencies !== 'true',
  26. };
  27. await Promise.all(
  28. DISPATCHES.map(({workflow, pathFilterName}) => {
  29. const inputs = {
  30. pull_request_number: `${context.payload.pull_request.number}`, // needs to be string
  31. skip: `${shouldSkip[pathFilterName]}`, // even though this is a boolean, it must be cast to a string
  32. // sentrySHA is the sha getsentry should run against.
  33. 'sentry-sha': mergeCommitSha,
  34. // prSHA is the sha actions should post commit statuses too.
  35. 'sentry-pr-sha': context.payload.pull_request.head.sha,
  36. };
  37. core.info(
  38. `Sending dispatch for '${workflow}':\n${JSON.stringify(inputs, null, 2)}`
  39. );
  40. return github.rest.actions.createWorkflowDispatch({
  41. owner: 'getsentry',
  42. repo: 'getsentry',
  43. workflow_id: workflow,
  44. ref: 'master',
  45. inputs,
  46. });
  47. })
  48. );
  49. core.endGroup();
  50. },
  51. };