-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (190 loc) · 6.62 KB
/
Copy pathmain.yaml
File metadata and controls
211 lines (190 loc) · 6.62 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
name: Build and Test
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
tags: [ 'v*' ]
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
# Ensure conda is activated in all steps
shell: bash -el {0}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0 # Fetch all history for tags
- name: Set up conda
uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
with:
activate-environment: ""
auto-activate-base: true
channels: defaults
- name: Install build packages
run: |
# We're jumping through a lot of hoops here to make sure we
# are getting the latest versions of all packaging tools with
# minimal use of pip. By installing twine via conda first then
# pip we're getting all of its dependencies via conda.
conda update --all
conda install conda-forge::conda-build hatchling twine
conda remove twine --force
pip install twine
- name: Set version
run: |
chmod +x .githooks/pre-commit
.githooks/pre-commit
VERSION=$(grep "__version__ = " proxyspy.py | cut -d'"' -f2)
echo "Package version: $VERSION"
- name: Build pip package
run: |
hatchling build
twine check dist/*
- name: Build conda package
run: |
conda build conda.recipe --no-test
cp -r ${CONDA_PREFIX}/conda-bld dist/conda
find dist
- name: Upload packages
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: packages
path: dist
retention-days: 1
test:
needs: build
defaults:
run:
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up conda
uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
with:
activate-environment: ""
auto-activate-base: true
channels: defaults
- name: Download built packages
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: packages
path: dist
- name: Add random delay to space out tests
run: |
DELAY=$(( $RANDOM % 20 ))
echo "Waiting $DELAY seconds before starting tests"
sleep $DELAY
- name: Test package (conda)
run: |
conda_pkg=$(basename dist/conda/noarch/proxyspy-* | \
sed -E 's@^(.*)-(.*)-(.*)[.](conda|tar.bz2)$@\1=\2=\3@')
conda create -n testconda -c ./dist/conda \
python=${{ matrix.python-version }} \
"$conda_pkg" pytest requests psutil
conda activate testconda
pytest -v tests || pytest -v tests
- name: Test package (pip)
run: |
wheel_file=$(ls dist/proxyspy-*.whl)
conda create -n testpip python=${{ matrix.python-version }}
pip install "${wheel_file}[test]"
pytest -v tests || pytest -v tests
- name: Example output for timing study
run: |
conda activate testconda
proxyspy --debug --return-code 200 --return-data "hello" -- \
python -c 'import urllib.request; urllib.request.urlopen("https://httpbingo.org")'
publish:
needs: test
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Determine if we are actually publishing
id: set-mode
run: |
if [ ${{ github.event_name }} = "pull_request" ]; then
echo "Pull request; running in dry run mode."
echo "label=dry-run" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref }} = refs/tags/* ]]; then
echo "Tagged version; publishing to conda and PyPi."
echo "label=main" >> $GITHUB_OUTPUT
else
echo "Untagged version; publishing to conda dev label only."
echo "label=dev" >> $GITHUB_OUTPUT
fi
error=no
if [ -z "${{ secrets.ANACONDA_CHANNEL }}" ]; then
echo "ERROR: missing the ANACONDA_CHANNEL secret"
error=yes
fi
if [ -z "${{ secrets.ANACONDA_TOKEN }}" ]; then
echo "ERROR: missing the ANACONDA_TOKEN secret"
error=yes
fi
if [ -z "${{ secrets.PYPI_API_TOKEN }}" ]; then
echo "ERROR: missing the PYPI_API_TOKEN secret"
error=yes
fi
if [ $error = yes ]; then
echo "Populate these secrets before proceeding."
false
fi
- name: Download built packages
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: packages
path: dist
- name: Set up conda
uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
with:
activate-environment: ""
auto-activate-base: true
channels: defaults
- name: Install publishing packages
run: |
# Duplicate our approach from above for installing twine
conda update --all
conda install anaconda-client twine
conda remove twine --force
pip install twine
- name: Publish to PyPI (tagged releases only)
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
LABEL: ${{ steps.set-mode.outputs.label }}
run: |
command=check
if [ "$LABEL" = dry-run ]; then
echo "Pull request; NOT publishing to PyPi."
elif [ "$LABEL" = dev ]; then
echo "Untagged build; NOT publishing to PyPi."
else
echo "Tagged build; publishing to PyPi."
command=upload
fi
twine $command dist/*.whl dist/*.tar.gz
- name: Upload to Anaconda.org (tagged and untagged releases)
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
LABEL: ${{ steps.set-mode.outputs.label }}
USER: ${{ secrets.ANACONDA_CHANNEL }}
run: |
if [ "$LABEL" = dry-run ]; then
echo "Pull request; NOT publishing to the channel '$USER'."
anaconda --version
else
echo "Publishing to conda: channel '$USER', label '$LABEL'."
find dist/conda -name "*.tar.bz2" -o -name "*.conda" | while read file; do
anaconda upload --force -u "$USER" -l "$LABEL" "$file"
done
fi