migrations.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. defaults:
  9. run:
  10. # the default default is:
  11. # bash --noprofile --norc -eo pipefail {0}
  12. shell: bash --noprofile --norc -eo pipefail -ux {0}
  13. jobs:
  14. did-migration-change:
  15. name: check if any migration changes
  16. runs-on: ubuntu-22.04
  17. timeout-minutes: 3
  18. # Map a step output to a job output
  19. outputs:
  20. added: ${{ steps.changes.outputs.migrations_added }}
  21. modified: ${{ steps.changes.outputs.migrations_modified }}
  22. steps:
  23. - name: Checkout sentry
  24. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  25. - name: Match migration files
  26. uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
  27. id: changes
  28. with:
  29. token: ${{ github.token }}
  30. filters: .github/file-filters.yml
  31. sql:
  32. name: Generate SQL
  33. runs-on: ubuntu-22.04
  34. timeout-minutes: 8
  35. strategy:
  36. matrix:
  37. pg-version: ['14']
  38. needs: did-migration-change
  39. if: needs.did-migration-change.outputs.added == 'true'
  40. steps:
  41. # Checkout master to run all merged migrations.
  42. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  43. with:
  44. ref: master
  45. - name: Setup sentry env
  46. uses: ./.github/actions/setup-sentry
  47. with:
  48. pg-version: ${{ matrix.pg-version }}
  49. - name: Apply migrations
  50. run: |
  51. sentry upgrade --noinput
  52. # Checkout the current ref
  53. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  54. with:
  55. clean: false
  56. - name: Get changed migration files
  57. id: file
  58. run: |
  59. echo 'added<<EOF' >> "$GITHUB_OUTPUT"
  60. git diff --diff-filter=A --name-only origin/master HEAD -- 'src/sentry/*/migrations/*' 'src/sentry/migrations/*' >> "$GITHUB_OUTPUT"
  61. echo 'EOF' >> "$GITHUB_OUTPUT"
  62. - name: Generate SQL for migration
  63. uses: getsentry/action-migrations@4d8ed0388dfc0774302bbfd5204e518f9ac4f066 # main
  64. env:
  65. SENTRY_LOG_LEVEL: ERROR
  66. with:
  67. githubToken: ${{ secrets.GITHUB_TOKEN }}
  68. migration: ${{ steps.file.outputs.added }}