ci: bump py package version to 0.1.6 #23
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-13, 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-13 | |
platform: darwin-amd64 | |
- os: macos-latest | |
platform: darwin-arm64 | |
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 | |
download_and_extract() { | |
local os=$1 | |
local arch=$2 | |
local ext=$3 | |
echo "Downloading binary for ${os}_${arch}" | |
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/gptcomet_${VERSION}_${os}_${arch}.${ext}" | |
echo "Download URL: $DOWNLOAD_URL" | |
if [ "$ext" = "zip" ]; then | |
curl -sL "$DOWNLOAD_URL" -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 "$DOWNLOAD_URL" -o "${WORK_DIR}/tmp.${ext}" | |
tar xzf "${WORK_DIR}/tmp.${ext}" -C "${WORK_DIR}" | |
mv "${WORK_DIR}/gptcomet" "py/gptcomet/gptcomet_${os}_${arch}" | |
fi | |
} | |
case "${{ matrix.os }}" in | |
"ubuntu-latest") | |
download_and_extract "linux" "amd64" "tar.gz" | |
download_and_extract "linux" "arm64" "tar.gz" | |
;; | |
"macos-13") | |
# 仅下载 Intel/AMD64 二进制文件 | |
download_and_extract "darwin" "amd64" "tar.gz" | |
mv "py/gptcomet/gptcomet_darwin_amd64" "py/gptcomet/gptcomet_macos_x86_64" | |
;; | |
"macos-latest") | |
# 仅下载 ARM64 二进制文件 | |
download_and_extract "darwin" "arm64" "tar.gz" | |
mv "py/gptcomet/gptcomet_darwin_arm64" "py/gptcomet/gptcomet_macos_arm64" | |
;; | |
esac | |
echo "Contents of py/gptcomet:" | |
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 | |
$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" | |
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 }} |