Browse Source

build(gha): Refactor `python.yml` workflow into multiple workflows (#21388)

Changes `python.yml` workflow into the following 3 workflows:

- "Check if migration is required" - checks is user forgot to make a
migration
- "backend 3.6 tests" - changes to run on all pull requests (not just when
python files change)
- "snuba 3.6 tests" - same as backend
Billy Vong 4 years ago
parent
commit
ca0e43dc56

+ 3 - 0
.github/file-filters.yml

@@ -0,0 +1,3 @@
+backend:
+  - '**/*.py'
+  - 'requirements*.txt'

+ 74 - 0
.github/workflows/backend-test-py3.6.yml

@@ -0,0 +1,74 @@
+name: backend [py3.6]
+on:
+  push:
+    branches:
+      - master
+      - releases/**
+  pull_request:
+
+jobs:
+  test:
+    runs-on: ubuntu-16.04
+    timeout-minutes: 30
+    strategy:
+      matrix:
+        instance: [0, 1, 2]
+
+    env:
+      MIGRATIONS_TEST_MIGRATE: 1
+
+    steps:
+      - uses: actions/checkout@v2
+
+      # If we make these jobs "required" to merge on GH, then on every PR, GitHub automatically
+      # creates a status check in the "pending" state. This means that the workflow needs to run
+      # for every PR in order to update the status checks.
+      #
+      # In order to optimize CI usage, we want the tests to only run when python files change,
+      # since frontend changes should have no effect on these test suites. We cannot use GH workflow
+      # path filters because entire workflow would be skipped vs skipping individual jobs which
+      # would still allow this status check to pass.
+      - name: Check for python file changes
+        uses: getsentry/paths-filter@v2
+        id: changes
+        with:
+          token: ${{ github.token }}
+          filters: .github/file-filters.yml
+
+      - name: Set python version output
+        id: python-version
+        if: steps.changes.outputs.backend == 'true'
+        run: |
+          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+
+      # Until GH composite actions can use `uses`, we need to setup python here
+      - uses: actions/setup-python@v2
+        if: steps.changes.outputs.backend == 'true'
+        with:
+          python-version: ${{ steps.python-version.outputs.python-version }}
+
+      - name: Setup pip
+        uses: ./.github/actions/setup-pip
+        if: steps.changes.outputs.backend == 'true'
+        id: pip
+
+      - name: pip cache
+        uses: actions/cache@v2
+        if: steps.changes.outputs.backend == 'true'
+        with:
+          path: ${{ steps.pip.outputs.pip-cache-dir }}
+          key: ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}
+
+      - name: Setup sentry env
+        uses: ./.github/actions/setup-sentry
+        if: steps.changes.outputs.backend == 'true'
+        id: setup
+        with:
+          python: 3
+
+      - name: Run backend test [py3.6] (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
+        if: steps.changes.outputs.backend == 'true'
+        run: |
+          make travis-test-postgres

+ 88 - 0
.github/workflows/check-if-migration-is-required.yml

@@ -0,0 +1,88 @@
+name: check if migration is required
+on:
+  pull_request:
+    paths:
+      # Matches all python files regardless of directory depth.
+      - '**.py'
+      - requirements*.txt
+
+jobs:
+  main:
+    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
+
+    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:
+      - name: Install System Dependencies
+        run: |
+          sudo apt-get update
+          sudo apt-get install -y --no-install-recommends \
+            libxmlsec1-dev \
+            libmaxminddb-dev
+
+      - uses: actions/checkout@v2
+
+      - name: Set up outputs
+        id: config
+        env:
+          MATRIX_INSTANCE: ${{ matrix.instance }}
+        run: |
+          echo "::set-output name=python-version::2.7.17"
+
+      - name: Set up Python ${{ steps.config.outputs.python-version }}
+        uses: actions/setup-python@v2
+        with:
+          python-version: ${{ steps.config.outputs.python-version}}
+
+      - name: Setup pip
+        uses: ./.github/actions/setup-pip
+        id: pip
+
+      - name: pip cache
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.pip.outputs.pip-cache-dir }}
+          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+
+      - 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)

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

@@ -1,197 +0,0 @@
-name: python
-on:
-  push:
-    branches:
-      - master
-      - releases/**
-  pull_request:
-    paths:
-      # Matches all python files regardless of directory depth.
-      - '**.py'
-      - requirements*.txt
-
-jobs:
-  check-missing-migration:
-    # Not necessary for this job to run on the push branches.
-    if: ${{ github.ref != 'refs/heads/master' || contains(github.ref, 'releases/') }}
-    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
-
-    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:
-      - name: Install System Dependencies
-        run: |
-          sudo apt-get update
-          sudo apt-get install -y --no-install-recommends \
-            libxmlsec1-dev \
-            libmaxminddb-dev
-
-      - uses: actions/checkout@v2
-
-      - name: Set up outputs
-        id: config
-        env:
-          MATRIX_INSTANCE: ${{ matrix.instance }}
-        run: |
-          echo "::set-output name=python-version::2.7.17"
-
-      - name: Set up Python ${{ steps.config.outputs.python-version }}
-        uses: actions/setup-python@v2
-        with:
-          python-version: ${{ steps.config.outputs.python-version}}
-
-      - name: Setup pip
-        uses: ./.github/actions/setup-pip
-        id: pip
-
-      - name: pip cache
-        uses: actions/cache@v2
-        with:
-          path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }}
-          restore-keys: |
-            ${{ runner.os }}-pip-
-
-      - 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)
-
-  test-py3:
-    name: 'python3.6 backend'
-    runs-on: ubuntu-16.04
-    timeout-minutes: 30
-    strategy:
-      matrix:
-        instance: [0, 1, 2]
-
-    env:
-      MIGRATIONS_TEST_MIGRATE: 1
-
-    steps:
-      - uses: actions/checkout@v2
-
-      - uses: volta-cli/action@v1
-
-      - name: Set python version output
-        id: python-version
-        run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
-
-      # Until GH composite actions can use `uses`, we need to setup python here
-      - uses: actions/setup-python@v2
-        with:
-          python-version: ${{ steps.python-version.outputs.python-version }}
-
-      - name: Setup pip
-        uses: ./.github/actions/setup-pip
-        id: pip
-
-      - name: pip cache
-        uses: actions/cache@v2
-        with:
-          path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}-${{ hashFiles('**/requirements-*.txt') }}
-          restore-keys: |
-            ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}
-
-      - name: Setup sentry env
-        uses: ./.github/actions/setup-sentry
-        id: setup
-        with:
-          python: 3
-
-      - name: Python 3.6 backend (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
-        if: always()
-        run: |
-          make travis-test-postgres
-
-  test-py3-snuba:
-    name: '[ignore fails] python3.6 backend (snuba)'
-    runs-on: ubuntu-16.04
-    continue-on-error: true
-    timeout-minutes: 30
-    strategy:
-      matrix:
-        instance: [0]
-
-    env:
-      # Note: `USE_SNUBA` is only used for the Snuba test suite because we have some failing acceptance tests with Snuba enabled.
-      USE_SNUBA: 1
-      MIGRATIONS_TEST_MIGRATE: 1
-
-    steps:
-      - uses: actions/checkout@v2
-
-      - uses: volta-cli/action@v1
-
-      - name: Set python version output
-        id: python-version
-        run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
-
-      # Until GH composite actions can use `uses`, we need to setup python here
-      - uses: actions/setup-python@v2
-        with:
-          python-version: ${{ steps.python-version.outputs.python-version }}
-
-      - name: Setup pip
-        uses: ./.github/actions/setup-pip
-        id: pip
-
-      - name: pip cache
-        uses: actions/cache@v2
-        with:
-          path: ${{ steps.pip.outputs.pip-cache-dir }}
-          key: ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}-${{ hashFiles('**/requirements-*.txt') }}
-          restore-keys: |
-            ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}
-
-      - name: Setup sentry env
-        uses: ./.github/actions/setup-sentry
-        id: setup
-        with:
-          python: 3
-          kafka: true
-
-      - name: Python 3.6 snuba backend (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
-        if: always()
-        run: |
-          make travis-test-snuba

+ 77 - 0
.github/workflows/snuba-integration-test-py3.6.yml

@@ -0,0 +1,77 @@
+name: snuba integration [py3.6]
+on:
+  push:
+    branches:
+      - master
+      - releases/**
+  pull_request:
+
+jobs:
+  test:
+    runs-on: ubuntu-16.04
+    timeout-minutes: 30
+    strategy:
+      matrix:
+        instance: [0]
+
+    env:
+      # Note: `USE_SNUBA` is only used for the Snuba test suite because we have some failing acceptance tests with Snuba enabled.
+      USE_SNUBA: 1
+      MIGRATIONS_TEST_MIGRATE: 1
+
+    steps:
+      - uses: actions/checkout@v2
+
+      # If we make these jobs "required" to merge on GH, then on every PR, GitHub automatically
+      # creates a status check in the "pending" state. This means that the workflow needs to run
+      # for every PR in order to update the status checks.
+      #
+      # In order to optimize CI usage, we want the tests to only run when python files change,
+      # since frontend changes should have no effect on these test suites. We cannot use GH workflow
+      # path filters because entire workflow would be skipped vs skipping individual jobs which
+      # would still allow this status check to pass.
+      - name: Check for python file changes
+        uses: getsentry/paths-filter@v2
+        id: changes
+        with:
+          token: ${{ github.token }}
+          filters: .github/file-filters.yml
+
+      - name: Set python version output
+        id: python-version
+        if: steps.changes.outputs.backend == 'true'
+        run: |
+          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+
+      # Until GH composite actions can use `uses`, we need to setup python here
+      - uses: actions/setup-python@v2
+        if: steps.changes.outputs.backend == 'true'
+        with:
+          python-version: ${{ steps.python-version.outputs.python-version }}
+
+      - name: Setup pip
+        uses: ./.github/actions/setup-pip
+        if: steps.changes.outputs.backend == 'true'
+        id: pip
+
+      - name: pip cache
+        uses: actions/cache@v2
+        if: steps.changes.outputs.backend == 'true'
+        with:
+          path: ${{ steps.pip.outputs.pip-cache-dir }}
+          key: ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}-${{ hashFiles('**/requirements-*.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-py${{ steps.python-version.outputs.python-version }}
+
+      - name: Setup sentry env
+        uses: ./.github/actions/setup-sentry
+        if: steps.changes.outputs.backend == 'true'
+        id: setup
+        with:
+          python: 3
+          kafka: true
+
+      - name: Run snuba test [py3.6] (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})
+        if: steps.changes.outputs.backend == 'true'
+        run: |
+          make travis-test-snuba