migrations.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  27. id: changes
  28. with:
  29. token: ${{ github.token }}
  30. filters: .github/file-filters.yml
  31. modified-migration:
  32. name: check if modified migration
  33. runs-on: ubuntu-22.04
  34. timeout-minutes: 4
  35. needs: did-migration-change
  36. if: needs.did-migration-change.outputs.modified == 'true'
  37. steps:
  38. - name: Failure because of modified migration
  39. run: |
  40. echo "If you have a valid reason to modify a migration please get approval"
  41. echo "from @getsentry/owners-migrations." && exit 1
  42. sql:
  43. name: Generate SQL
  44. runs-on: ubuntu-22.04
  45. timeout-minutes: 8
  46. strategy:
  47. matrix:
  48. pg-version: ['14']
  49. needs: did-migration-change
  50. if: needs.did-migration-change.outputs.added == 'true'
  51. steps:
  52. # Checkout master to run all merged migrations.
  53. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  54. with:
  55. ref: master
  56. - name: Setup sentry env
  57. uses: ./.github/actions/setup-sentry
  58. with:
  59. pg-version: ${{ matrix.pg-version }}
  60. - name: Apply migrations
  61. run: |
  62. sentry upgrade --noinput
  63. # Checkout the current ref
  64. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  65. with:
  66. clean: false
  67. - name: Get changed migration files
  68. id: file
  69. run: |
  70. echo 'added<<EOF' >> "$GITHUB_OUTPUT"
  71. git diff --diff-filter=A --name-only origin/master HEAD -- 'src/sentry/*/migrations/' 'src/sentry/migrations/' >> "$GITHUB_OUTPUT"
  72. echo 'EOF' >> "$GITHUB_OUTPUT"
  73. - name: Generate SQL for migration
  74. uses: getsentry/action-migrations@4d8ed0388dfc0774302bbfd5204e518f9ac4f066 # main
  75. env:
  76. SENTRY_LOG_LEVEL: ERROR
  77. with:
  78. githubToken: ${{ secrets.GITHUB_TOKEN }}
  79. migration: ${{ steps.file.outputs.added }}