2424
2525jobs :
2626 check-semantic-version :
27- if : github.event.pull_request.draft == false
27+ if : github.ref != 'refs/heads/main'
2828 uses : octue/workflows/.github/workflows/check-semantic-version.yml@main
2929 with :
3030 path : pyproject.toml
3131 breaking_change_indicated_by : minor
3232
33- run-tests :
33+ check-ahead-of-main :
34+ if : github.ref != 'refs/heads/main'
35+ runs-on : ubuntu-latest
36+ steps :
37+ - name : Checkout repository
38+ uses : actions/checkout@v4
39+ with :
40+ fetch-depth : 0
41+
42+ - name : Check branch is ahead of main
43+ run : |
44+ if ! git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }};
45+ then echo "::error::This branch is not up-to-date with the latest main branch commit.";
46+ exit 1; fi
47+
48+ lint :
49+ runs-on : ubuntu-latest
50+ steps :
51+ - name : Checkout repository
52+ uses : actions/checkout@v4
53+
54+ - name : Setup python
55+ uses : actions/setup-python@v5
56+ with :
57+ python-version : ' 3.11'
58+
59+ - name : Install and configure poetry
60+ uses : snok/install-poetry@v1
61+ with :
62+ virtualenvs-create : true
63+ virtualenvs-in-project : true
64+
65+ - name : Setup virtual environment cache
66+ id : cached-poetry-dependencies
67+ uses : actions/cache@v4
68+ with :
69+ path : .venv
70+ key : venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }}
71+
72+ - name : Install dependencies (if not cached)
73+ if : steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
74+ run : poetry install --only dev --no-interaction --no-root
75+
76+ - name : Install root project
77+ run : poetry install --no-interaction
78+
79+ - name : Run precommit
80+ run : SKIP=build-docs,check-branch-name poetry run pre-commit run --all-files
81+
82+ publish-test :
83+ runs-on : ubuntu-latest
84+ needs :
85+ - lint
86+ - check-ahead-of-main
87+ - check-semantic-version
88+ permissions :
89+ id-token : write
90+ contents : read
91+ steps :
92+ - name : Checkout repository
93+ uses : actions/checkout@v4
94+
95+ - name : Install poetry
96+ 97+
98+ - name : Build a binary wheel and a source tarball
99+ run : poetry build
100+
101+ - name : Test package is publishable with PyPI test server
102+ 103+ with :
104+ repository-url : https://test.pypi.org/legacy/
105+ skip-existing : true
106+ verbose : true
107+
108+ test :
34109 if : github.event.pull_request.draft == false
110+ needs :
111+ - lint
112+ - check-ahead-of-main
113+ - check-semantic-version
35114 strategy :
36- fail-fast : true
115+ fail-fast : false
37116 matrix :
38- python : ['3.9', '3.10', '3.11']
39- os : [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest] for full coverage but this gets expensive quickly
40- runs-on : ${{ matrix.os }}
117+ python-version : ['3.9', '3.10', '3.11', '3.12']
118+ django-version : ['>=4.2,<4.3', '>=5.0,<5.1']
119+ database-engine : ['sqlite', 'postgres']
120+
121+ exclude :
122+ # Exclude Django 5 with Python 3.9
123+ - python-version : ' 3.9'
124+ django-version : ' >=5.0,<5.1'
125+
126+ permissions :
127+ id-token : write
128+ contents : read
41129
42130 services :
43131 postgres :
@@ -55,63 +143,85 @@ jobs:
55143 --health-timeout 5s
56144 --health-retries 5
57145
146+ runs-on : ' ubuntu-latest'
147+
148+ env :
149+ DJANGO_SETTINGS_MODULE : tests.server.settings
150+ DATABASE_ENGINE : ${{ matrix.database-engine }}
151+
58152 steps :
59- - name : Checkout repository
153+ - name : Check out repository
60154 uses : actions/checkout@v4
61155
62- - name : Setup python ${{ matrix.python }}
156+ - name : Prepare Integration Test Credentials
157+ # Workload Identity Federation works great for using the GCloud API, but the credentials required by
158+ # the storages client in integration tests don't like it; they need a private key to sign blobs.
159+ # So until the credentials APIs are sensibly applied across the google client libraries, we inject
160+ # a private service account key (against recommended practice, but this is the only thing that works).
161+ id : application-credentials
162+ run : |
163+ echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}' > $(pwd)/gha-creds-github-actions.json
164+ echo "GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/gha-creds-github-actions.json" >> $GITHUB_ENV
165+
166+ # - name: Authenticate with GCP Workload Identity
167+ # id: auth
168+ # uses: google-github-actions/auth@v2
169+ # with:
170+ # # NOTE: If setting create_credentials_file=true when building docker images,
171+ # # a .dockerignore file must be present and include `gha-creds-*.json` to
172+ # # avoid baking these credentials into the container
173+ # create_credentials_file: true
174+ # workload_identity_provider: projects/134056372703/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
175+ # service_account: [email protected] 176+
177+ # - name: Setup gcloud
178+ # uses: 'google-github-actions/setup-gcloud@v2'
179+
180+ - name : Set up python ${{ matrix.python-version }}
181+ id : setup-python
63182 uses : actions/setup-python@v5
64183 with :
65- python-version : ${{ matrix.python }}
184+ python-version : ${{ matrix.python-version }}
66185
67- # See the repo of this action for way more advanced caching strategies than used here
68- - name : Install poetry
69- 186+ - name : Install Poetry
187+ uses : snok/install-poetry@v1
188+ with :
189+ virtualenvs-create : true
190+ virtualenvs-in-project : true
70191
71- # For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
72- - name : Install tox and plugins
192+ - name : Setup virtual environment cache
193+ id : cached-poetry-dependencies
194+ uses : actions/cache@v4
195+ with :
196+ path : .venv
197+ key : venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
198+
199+ - name : Install dependencies (if not cached)
200+ if : steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
201+ run : poetry install --no-interaction --no-root
202+
203+ - name : Install root project
204+ run : poetry install --no-interaction
205+
206+ - name : Install django ${{ matrix.django-version }}
73207 run : |
74- python -m pip install --upgrade pip
75- python -m pip install tox==3.24.5 tox-gh-actions==2.9.1 tox-poetry==0.4.1
208+ source .venv/bin/activate
209+ pip install "django${{ matrix.django-version }}"
76210
77211 - name : Setup tmate session [DEBUG]
78212 if : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true'}}
79213 uses : mxschmitt/action-tmate@v3
80214
81- # For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
82- - name : Run tests using tox
83- run : tox
215+ - name : Run tests
216+ run : poetry run pytest --cov=django_gcp --cov-report=xml
84217
85218 - name : Upload coverage to Codecov
86219 # This seems redundant inside the test matrix but actually isn't, since different
87220 # dependency combinations may cause different lines of code to be hit (e.g. backports)
88- uses : codecov/codecov-action@v3
221+ uses : codecov/codecov-action@v4
89222 with :
90223 files : coverage.xml
91224 fail_ci_if_error : false
92- # Token is not required for public repos, but see:
225+ # Token is not strictly required for public repos, but see:
93226 # https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
94227 token : ${{ secrets.CODECOV_TOKEN }}
95-
96- test-publish :
97- runs-on : ubuntu-latest
98- needs : run-tests
99- permissions :
100- id-token : write
101- contents : read
102- steps :
103- - name : Checkout repository
104- uses : actions/checkout@v4
105-
106- - name : Install poetry
107- 108-
109- - name : Build a binary wheel and a source tarball
110- run : poetry build
111-
112- - name : Test package is publishable with PyPI test server
113- 114- with :
115- repository-url : https://test.pypi.org/legacy/
116- skip-existing : true
117- verbose : true
0 commit comments