-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (151 loc) · 5.74 KB
/
ci-testpypi.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
name: ci-testpypi
# This workflow bumps the version of the package (without commit and tag),
# builds and uploads the package to TestPyPI,
# and tests the installation under py3 and py2 from TestPyPI.
#
# This workflow is triggered by:
# - a manual trigger
# - a push to the repository with changes in the certain paths
# - a workflow run from ci-unittest with success conclusion
on:
workflow_dispatch:
push:
paths:
- '.github/workflows/ci-testpypi.yml'
- 'pyproject.toml'
workflow_run:
workflows: ["ci-unittest"]
types:
- completed
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TESTPYPI_TOKEN }}
PROJECT_NAME_FOR_TESTPYPI: shadowsocks-manager-alexzhangs
jobs:
check-run-history:
runs-on: ubuntu-latest
outputs:
RUN_HISTORY: ${{ steps.check-run.outputs.RUN_HISTORY }}
steps:
- name: Check run history
id: check-run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
run_history=$(gh api repos/:owner/:repo/actions/workflows/ci-testpypi.yml/runs --jq '.workflow_runs[] | select(.event == "push" and .head_sha == "${{ github.sha }}") | .id' | wc -l)
echo "RUN_HISTORY=$run_history" >> $GITHUB_OUTPUT
testpypi-py3-build-and-upload:
runs-on: ubuntu-latest
needs: check-run-history
if: ${{ github.event_name == 'workflow_dispatch'
|| github.event_name == 'push'
|| (github.event_name == 'workflow_run'
&& github.event.workflow_run.conclusion == 'success'
&& needs.check-run-history.outputs.RUN_HISTORY == '0') }}
outputs:
NEW_VERSION: ${{ steps.bump-version.outputs.NEW_VERSION }}
strategy:
fail-fast: false
matrix:
python-version: ['3.12.3']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install build twine bump-my-version
- name: Update project name to avoid naming conflict in TestPyPI
run: |
sed -i 's/^name = .*/name = "${{ env.PROJECT_NAME_FOR_TESTPYPI }}"/' pyproject.toml
- name: Bump version without commit and tag
id: bump-version
run: |
current_version=$(bump-my-version show-bump | awk 'NR==1 {print $1}')
new_versoin="${current_version}-$(date +%Y%m%d%H%M%S)"
bump-my-version bump --verbose --no-commit --no-tag --new-version "${new_versoin}" suffix
echo "NEW_VERSION=${new_versoin}" >> $GITHUB_OUTPUT
- name: Build source and binary distributions
run: python -m build
- name: Upload to TestPyPI
run: twine upload --repository testpypi dist/*
testpypi-py3-install:
runs-on: ubuntu-latest
needs: testpypi-py3-build-and-upload
strategy:
fail-fast: false
matrix:
python-version: ['3.12.3']
env:
NEW_VERSION: ${{ needs.testpypi-py3-build-and-upload.outputs.NEW_VERSION }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel
- name: Install from binary distribution
env:
PIP_INDEX_URL: https://test.pypi.org/simple/
uses: nick-invision/retry@v2
with:
timeout_minutes: 6
max_attempts: 3
retry_on: error
command: |
pip install --no-deps --only-binary ${{ env.PROJECT_NAME_FOR_TESTPYPI }} ${{ env.PROJECT_NAME_FOR_TESTPYPI }}==${{ env.NEW_VERSION }}
- name: Clean up for installing source distribution
run: |
pip uninstall -y ${{ env.PROJECT_NAME_FOR_TESTPYPI }}
- name: Install from source distribution with setuptools and wheel required
env:
PIP_INDEX_URL: https://test.pypi.org/simple/
uses: nick-invision/retry@v2
with:
timeout_minutes: 3
max_attempts: 3
retry_on: error
command: |
pip install --no-build-isolation --no-deps --no-binary ${{ env.PROJECT_NAME_FOR_TESTPYPI }} ${{ env.PROJECT_NAME_FOR_TESTPYPI }}==${{ env.NEW_VERSION }}
testpypi-py2-install:
runs-on: ubuntu-latest
needs: testpypi-py3-build-and-upload
container:
image: python:2.7
env:
NEW_VERSION: ${{ needs.testpypi-py3-build-and-upload.outputs.NEW_VERSION }}
steps:
- name: Install dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel
- name: Install from binary distribution
env:
PIP_INDEX_URL: https://test.pypi.org/simple/
uses: nick-invision/retry@v2
with:
timeout_minutes: 6
max_attempts: 3
retry_on: error
command: |
pip install --no-deps --only-binary ${{ env.PROJECT_NAME_FOR_TESTPYPI }} ${{ env.PROJECT_NAME_FOR_TESTPYPI }}==${{ env.NEW_VERSION }}
- name: Clean up for install source distribution
run: |
pip uninstall -y ${{ env.PROJECT_NAME_FOR_TESTPYPI }}
- name: Install from source distribution with setuptools and wheel required
env:
PIP_INDEX_URL: https://test.pypi.org/simple/
uses: nick-invision/retry@v2
with:
timeout_minutes: 3
max_attempts: 3
retry_on: error
command: |
pip install --no-build-isolation --no-deps --no-binary ${{ env.PROJECT_NAME_FOR_TESTPYPI }} ${{ env.PROJECT_NAME_FOR_TESTPYPI }}==${{ env.NEW_VERSION }}