migrations.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. name: migrations
  2. on: pull_request
  3. # Cancel in progress workflows on pull_requests.
  4. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  5. concurrency:
  6. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  7. cancel-in-progress: true
  8. defaults:
  9. run:
  10. # the default default is:
  11. # bash --noprofile --norc -eo pipefail {0}
  12. shell: bash --noprofile --norc -eo pipefail -ux {0}
  13. jobs:
  14. did-migration-change:
  15. name: check if any migration changes
  16. runs-on: ubuntu-22.04
  17. timeout-minutes: 3
  18. # Map a step output to a job output
  19. outputs:
  20. added: ${{ steps.changes.outputs.migrations_added }}
  21. modified: ${{ steps.changes.outputs.migrations_modified }}
  22. steps:
  23. - name: Checkout sentry
  24. uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  25. - name: Match migration files
  26. uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
  27. id: changes
  28. with:
  29. token: ${{ github.token }}
  30. filters: .github/file-filters.yml
  31. check-migration-approval:
  32. name: check if migration is approved
  33. runs-on: ubuntu-22.04
  34. timeout-minutes: 3
  35. needs: did-migration-change
  36. if: needs.did-migration-change.outputs.added == 'true'
  37. steps:
  38. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  39. with:
  40. persist-credentials: false
  41. - name: getsentry token
  42. uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
  43. id: getsentry
  44. with:
  45. app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
  46. private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
  47. - uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # v6.3.3
  48. with:
  49. github-token: ${{ steps.getsentry.outputs.token }}
  50. script: |
  51. const {check} = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/team-approval-check`);
  52. await check({ github, context, core, team_slug: 'owners-migrations' });
  53. modified-migration:
  54. name: check if modified migration
  55. runs-on: ubuntu-22.04
  56. timeout-minutes: 4
  57. needs: did-migration-change
  58. if: needs.did-migration-change.outputs.modified == 'true'
  59. steps:
  60. - name: Failure because of modified migration
  61. run: |
  62. echo "If you have a valid reason to modify a migration please get approval"
  63. echo "from @getsentry/owners-migrations." && exit 1
  64. sql:
  65. name: Generate SQL
  66. runs-on: ubuntu-22.04
  67. timeout-minutes: 8
  68. strategy:
  69. matrix:
  70. pg-version: ['14']
  71. needs: did-migration-change
  72. if: needs.did-migration-change.outputs.added == 'true'
  73. steps:
  74. # Checkout master to run all merged migrations.
  75. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  76. with:
  77. ref: master
  78. - name: Setup sentry env
  79. uses: ./.github/actions/setup-sentry
  80. with:
  81. pg-version: ${{ matrix.pg-version }}
  82. - name: Apply migrations
  83. run: |
  84. sentry upgrade --noinput
  85. # Checkout the current ref
  86. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  87. with:
  88. clean: false
  89. - name: Get changed migration files
  90. id: file
  91. run: |
  92. echo 'added<<EOF' >> "$GITHUB_OUTPUT"
  93. git diff --diff-filter=A --name-only origin/master HEAD -- 'src/sentry/*/migrations/' 'src/sentry/migrations/' >> "$GITHUB_OUTPUT"
  94. echo 'EOF' >> "$GITHUB_OUTPUT"
  95. - name: Generate SQL for migration
  96. uses: getsentry/action-migrations@4d8ed0388dfc0774302bbfd5204e518f9ac4f066 # main
  97. env:
  98. SENTRY_LOG_LEVEL: ERROR
  99. with:
  100. githubToken: ${{ secrets.GITHUB_TOKEN }}
  101. migration: ${{ steps.file.outputs.added }}