migrations.yml 2.8 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@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  20. - name: Match migration files
  21. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  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@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  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@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  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 }}