migrations.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. name: migrations
  2. on: pull_request
  3. jobs:
  4. did-migration-change:
  5. name: check if any migration changes
  6. runs-on: ubuntu-20.04
  7. timeout-minutes: 3
  8. # Map a step output to a job output
  9. outputs:
  10. added: ${{ steps.changes.outputs.migrations_added }}
  11. modified: ${{ steps.changes.outputs.migrations_modified }}
  12. steps:
  13. - name: Checkout sentry
  14. uses: actions/checkout@v2
  15. - name: Match migration files
  16. uses: getsentry/paths-filter@v2
  17. id: changes
  18. with:
  19. token: ${{ github.token }}
  20. filters: .github/file-filters.yml
  21. modified-migration:
  22. name: check if modified migration
  23. runs-on: ubuntu-20.04
  24. timeout-minutes: 4
  25. needs: did-migration-change
  26. if: needs.did-migration-change.outputs.modified == 'true'
  27. steps:
  28. - name: Failure because of modified migration
  29. shell: bash
  30. run: |
  31. echo "If you have a valid reason to modify a migration please get approval"
  32. echo "from @getsentry/owners-migrations, then ask a Github admin to merge." && exit 1
  33. sql:
  34. name: Generate SQL
  35. runs-on: ubuntu-20.04
  36. timeout-minutes: 8
  37. strategy:
  38. matrix:
  39. python-version: [3.8.12]
  40. pg-version: ['9.6']
  41. needs: did-migration-change
  42. if: needs.did-migration-change.outputs.added == 'true'
  43. steps:
  44. # Checkout master to run all merged migrations.
  45. - uses: actions/checkout@v1
  46. with:
  47. ref: master
  48. - name: Setup sentry env (python ${{ matrix.python-version }})
  49. uses: ./.github/actions/setup-sentry
  50. id: setup
  51. with:
  52. python-version: ${{ matrix.python-version }}
  53. pg-version: ${{ matrix.pg-version }}
  54. - name: Apply migrations
  55. run: |
  56. sentry upgrade --noinput
  57. # Checkout the current ref
  58. - uses: actions/checkout@v1
  59. with:
  60. clean: false
  61. - name: Get changed migration files
  62. id: file
  63. run: |
  64. echo $(git diff --diff-filter=A --name-only origin/master HEAD)
  65. echo "::set-output name=added::$(git diff --diff-filter=A --name-only origin/master HEAD | grep 'src/sentry/migrations/')"
  66. - name: Generate SQL for migration
  67. uses: getsentry/action-migrations@main
  68. env:
  69. SENTRY_LOG_LEVEL: ERROR
  70. with:
  71. githubToken: ${{ secrets.GITHUB_TOKEN }}
  72. migration: ${{ steps.file.outputs.added }}