Browse Source

build(github): Add check for required migration (#19419)

Add workflow for sentry python files that checks if a migration is needed.

Co-authored-by: josh <josh@jrl.ninja>
Billy Vong 4 years ago
parent
commit
373cfbf140
1 changed files with 104 additions and 0 deletions
  1. 104 0
      .github/workflows/python.yml

+ 104 - 0
.github/workflows/python.yml

@@ -0,0 +1,104 @@
+name: python
+on:
+  pull_request:
+    paths:
+      - 'src/**/*.py'
+
+jobs:
+    check-missing-migration:
+      name: Check Migration Required
+      runs-on: ubuntu-16.04
+
+      env:
+        PIP_DISABLE_PIP_VERSION_CHECK: on
+        SENTRY_LIGHT_BUILD: 1
+        SENTRY_SKIP_BACKEND_VALIDATION: 1
+        MIGRATIONS_TEST_MIGRATE: 0
+
+        # The hostname used to communicate with the PostgreSQL from sentry
+        DATABASE_URL: postgresql://postgres:postgres@localhost/sentry
+
+        # Use this to override the django version in the requirements file.
+        DJANGO_VERSION: ">=1.11,<1.12"
+
+      services:
+        postgres:
+          image: postgres:9.6
+          env:
+            POSTGRES_USER: postgres
+            POSTGRES_PASSWORD: postgres
+          ports:
+            # Maps tcp port 5432 on service container to the host
+            - 5432:5432
+          # needed because the postgres container does not provide a healthcheck
+          options: >-
+            --health-cmd pg_isready
+            --health-interval 10s
+            --health-timeout 5s
+            --health-retries 5
+
+      steps:
+        # Checkout codebase
+        - uses: actions/checkout@v2
+
+        # Python
+        #   Use `.python-version` to avoid duplication
+        #   XXX: can't actually read from .python-version because GitHub Actions
+        #   does not support our version (2.7.16)
+        #
+        #   XXX: Using `2.7` as GHA image only seems to keep one minor version around and will break
+        #   CI if we pin it to a specific patch version.
+        - name: Set up outputs
+          id: config
+          env:
+            MATRIX_INSTANCE: ${{ matrix.instance }}
+          run: |
+            echo "::set-output name=python-version::2.7"
+
+        # setup python
+        - name: Set up Python ${{ steps.config.outputs.python-version }}
+          uses: actions/setup-python@v1
+          with:
+            python-version: ${{ steps.config.outputs.python-version}}
+
+        # setup pip
+        - name: Install pip
+          run: |
+            pip install --no-cache-dir --upgrade "pip>=20.0.2"
+
+        # pip cache
+        - name: Get pip cache dir
+          id: pip-cache
+          run: |
+            echo "::set-output name=dir::$(pip cache dir)"
+
+        - name: pip cache
+          uses: actions/cache@v1
+          with:
+            path: ${{ steps.pip-cache.outputs.dir }}
+            key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+            restore-keys: |
+              ${{ runner.os }}-pip-
+
+        - name: Install System Dependencies
+          run: |
+            sudo apt-get update
+            sudo apt-get install libxmlsec1-dev libmaxminddb-dev
+
+        - name: Install Python Dependencies
+          env:
+            PGPASSWORD: postgres
+          run: |
+            python setup.py install_egg_info
+            pip install wheel # GitHub Actions does not have this installed by default (unlike Travis)
+            pip install -U -e ".[dev]"
+            psql -c 'create database sentry;' -h localhost -U postgres
+            sentry init
+
+        - name: Check if a migration is required
+          env:
+            SENTRY_LOG_LEVEL: ERROR
+            PGPASSWORD: postgres
+          run: |
+            # Below will exit with non-zero status if model changes are missing migrations
+            sentry django makemigrations -n ci_test --check --dry-run --no-input || echo '::error::Error: Migration required -- to generate a migration, run `sentry django makemigrations -n <some_name>`' && exit 1