migrations.yml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. needs: did-migration-change
  38. if: ${{ needs.did-migration-change.outputs.added == 'true' }}
  39. steps:
  40. # Checkout master to run all merged migrations.
  41. - uses: actions/checkout@v1
  42. with:
  43. ref: master
  44. - name: Set python version output
  45. id: python-version
  46. run: |
  47. echo "::set-output name=python-version::$(cat .python-version)"
  48. # Until GH composite actions can use `uses`, we need to setup python here
  49. - uses: actions/setup-python@v2
  50. with:
  51. python-version: ${{ steps.python-version.outputs.python-version }}
  52. - name: Setup pip
  53. uses: ./.github/actions/setup-pip
  54. id: pip
  55. - name: pip cache
  56. uses: actions/cache@v2
  57. with:
  58. path: ${{ steps.pip.outputs.pip-cache-dir }}
  59. key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
  60. restore-keys: |
  61. ${{ runner.os }}-pip-
  62. - name: Setup sentry env
  63. uses: ./.github/actions/setup-sentry
  64. id: setup
  65. - name: Apply migrations
  66. run: |
  67. sentry upgrade --noinput
  68. # Checkout the current ref
  69. - uses: actions/checkout@v1
  70. with:
  71. clean: false
  72. - name: Get changed migration files
  73. id: file
  74. run: |
  75. echo $(git diff --diff-filter=A --name-only origin/master HEAD)
  76. echo "::set-output name=added::$(git diff --diff-filter=A --name-only origin/master HEAD | grep 'src/sentry/migrations/')"
  77. - name: Generate SQL for migration
  78. uses: getsentry/action-migrations@v1.0.7
  79. env:
  80. SENTRY_LOG_LEVEL: ERROR
  81. with:
  82. githubToken: ${{ secrets.GITHUB_TOKEN }}
  83. migration: ${{ steps.file.outputs.added }}