-
Notifications
You must be signed in to change notification settings - Fork 5
173 lines (160 loc) · 6.13 KB
/
tests.yml
File metadata and controls
173 lines (160 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# run test suites
name: Tests and Deployment
on:
- pull_request
- push
- release
- workflow_dispatch
# cancel the current workflow if another commit was pushed on the same PR or reference
# uses the GitHub workflow name to avoid collision with other workflows running on the same PR/reference
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
permissions:
contents: read
jobs:
# see: https://github.com/fkirc/skip-duplicate-actions
skip_duplicate:
name: Skip Duplicate Workflows
continue-on-error: true
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_duplicate.outputs.should_skip && ! contains(github.ref, 'refs/tags') && ! contains(github.ref, 'refs/heads/master') }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: "same_content"
skip_after_successful_duplicate: "true"
do_not_skip: '["pull_request", "workflow_dispatch", "schedule", "release"]'
# see: https://github.com/actions/setup-python
tests:
name: Test
needs: skip_duplicate
if: ${{ needs.skip_duplicate.outputs.should_skip != 'true' }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.allow-failure }}
env:
# override make command to install directly in active python
CONDA_CMD: ""
services:
# Label used to access the service container
mongodb:
image: mongo:3.4.23 # DockerHub
ports:
- "27017:27017"
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
allow-failure: [false]
test-case: [test-local]
include:
# linter tests
- os: ubuntu-latest
python-version: 3.11
allow-failure: false
test-case: lint
# coverage test
- os: ubuntu-latest
python-version: 3.11
allow-failure: false
test-case: coverage
# smoke test of Docker image
- os: ubuntu-latest
python-version: None # doesn't matter which one (in docker), but match default of repo
allow-failure: false
test-case: docker-test
# deprecated versions
- os: ubuntu-latest
python-version: 3.8 # EOL 2024-10
allow-failure: false
test-case: test-local
steps:
- name: Checkout Repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
fetch-depth: "0"
persist-credentials: false
- name: Set up Python3
if: ${{ matrix.python-version != 'None' }}
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install Dependencies
if: ${{ matrix.python-version != 'None' }}
# install package and dependencies directly,
# skip sys/conda setup to use active python
run: make install develop
- name: Display Packages
if: ${{ matrix.python-version != 'None' }}
run: pip freeze
- name: Display Environment Variables
run: |
hash -r
env | sort
- name: Run Tests
run: make --no-keep-going ${{ matrix.test-case }}
- name: Stop Workers
if: ${{ matrix.python-version == 'None' }}
run: make docker-stop
- name: Upload coverage report
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
if: ${{ success() && matrix.test-case == 'coverage' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage.xml
fail_ci_if_error: true
verbose: true
# FIXME: We should split the deployment job into its own workflow. Token-based updates to PyPI are heavily discouraged in favour of Trusted Publishing.
deploy_pypi:
name: Deploy (PyPI)
needs: tests
# Don't match master branch for upload to avoid duplicate error, even if the tag is usually applied on master.
if: ${{ success() && github.event_name == 'push' && contains(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
fetch-depth: "0"
persist-credentials: false
- name: Set up Python3
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: "3.11"
- name: Build Distribution Package
run: |
make develop dist
- name: Push Package to PyPi
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true # For debugging 'twine upload' if a problem occurs.
deploy_docker:
name: Deploy (DockerHub)
needs: tests
if: ${{ success() && (contains(github.ref, 'refs/tags') || github.ref == 'refs/heads/master') }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
fetch-depth: "0"
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
# FIXME: We should be using a PAT generated specifically for this. docker/build-push-action accepts PATs directly.
- name: Login to DockerHub
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
file: "Dockerfile"
push: true
tags: birdhouse/twitcher:latest,birdhouse/twitcher:${{ github.ref_name }}