Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 59 additions & 64 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,57 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/guides/building-and-testing-python
# This workflow uses uv for dependency management, testing, and building.
# It maintains parity with the original python-app.yml but leverages uv's speed and caching.

name: Python application
name: Python application via uv

on:
push:
branches: [ release/v1 ]
pull_request:
branches: [ release/v1 ]
workflow_dispatch:
inputs:
mode:
description: "Pre-release mode (alpha or rc)"
required: true
type: choice
options:
- alpha
- rc
default: alpha

jobs:
test:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os:
- Ubuntu
- Windows
- MacOS
py:
- "3.13"
- "3.12"
- "3.11"
- "3.10"
os: [Ubuntu, Windows, MacOS]
py: ["3.14", "3.13", "3.12", "3.11", "3.10"]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}

- name: Cache python packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Cache tox results
uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
path: .tox
key: ${{ runner.os }}-${{ matrix.py }}-tox-${{ hashFiles('tox.ini') }}-${{ hashFiles('requirements*.txt') }}
restore-keys: ${{ runner.os }}-${{ matrix.py }}-tox-
enable-cache: true

- name: Set up Python ${{ matrix.py }}
run: uv python install ${{ matrix.py }}

- name: Install dependencies
run: |
python3 -m pip install -q --upgrade pip
python3 -m pip install -q -r requirements-dev.txt
# Installs dev dependencies (including tox, tox-gh-actions) into the project environment
run: uv sync --frozen --group dev

- name: Test with tox
# This will run flake8 tests (which will fail quickly) alongside running
# pylint for a deeper inspect and running unit tests for all available
# python interpreters in parallel
# uv run tox will use the project environment where tox and tox-gh-actions are installed.
# tox-gh-actions will automatically filter the envlist based on the active python version.
env:
TOX_PARALLEL_NO_SPINNER: 1
run: |
tox --parallel
run: uv run tox --parallel

pypi-publish:
name: Upload release to PyPI
# Don't try to publish except when this is a push onto the main branch of the master repos.
if: github.repository == 'eyeonus/Trade-Dangerous' && github.event_name == 'push' && github.ref == 'refs/heads/release/v1'
if: github.repository == 'eyeonus/Trade-Dangerous' && ((github.event_name == 'push' && github.ref == 'refs/heads/release/v1') || github.event_name == 'workflow_dispatch')
needs: test
runs-on: ubuntu-latest
environment:
Expand All @@ -72,50 +61,56 @@ jobs:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write
steps:
# retrieve your distributions here
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Set up Python 3.10
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.10"
enable-cache: true

- name: Install dependencies
run: |
python3 -m pip install -q --upgrade pip
python3 -m pip install -q -r requirements-publish.txt
# Installs publish dependencies (python-semantic-release, build)
# NOTE: Version of Python used determined by ".python-version" file.
run: uv sync --frozen --group publish

- name: Configure git
run: |
git config --global user.name "semantic-release (via GitHub Actions)"
git config --global user.email "semantic-release@gh"

# This action uses Python Semantic Release v8
- name: Python Semantic Release
- name: Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@v10
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build a binary wheel and a source tarball
run: python3 -m build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use prerelease mode on manual dispatch; normal version on push
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
uv run semantic-release version --prerelease --as-prerelease --prerelease-token ${{ github.event.inputs.mode }}
else
uv run semantic-release version
fi

# Check if a tag was created at HEAD to determine if a release occurred
if git describe --exact-match --tags HEAD >/dev/null 2>&1; then
echo "released=true" >> $GITHUB_OUTPUT
else
echo "released=false" >> $GITHUB_OUTPUT
fi

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Build artifacts
if: steps.release.outputs.released == 'true'
run: uv build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'

- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Use semantic-release to publish to GitHub Releases (skipping PyPI as we used the action above)
run: uv run semantic-release publish
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
Loading