-
Notifications
You must be signed in to change notification settings - Fork 1
217 lines (185 loc) · 5.9 KB
/
ci-cd.yml
File metadata and controls
217 lines (185 loc) · 5.9 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
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
name: CI/CD
on:
workflow_dispatch:
push:
branches:
- '**' # run on all branches (including main)
tags:
- 'v*.*.*' # release tags like v1.2.3
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
integration-fms17:
name: Integration tests (FMS17 on fms_17)
runs-on: [fms_17]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create tests/.env for FMS17
shell: powershell
run: |
$envContent = @"
FMS_ADDRESS="https://localhost"
FMS_DB_NAME="fmdata_testing"
FMS_DB_USER="${{ secrets.FMDATA_TESTING_USER }}"
FMS_DB_PASSWORD="${{ secrets.FMDATA_TESTING_PASSWORD }}"
FMS_VERSION="17"
"@
New-Item -ItemType Directory -Force -Path tests | Out-Null
Set-Content -Path tests/.env -Value $envContent -NoNewline
- name: Run integration tests with coverage (FMS17)
shell: powershell
run: |
$env:ENV_FILE = ".env"
coverage run -m unittest discover -s tests -t tests
coverage xml -o coverage_fms17.xml
- name: Upload coverage artifact (FMS17)
uses: actions/upload-artifact@v4
with:
name: coverage-fms17
path: |
coverage_fms17.xml
.coverage.fms17
integration-fms22:
name: Integration tests (FMS22 on fms_22)
runs-on: [fms_22]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.9'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create tests/.env for FMS22
shell: bash
run: |
mkdir -p tests
cat > tests/.env << 'EOF'
FMS_ADDRESS="https://localhost"
FMS_DB_NAME="fmdata_testing"
FMS_DB_USER="${{ secrets.FMDATA_TESTING_USER }}"
FMS_DB_PASSWORD="${{ secrets.FMDATA_TESTING_PASSWORD }}"
FMS_VERSION="22"
EOF
- name: Run integration tests with coverage (FMS22)
shell: bash
run: |
export ENV_FILE=".env"
coverage run -m unittest discover -s tests -t tests
coverage xml -o coverage_fms22.xml
mv .coverage .coverage.fms22 || true
- name: Upload coverage artifact (FMS22)
uses: actions/upload-artifact@v4
with:
name: coverage-fms22
path: |
coverage_fms22.xml
.coverage.fms22
sonarcloud:
name: SonarCloud analysis
runs-on: ubuntu-latest
needs:
- integration-fms17
- integration-fms22
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Download coverage artifact (FMS17)
uses: actions/download-artifact@v4
with:
name: coverage-fms17
path: coverage_artifacts
- name: Download coverage artifact (FMS22)
uses: actions/download-artifact@v4
with:
name: coverage-fms22
path: coverage_artifacts
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v6.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
release:
name: Release on tag
runs-on: ubuntu-latest
needs: sonarcloud
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/fmdata
permissions:
id-token: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure tag commit is on main
run: |
git fetch origin main:origin-main
if git merge-base --is-ancestor origin-main "${GITHUB_SHA}"; then
echo "Tag commit is contained in main."
else
echo "Error: Release tags must point to a commit on main."
exit 1
fi
- name: Extract version from tag and export PACKAGE_VERSION
run: |
TAG_NAME="${GITHUB_REF_NAME}"
# Expect tags like v1.2.3 -> PACKAGE_VERSION=1.2.3
VERSION="${TAG_NAME#v}"
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install build
- name: Build package
run: |
python -m build
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
tag_name: "${{ github.ref_name }}"
generate_release_notes: true
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1