forked from frequenz-floss/frequenz-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (212 loc) · 7.14 KB
/
ci.yaml
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: frequenz-sdk-python
on: [pull_request, push, workflow_dispatch]
jobs:
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
python:
- "3.8"
- "3.9"
- "3.10"
runs-on: ${{ matrix.os }}
steps:
- name: Fetch sources
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('minimum-requirements-ci.txt', 'pyproject.toml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-
- name: Install required Python packages
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: run nox
run: nox -e ci_checks_max pytest_min
timeout-minutes: 10
build-dist:
runs-on: ubuntu-20.04
steps:
- name: Fetch sources
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install build dependencies
run: |
python -m pip install -U pip
python -m pip install -U build
- name: Build the source and binary distribution
run: python -m build
- name: Upload dist files
uses: actions/upload-artifact@v3
with:
name: frequenz-sdk-python-dist
path: dist/
if-no-files-found: error
generate-docs-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-20.04
steps:
- name: Fetch sources
uses: actions/checkout@v3
- name: Setup Git user and e-mail
uses: frequenz-floss/setup-git-user@v1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install build dependencies
run: |
python -m pip install -U pip
python -m pip install .[docs]
- name: Generate the documentation
env:
MIKE_VERSION: pr-${{ github.event.number }}
run: |
mike deploy $MIKE_VERSION
mike set-default $MIKE_VERSION
- name: Upload site
uses: actions/upload-artifact@v3
with:
name: frequenz-channels-python-site
path: site/
if-no-files-found: error
publish-docs:
needs: ["test", "build-dist"]
if: github.event_name == 'push'
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Calculate and check version
id: mike-metadata
env:
REF: ${{ github.ref }}
REF_NAME: ${{ github.ref_name }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
aliases=
version=
if test "$REF_NAME" = "$DEFAULT_BRANCH"
then
version=next
# A tag that starts with vX.Y or X.Y
elif echo "$REF" | grep -q '^refs/tags' && echo "$REF_NAME" | grep -Pq '^v?\d+\.\d+\.'
then
if echo "$REF_NAME" | grep -Pq -- "-" # pre-release
then
echo "::notice title=Documentation was not published::" \
"The tag '$REF_NAME' looks like a pre-release."
exit 0
fi
version=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+\.[0-9]+)\..*$/\1/') # vX.Y
major=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
default_major=$(echo "$DEFAULT_BRANCH" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
aliases=$major
if test "$major" = "$default_major"
then
aliases="$aliases latest"
fi
else
echo "::warning title=Documentation was not published::" \
"Don't know how to handle '$REF' to make 'mike' version."
exit 0
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "aliases=$aliases" >> $GITHUB_OUTPUT
- name: Fetch sources
if: steps.mike-metadata.outputs.version
uses: actions/checkout@v3
- name: Setup Git user and e-mail
if: steps.mike-metadata.outputs.version
uses: frequenz-floss/setup-git-user@v1
- name: Set up Python
if: steps.mike-metadata.outputs.version
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install build dependencies
if: steps.mike-metadata.outputs.version
run: |
python -m pip install -U pip
python -m pip install .[docs]
- name: Fetch the gh-pages branch
if: steps.mike-metadata.outputs.version
run: git fetch origin gh-pages --depth=1
- name: Publish site
if: steps.mike-metadata.outputs.version
env:
VERSION: ${{ steps.mike-metadata.outputs.version }}
ALIASES: ${{ steps.mike-metadata.outputs.aliases }}
run: |
mike deploy --push --update-aliases "$VERSION" $ALIASES
create-github-release:
needs: ["publish-docs"]
# Create a release only on tags creation
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
permissions:
# We need write permissions on contents to create GitHub releases and on
# discussions to create the release announcement in the discussion forums
contents: write
discussions: write
runs-on: ubuntu-20.04
steps:
- name: Download dist files
uses: actions/download-artifact@v3
with:
name: frequenz-sdk-python-dist
path: dist
- name: Download RELEASE_NOTES.md
run: |
set -ux
gh api \
-X GET \
-f ref=$REF \
-H "Accept: application/vnd.github.raw" \
"/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \
> RELEASE_NOTES.md
env:
REF: ${{ github.ref }}
REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release
run: |
set -ux
extra_opts=
if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi
gh release create \
-R "$REPOSITORY" \
--discussion-category announcements \
--notes-file RELEASE_NOTES.md \
--generate-notes \
$extra_opts \
$REF_NAME \
dist/*
env:
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-pypi:
needs: ["create-github-release"]
runs-on: ubuntu-20.04
steps:
- name: Download dist files
uses: actions/download-artifact@v3
with:
name: frequenz-sdk-python-dist
path: dist
- name: Publish the Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true