-
Notifications
You must be signed in to change notification settings - Fork 41
205 lines (198 loc) · 7.04 KB
/
cicd.yml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: CI/CD
on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:
env:
PIPX_HOME: "/home/runner/.cache/pipx"
PIPX_BIN_DIR: "/home/runner/.local/bin"
POETRY_VERSION: "1.5.1"
jobs:
lint:
runs-on: ubuntu-22.04
name: lint with isort, Black & flake8
steps:
- uses: actions/checkout@v3
- name: "Prepare: restore caches, install Poetry, set up Python"
uses: ./.github/actions/prepare
with:
python-version: "3.10"
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dev dependencies
run: |
poetry install --only dev
- name: Lint with isort
run: |
poetry run isort . --check-only --diff
- name: Lint with Black
run: |
poetry run black . --check --diff
- name: Lint with flake8
run: |
poetry run flake8
time-startup:
runs-on: ubuntu-22.04
name: check CLI startup time
steps:
- uses: actions/checkout@v3
- name: "Prepare: restore caches, install Poetry, set up Python"
id: prepare
uses: ./.github/actions/prepare
with:
python-version: "3.9"
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dependencies
run: |
poetry install
- name: Check startup time
run: |
poetry run tests/time-startup.sh
test:
runs-on: ubuntu-22.04
timeout-minutes: 15
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
experimental: [false]
include:
- python-version: "3.11"
experimental: true
name: test on Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Install system packages
run: |
sudo apt-get install \
libvoikko1 \
voikko-fi
- name: "Prepare: restore caches, install Poetry, set up Python"
id: prepare
uses: ./.github/actions/prepare
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dependencies
run: |
# Selectively install the optional dependencies for some Python versions
# For Python 3.8:
if [[ ${{ matrix.python-version }} == '3.8' ]]; then
poetry install -E "nn omikuji yake voikko stwfsa";
fi
# For Python 3.9:
if [[ ${{ matrix.python-version }} == '3.9' ]]; then
poetry install -E "fasttext spacy";
# download the small English pretrained spaCy model needed by spacy analyzer
poetry run python -m spacy download en_core_web_sm --upgrade-strategy only-if-needed
fi
# For Python 3.10:
if [[ ${{ matrix.python-version }} == '3.10' ]]; then
poetry install -E "nn omikuji yake stwfsa";
fi
# For Python 3.11:
if [[ ${{ matrix.python-version }} == '3.11' ]]; then
poetry install -E "nn fasttext yake stwfsa voikko spacy";
# download the small English pretrained spaCy model needed by spacy analyzer
poetry run python -m spacy download en_core_web_sm --upgrade-strategy only-if-needed
fi
poetry run python -m nltk.downloader punkt
- name: Test with pytest
run: |
poetry run pytest --cov=./ --cov-report xml
if [[ ${{ matrix.python-version }} == '3.9' ]]; then
poetry run pytest --cov=./ --cov-report xml --cov-append -m slow
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
- name: Save cache
if: steps.prepare.outputs.cache-matched-key != format('poetry-installation-and-cache-{0}-{1}-{2}', matrix.python-version, env.POETRY_VERSION, hashFiles('**/poetry.lock'))
uses: actions/cache/save@v3
with:
path: |
~/.cache/pipx/venvs
~/.local/bin
~/.cache/pypoetry/
# A new key is created to update the cache if some dependency has been updated
key: poetry-installation-and-cache-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}
test-docker-image:
name: "test Docker image"
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- name: "Build image for testing"
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
with:
push: false
tags: test-image
- name: "Test with pytest"
run: |
docker run --rm --workdir /Annif test-image pytest -p no:cacheprovider
publish-docker-latest:
name: publish latest Docker image
needs: [lint, test, test-docker-image]
runs-on: ubuntu-22.04
timeout-minutes: 15
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Login to Quay.io
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: quay.io
username: ${{ secrets.YHTEENTOIMIVUUSPALVELUT_QUAY_IO_USERNAME }}
password: ${{ secrets.YHTEENTOIMIVUUSPALVELUT_QUAY_IO_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea # v4.1.1
with:
images: quay.io/natlibfi/annif
tags: |
latest
- name: Build and push to Quay.io
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
publish-release:
name: publish release
needs: [lint, test, test-docker-image]
runs-on: ubuntu-22.04
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: "Prepare: restore caches, install Poetry, set up Python"
uses: ./.github/actions/prepare
with:
python-version: '3.10'
poetry-version: ${{ env.POETRY_VERSION }}
- name: Build and publish distribution to PyPI
env:
POETRY_HTTP_BASIC_PYPI_USERNAME: __token__
POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry publish --build
- name: Login to Quay.io
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: quay.io
username: ${{ secrets.YHTEENTOIMIVUUSPALVELUT_QUAY_IO_USERNAME }}
password: ${{ secrets.YHTEENTOIMIVUUSPALVELUT_QUAY_IO_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea # v4.1.1
with:
images: quay.io/natlibfi/annif
tags: |
type=semver,pattern={{version}},suffix=-{{date 'YYYYMMDD'}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push to Quay.io
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}