migrations.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. pip-cache-version: ${{ secrets.PIP_CACHE_VERSION }}
  54. pg-version: ${{ matrix.pg-version }}
  55. - name: Apply migrations
  56. run: |
  57. sentry upgrade --noinput
  58. # Checkout the current ref
  59. - uses: actions/checkout@v1
  60. with:
  61. clean: false
  62. - name: Get changed migration files
  63. id: file
  64. run: |
  65. echo $(git diff --diff-filter=A --name-only origin/master HEAD)
  66. echo "::set-output name=added::$(git diff --diff-filter=A --name-only origin/master HEAD | grep 'src/sentry/migrations/')"
  67. - name: Generate SQL for migration
  68. uses: getsentry/action-migrations@main
  69. env:
  70. SENTRY_LOG_LEVEL: ERROR
  71. with:
  72. githubToken: ${{ secrets.GITHUB_TOKEN }}
  73. migration: ${{ steps.file.outputs.added }}