-
Notifications
You must be signed in to change notification settings - Fork 259
166 lines (166 loc) · 6.05 KB
/
ci-test.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
on: [push]
name: Run Test Cases
jobs:
test:
strategy:
fail-fast: false
max-parallel: 1
matrix:
python_version: ['2.7', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9']
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Setup miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
channels: conda-forge
python-version: ${{ matrix.python_version }}
activate-environment: qiniu-sdk
auto-activate-base: false
- name: Setup pip
shell: bash -l {0}
env:
PYTHON_VERSION: ${{ matrix.python_version }}
PIP_BOOTSTRAP_SCRIPT_PREFIX: https://bootstrap.pypa.io/pip
run: |
MAJOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f1)
MINOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f2)
# reinstall pip by some python(<3.7) not compatible
if ! [[ $MAJOR -ge 3 && $MINOR -ge 7 ]]; then
cd /tmp
wget -qLO get-pip.py "$PIP_BOOTSTRAP_SCRIPT_PREFIX/$MAJOR.$MINOR/get-pip.py"
python get-pip.py --user
fi
- name: Setup mock server
shell: bash -el {0}
run: |
conda create -y -n mock-server python=3.10
conda activate mock-server
python3 --version
nohup python3 tests/mock_server/main.py --port 9000 > py-mock-server.log &
echo $! > mock-server.pid
conda deactivate
- name: Install dependencies
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install -I -e ".[dev]"
- name: Run cases
shell: bash -el {0}
env:
QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }}
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
QINIU_TEST_BUCKET: ${{ secrets.QINIU_TEST_BUCKET }}
QINIU_TEST_NO_ACC_BUCKET: ${{ secrets.QINIU_TEST_NO_ACC_BUCKET }}
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
QINIU_UPLOAD_CALLBACK_URL: ${{secrets.QINIU_UPLOAD_CALLBACK_URL}}
QINIU_TEST_ENV: "travis"
MOCK_SERVER_ADDRESS: "http://127.0.0.1:9000"
run: |
flake8 --show-source --max-line-length=160 ./qiniu
python -m pytest ./test_qiniu.py tests --cov qiniu --cov-report=xml
- name: Post Setup mock server
if: ${{ always() }}
shell: bash
run: |
set +e
cat mock-server.pid | xargs kill
rm mock-server.pid
- name: Print mock server log
if: ${{ failure() }}
run: |
cat py-mock-server.log
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
test-win:
strategy:
fail-fast: false
max-parallel: 1
matrix:
python_version: ['2.7', '3.5', '3.9']
runs-on: windows-2019
# make sure only one test running,
# remove this when cases could run in parallel.
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Setup miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
channels: conda-forge
python-version: ${{ matrix.python_version }}
activate-environment: qiniu-sdk
auto-activate-base: false
- name: Setup pip
env:
PYTHON_VERSION: ${{ matrix.python_version }}
PIP_BOOTSTRAP_SCRIPT_PREFIX: https://bootstrap.pypa.io/pip
run: |
# reinstall pip by some python(<3.7) not compatible
$pyversion = [Version]"$ENV:PYTHON_VERSION"
if ($pyversion -lt [Version]"3.7") {
Invoke-WebRequest "$ENV:PIP_BOOTSTRAP_SCRIPT_PREFIX/$($pyversion.Major).$($pyversion.Minor)/get-pip.py" -OutFile "$ENV:TEMP\get-pip.py"
python $ENV:TEMP\get-pip.py --user
Remove-Item -Path "$ENV:TEMP\get-pip.py"
}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -I -e ".[dev]"
- name: Run cases
env:
QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }}
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
QINIU_TEST_BUCKET: ${{ secrets.QINIU_TEST_BUCKET }}
QINIU_TEST_NO_ACC_BUCKET: ${{ secrets.QINIU_TEST_NO_ACC_BUCKET }}
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
QINIU_UPLOAD_CALLBACK_URL: ${{secrets.QINIU_UPLOAD_CALLBACK_URL}}
QINIU_TEST_ENV: "github"
MOCK_SERVER_ADDRESS: "http://127.0.0.1:9000"
PYTHONPATH: "$PYTHONPATH:."
run: |
Write-Host "======== Setup Mock Server ========="
conda create -y -n mock-server python=3.10
conda activate mock-server
python --version
$processOptions = @{
FilePath="python"
ArgumentList="tests\mock_server\main.py", "--port", "9000"
PassThru=$true
RedirectStandardOutput="py-mock-server.log"
}
$mocksrvp = Start-Process @processOptions
$mocksrvp.Id | Out-File -FilePath "mock-server.pid"
conda deactivate
Sleep 3
Write-Host "======== Running Test ========="
python --version
python -m pytest ./test_qiniu.py tests --cov qiniu --cov-report=xml
- name: Post Setup mock server
if: ${{ always() }}
run: |
Try {
$mocksrvpid = Get-Content -Path "mock-server.pid"
Stop-Process -Id $mocksrvpid
Remove-Item -Path "mock-server.pid"
} Catch {
Write-Host -Object $_
}
- name: Print mock server log
if: ${{ failure() }}
run: |
Get-Content -Path "py-mock-server.log" | Write-Host
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}