2323 default : false
2424
2525jobs :
26- run-tests :
26+ check-ahead-of-main :
27+ if : github.ref != 'refs/heads/main'
28+ runs-on : ubuntu-latest
29+ steps :
30+ - name : Checkout repository
31+ uses : actions/checkout@v4
32+ with :
33+ fetch-depth : 0
34+
35+ - name : Check branch is ahead of main
36+ run : |
37+ if ! git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }};
38+ then echo "::error::This branch is not up-to-date with the latest main branch commit.";
39+ exit 1; fi
40+
41+ lint :
42+ runs-on : ubuntu-latest
43+ steps :
44+ - name : Checkout repository
45+ uses : actions/checkout@v4
46+
47+ - name : Setup python
48+ uses : actions/setup-python@v5
49+ with :
50+ python-version : " 3.11"
51+
52+ - name : Install and configure poetry
53+ uses : snok/install-poetry@v1
54+ with :
55+ virtualenvs-create : true
56+ virtualenvs-in-project : true
57+
58+ - name : Setup virtual environment cache
59+ id : cached-poetry-dependencies
60+ uses : actions/cache@v4
61+ with :
62+ path : .venv
63+ key : venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }}
64+
65+ - name : Install dependencies (if not cached)
66+ if : steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
67+ run : poetry install --only dev --no-interaction --no-root
68+
69+ - name : Install root project
70+ run : poetry install --no-interaction
71+
72+ - name : Run precommit
73+ run : SKIP=build-docs,check-branch-name poetry run pre-commit run --all-files
74+
75+ test :
2776 if : github.event.pull_request.draft == false
2877 strategy :
29- fail-fast : true
78+ fail-fast : false
3079 matrix :
31- python : ["3.11", "3.12", "3.13"]
80+ python-version : ["3.10", "3.11", "3.12"]
81+ django-version : [">=4.2,<4.3", ">=5.0,<5.1"]
3282 os : [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest] for full coverage but this gets expensive quickly
33- runs-on : ${{ matrix.os }}
83+
84+ permissions :
85+ id-token : write
86+ contents : read
87+
88+ env :
89+ DJANGO_SETTINGS_MODULE : tests.server.settings
3490
3591 services :
3692 postgres :
@@ -48,50 +104,71 @@ jobs:
48104 --health-timeout 5s
49105 --health-retries 5
50106
107+ runs-on : ${{ matrix.os }}
108+
51109 steps :
52- - name : Checkout Repository
53- uses : actions/checkout@v3
110+ - name : Check out repository
111+ uses : actions/checkout@v4
54112
55- - name : Setup Python ${{ matrix.python }}
56- uses : actions/setup-python@v3
113+ - name : Set up python ${{ matrix.python-version }}
114+ id : setup-python
115+ uses : actions/setup-python@v5
57116 with :
58- python-version : ${{ matrix.python }}
117+ python-version : ${{ matrix.python-version }}
59118
60- # See the repo of this action for way more advanced caching strategies than used here
61119 - name : Install Poetry
62120 uses : snok/install-poetry@v1
121+ with :
122+ virtualenvs-create : true
123+ virtualenvs-in-project : true
124+
125+ - name : Setup virtual environment cache
126+ id : cached-poetry-dependencies
127+ uses : actions/cache@v4
128+ with :
129+ path : .venv
130+ key : venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
63131
64- # For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
65- - name : Install tox and plugins
132+ - name : Install dependencies (if not cached)
133+ if : steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
134+ run : poetry install --no-interaction --no-root
135+
136+ - name : Install root project
137+ run : poetry install --no-interaction
138+
139+ - name : Install django ${{ matrix.django-version }}
66140 run : |
67- python -m pip install --upgrade pip
68- python -m pip install tox==3.24.5 tox-gh-actions==2.9.1 tox-poetry==0.4.1
141+ source .venv/bin/activate
142+ pip install "django${{ matrix.django-version }}"
69143
70144 - name : Setup tmate session [DEBUG]
71145 if : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true'}}
72146 uses : mxschmitt/action-tmate@v3
73147
74- # For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
75- - name : Run tests using tox
76- run : tox
148+ - name : Run tests
149+ run : poetry run pytest --cov=django_gcp --cov-report=xml
77150
78151 - name : Upload coverage to Codecov
79152 # This seems redundant inside the test matrix but actually isn't, since different
80153 # dependency combinations may cause different lines of code to be hit (e.g. backports)
81- uses : codecov/codecov-action@v3
154+ uses : codecov/codecov-action@v4
82155 with :
83156 files : coverage.xml
84157 fail_ci_if_error : false
85- # Token is not required for public repos, but see:
158+ # Token is not strictly required for public repos, but see:
86159 # https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
87160 token : ${{ secrets.CODECOV_TOKEN }}
88161
89- test- publish :
162+ publish-test :
90163 runs-on : ubuntu-latest
91- needs : run-tests
164+ needs :
165+ - lint
166+ - check-ahead-of-main
167+
92168 permissions :
93169 id-token : write
94170 contents : read
171+
95172 steps :
96173 - name : Checkout repository
97174 uses : actions/checkout@v4
0 commit comments