-
Notifications
You must be signed in to change notification settings - Fork 1
211 lines (180 loc) · 6.34 KB
/
release.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
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: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
detect-env:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.set-env.outputs.environment }}
pypi_repo: ${{ steps.set-env.outputs.pypi_repo }}
steps:
- name: Set environment based on tag
id: set-env
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "Tag: $TAG"
if [[ "$TAG" == *"-dev" ]]; then
echo "Development version detected"
echo "environment=testpypi" >> $GITHUB_OUTPUT
echo "pypi_repo=-r testpypi" >> $GITHUB_OUTPUT
else
echo "Release version detected"
echo "environment=pypi" >> $GITHUB_OUTPUT
echo "pypi_repo=" >> $GITHUB_OUTPUT
fi
goreleaser:
needs: detect-env
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21'
- name: List files
run: |
go version
ls -la
ls -la py
cat py/pyproject.toml
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
python-build:
needs: [detect-env, goreleaser]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: ubuntu-latest
platform: linux
- os: windows-latest
platform: windows
- os: macos-latest
platform: darwin
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install PDM
run: |
cd py
python -m pip install --upgrade pip
pip install pdm
- name: Download Go binaries (Unix)
if: runner.os != 'Windows'
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v} # Remove 'v' prefix
WORK_DIR=$(mktemp -d)
mkdir -p py/gptcomet
# Function to download and extract binary
download_and_extract() {
local os=$1
local arch=$2
local ext=$3
echo "Downloading binary for ${os}_${arch}"
if [ "$ext" = "zip" ]; then
curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/gptcomet_${VERSION}_${os}_${arch}.${ext}" -o "${WORK_DIR}/tmp.${ext}"
unzip -j "${WORK_DIR}/tmp.${ext}" "gptcomet*" -d "py/gptcomet"
if [ "$os" = "windows" ]; then
mv py/gptcomet/gptcomet.exe "py/gptcomet/gptcomet_${os}_${arch}.exe"
fi
else
curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/gptcomet_${VERSION}_${os}_${arch}.${ext}" | tar xz -C "${WORK_DIR}"
mv "${WORK_DIR}/gptcomet" "py/gptcomet/gptcomet_${os}_${arch}"
fi
}
# Download platform-specific binary
case "${{ matrix.os }}" in
"ubuntu-latest")
download_and_extract "linux" "amd64" "tar.gz"
download_and_extract "linux" "arm64" "tar.gz"
;;
"macos-latest")
download_and_extract "darwin" "amd64" "tar.gz"
download_and_extract "darwin" "arm64" "tar.gz"
;;
esac
# Cleanup
rm -rf "${WORK_DIR}"
# List files for debugging
ls -la py/gptcomet/
- name: Download Go binaries (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$TAG = $env:GITHUB_REF -replace '^refs/tags/', ''
$VERSION = $TAG -replace '^v', ''
$WORK_DIR = Join-Path $env:TEMP ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $WORK_DIR | Out-Null
New-Item -ItemType Directory -Force -Path "py/gptcomet" | Out-Null
# Download and extract Windows binary
$url = "https://github.com/${{ github.repository }}/releases/download/${TAG}/gptcomet_${VERSION}_windows_amd64.zip"
$zipPath = Join-Path $WORK_DIR "gptcomet.zip"
Write-Host "Downloading from: $url"
Invoke-WebRequest -Uri $url -OutFile $zipPath
Expand-Archive -Path $zipPath -DestinationPath $WORK_DIR
Move-Item -Path (Join-Path $WORK_DIR "gptcomet.exe") -Destination "py/gptcomet/gptcomet_windows_amd64.exe"
# Cleanup
Remove-Item -Recurse -Force $WORK_DIR
Get-ChildItem "py/gptcomet"
- name: Install dependencies
run: |
cd py
pdm install
- name: Build package
run: |
cd py
pdm build
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.platform }}-py${{ matrix.python-version }}
path: py/dist/*.whl
if-no-files-found: error
python-publish:
needs: [detect-env, python-build]
runs-on: ubuntu-latest
environment: ${{ needs.detect-env.outputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Download all wheels
uses: actions/download-artifact@v4
with:
pattern: wheel-*
path: py/dist
merge-multiple: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install PDM
run: |
python -m pip install --upgrade pip
pip install pdm
- name: Publish to PyPI
env:
PDM_PUBLISH_USERNAME: __token__
PDM_PUBLISH_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
cd py
ls -al gptcomet
ls -al dist
pdm publish --no-build ${{ needs.detect-env.outputs.pypi_repo }}