-
Notifications
You must be signed in to change notification settings - Fork 70
171 lines (147 loc) · 4.25 KB
/
Copy pathci-cd.yml
File metadata and controls
171 lines (147 loc) · 4.25 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
name: ci-cd
on:
push:
branches:
- master
- staging
tags:
- "*"
pull_request:
workflow_dispatch:
inputs:
publish_target:
description: "Optional manual publish target"
required: true
type: choice
options:
- none
- testpypi
default: none
concurrency:
group: ci-cd-${{ github.ref }}
cancel-in-progress: true
env:
PYTHON_RUNTIME_VERSION: "3.9.21"
jobs:
code_quality:
name: Code quality
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_RUNTIME_VERSION }}
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install flake8==3.0.4
- name: Run flake8
run: flake8 ./
test:
name: Tests
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_RUNTIME_VERSION }}
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools==70.0.0
pip install -r requirements.txt
pip install \
coverage \
pytest==3.5.1 \
pytest-cov==2.5.1 \
pytest-env==0.6.2 \
responses==0.9.0
- name: Run tests with coverage
run: |
pytest \
--cov evalai \
--cov-config .coveragerc \
--cov-report=xml:coverage.xml
- name: Save pull request number for downstream coverage upload
run: |
mkdir -p pr-metadata
echo "${{ github.event.pull_request.number }}" > pr-metadata/pr_number.txt
- name: Upload test and coverage artifacts
uses: actions/upload-artifact@v4
with:
name: ci-test-reports
path: coverage.xml
if-no-files-found: error
- name: Upload pull request metadata artifact
uses: actions/upload-artifact@v4
with:
name: pr-metadata
path: pr-metadata/pr_number.txt
if-no-files-found: error
publish_to_testpypi:
name: Publish to TestPyPI
runs-on: ubuntu-latest
needs:
- code_quality
- test
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/staging') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'testpypi')
environment: staging
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_RUNTIME_VERSION }}
cache: pip
- name: Build and publish package to TestPyPI
env:
TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }}
run: |
python -m pip install --upgrade pip setuptools wheel twine
python setup.py sdist bdist_wheel
python -m twine upload \
--repository-url https://test.pypi.org/legacy/ \
dist/*
publish_to_pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs:
- code_quality
- test
if: startsWith(github.ref, 'refs/tags/')
environment: production
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_RUNTIME_VERSION }}
cache: pip
- name: Build and publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip setuptools wheel twine
python setup.py sdist bdist_wheel
python -m twine upload dist/*