Skip to content

Release

Release #44

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get version
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- uses: actions/setup-go@v4
with:
go-version: ">=1.20.0"
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check-version:
needs: goreleaser
runs-on: ubuntu-latest
outputs:
is_dev: ${{ steps.check_tag.outputs.is_dev }}
steps:
- name: Check if version is prerelease
id: check_tag
run: |
VERSION=${GITHUB_REF#refs/tags/}
if [[ $VERSION =~ .*-dev$ ]]; then
echo "is_dev=true" >> $GITHUB_OUTPUT
else
echo "is_dev=false" >> $GITHUB_OUTPUT
fi
python-package:
needs: check-version
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: windows-latest
arch: amd64
- os: macos-13
platform: macos
arch: amd64
- os: macos-14
platform: macos
arch: arm64
- os: ubuntu-20.04
platform: linux
arch: amd64
# - os: ubuntu-22.04-arm64
# platform: linux
# arch: arm64
os: [windows-latest, macos-13, macos-14, ubuntu-20.04]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup Nushell
uses: hustcer/setup-nu@v3
with:
version: "0.86.0"
- name: Set matrix vars
shell: bash
run: |
echo "MATRIX_ARCH=${{ matrix.arch }}" >> $GITHUB_ENV
echo "MATRIX_OS=${{ matrix.os }}" >> $GITHUB_ENV
- name: Set version and download binary
shell: nu {0}
run: |
# Set version variables
let package_version = $env.GITHUB_REF | str replace 'refs/tags/' ''
let version = $package_version | str replace 'v' ''
$env.PACKAGE_VERSION = $package_version
$env.VERSION = $version
# Determine OS and set asset details
let os = if $env.RUNNER_OS == 'Windows' {
{name: 'windows', ext: 'zip', extract: 'expand', bin_suffix: 'exe'}
} else if $env.RUNNER_OS == 'macOS' {
{name: 'darwin', ext: 'tar.gz', extract: 'tar', bin_suffix: 'mac'}
} else {
{name: 'linux', ext: 'tar.gz', extract: 'tar', bin_suffix: 'linux'}
}
# Map architecture names - always use amd64 or arm64
let arch = if $env.MATRIX_ARCH in ['x86_64', 'amd64'] {
'amd64'
} else if $env.MATRIX_ARCH in ['arm64', 'aarch64'] {
'arm64'
} else {
$env.MATRIX_ARCH
}
# Build asset name and URL
let asset_name = $'gptcomet_($version)_($os.name)_($arch).($os.ext)'
let asset_url = $'https://github.com/($env.GITHUB_REPOSITORY)/releases/download/($package_version)/($asset_name)'
print $'Downloading from ($asset_url)'
# Download and extract
http get $asset_url | save -f binary.archive
tar -xzf binary.archive
# Move binary to appropriate location - use arch consistently
if $os.name == 'windows' {
mv gptcomet.exe $"py/gptcomet/bin/gptcomet_($arch).exe"
} else if $os.name == 'darwin' {
mv gptcomet $"py/gptcomet/bin/gptcomet_($arch)_mac"
} else {
mv gptcomet $"py/gptcomet/bin/gptcomet_($arch)_linux"
}
# Set platform tag for wheel
let platform = if $os.name == 'windows' {
'win_amd64'
} else if $os.name == 'darwin' {
'macos'
} else {
'linux'
}
$env.PLATFORM = $platform
print $'Set PLATFORM=$platform'
- name: Install dependencies
run: |
echo "Installing dependencies"
python -m pip install --upgrade pip
pip install uv
uv --version
- name: Build package
run: |
echo "Building package on ${{ matrix.os }} with arch ${{ matrix.arch }}"
uv build --wheel
ls dist/
- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}-${{ matrix.arch }}
path: dist/*.whl
retention-days: 1
publish:
needs: [check-version, python-package]
environment: ${{ needs.check-version.outputs.is_dev == 'true' && 'testpypi' || 'pypi' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install UV
run: |
python -m pip install --upgrade pip
pip install uv
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: dist
- name: Prepare dist directory
run: |
mkdir -p final_dist
find dist -name "*.whl" -exec cp {} final_dist/ \;
ls -la final_dist/
- name: Install twine
run: |
python -m pip install --upgrade pip
pip install twine
- name: Publish to TestPyPI
if: needs.check-version.outputs.is_dev == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
echo "Publishing to TestPyPI"
twine upload final_dist/* --verbose --repository-url https://test.pypi.org/legacy/
- name: Publish to PyPI
if: needs.check-version.outputs.is_dev != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
echo "Publishing to PyPI"
twine upload final_dist/* --verbose