migrations.yml 2.7 KB

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