-
Notifications
You must be signed in to change notification settings - Fork 7
110 lines (93 loc) · 3.36 KB
/
test-pypi.yml
File metadata and controls
110 lines (93 loc) · 3.36 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
name: Publish to TestPyPI and Test
on:
push:
branches: [release-test]
jobs:
build-and-publish:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip build twine
- name: Set unique dev version and patch project name
id: set-version
run: |
BASE_VERSION=$(grep '^version =' pyproject.toml | cut -d '"' -f2 | cut -d'.' -f1-3)
UNIQUE_VERSION="${BASE_VERSION}.dev${{ github.run_number }}"
echo "New version: $UNIQUE_VERSION"
# Patch the version and name in pyproject.toml
sed -i "s/^version = .*/version = \"$UNIQUE_VERSION\"/" pyproject.toml
sed -i 's/^name = "artist-csp"/name = "artist-test"/' pyproject.toml
# Export version for downstream jobs
echo "version=$UNIQUE_VERSION" >> $GITHUB_OUTPUT
echo "VERSION=$UNIQUE_VERSION" >> $GITHUB_ENV
- name: Build package
run: python -m build
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
test-from-testpypi:
needs: build-and-publish
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
env:
VERSION: ${{ needs.build-and-publish.outputs.version }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install package from TestPyPI (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
max_attempts=5
sleep_seconds=10
for i in $(seq 1 $max_attempts); do
echo "Attempt $i: installing artist-test==$VERSION"
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --pre "artist-test[dev]==$VERSION" && break
echo "Not ready yet, retrying in $sleep_seconds seconds..."
sleep $sleep_seconds
done
- name: Install package from TestPyPI (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$maxAttempts = 5
$sleepSeconds = 10
$i = 0
do {
$i++
Write-Host "Attempt ${i}: installing artist-test==${env:VERSION}"
pip install --index-url https://test.pypi.org/simple/ `
--extra-index-url https://pypi.org/simple `
--pre `
"artist-test[dev]==$env:VERSION"
if ($LASTEXITCODE -eq 0) {
Write-Host "Install succeeded"
break
}
Write-Host "Not ready yet, retrying in ${sleepSeconds} seconds..."
Start-Sleep -Seconds $sleepSeconds
} while ($i -lt $maxAttempts)
if ($LASTEXITCODE -ne 0) {
throw "Failed to install after $maxAttempts attempts"
}
- name: Checkout repository (for tests)
uses: actions/checkout@v3
- name: Run tests with coverage
run: |
python --version
pytest --cov=artist