Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from poetry to uv and enable testpypi publishing #9

Merged
merged 3 commits into from
Sep 6, 2024
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
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

38 changes: 19 additions & 19 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: Setup Environment
description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies
description: Install requested pipx dependencies, configure the system python, and install uv and the package dependencies

inputs:
poetry-install-options:
uv-install-options:
default: ""
poetry-version:
default: 1.8.2
uv-version:
default: 0.4.5
python-version:
required: true
cache-pre-commit:
Expand All @@ -25,7 +25,7 @@ runs:
id: pipx-env-setup
# pipx default home and bin dir are not writable by the cache action
# so override them here and add the bin dir to PATH for later steps.
# This also ensures the pipx cache only contains poetry
# This also ensures the pipx cache only contains uv
run: |
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
Expand All @@ -42,43 +42,43 @@ runs:
uses: actions/cache@v4
with:
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }}
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-uv-${{ inputs.uv-version }}

- name: Install poetry
- name: Install uv
if: steps.pipx-cache.outputs.cache-hit != 'true'
id: install-poetry
id: install-uv
shell: bash
run: |-
pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}"
pipx install uv==${{ inputs.uv-version }} --python "${{ steps.setup-python.outputs.python-path }}"

- name: Read poetry cache location
id: poetry-cache-location
- name: Read uv cache location
id: uv-cache-location
shell: bash
run: |-
echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
echo "uv-venv-location=$(uv cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
name: Poetry cache
name: uv cache
with:
path: |
${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}
${{ steps.uv-cache-location.outputs.uv-venv-location }}
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('uv.lock') }}-options-${{ inputs.uv-install-options }}

- name: "Poetry install"
- name: "uv install"
shell: bash
run: |
poetry install ${{ inputs.poetry-install-options }}
uv sync --python "${{ steps.setup-python.outputs.python-path }}" ${{ inputs.uv-install-options }}

- name: Read pre-commit version
if: inputs.cache-pre-commit == 'true'
id: pre-commit-version
shell: bash
run: >-
echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
echo "pre-commit-version=$(uv run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
if: inputs.cache-pre-commit == 'true'
name: Pre-commit cache
with:
path: ~/.cache/pre-commit/
key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
35 changes: 24 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
branches: ["main"]

env:
POETRY_VERSION: 1.8.3
UV_VERSION: 0.4.5
PACKAGE_NAME: firebase_messaging

jobs:
linting:
Expand All @@ -22,12 +23,12 @@ jobs:
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: ""
uv-version: ${{ env.UV_VERSION }}
uv-install-options: ""
cache-pre-commit: true
- name: "Run pre-commit checks"
run: |
poetry run pre-commit run --all-files
uv run pre-commit run --all-files --verbose

docs:
name: "Build docs"
Expand All @@ -42,11 +43,11 @@ jobs:
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
poetry-install-options: "--extras docs --without dev"
- name: Make docs poetry
uv-version: ${{ env.UV_VERSION }}
uv-install-options: "--extra docs --no-dev"
- name: Make docs
run: |
poetry run make -C docs html
uv run make -C docs html

tests:
name: Tests - Python ${{ matrix.python-version}} on ${{ matrix.os }}
Expand All @@ -64,15 +65,27 @@ jobs:
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
uv-version: ${{ env.UV_VERSION }}
uv-install-options: ""
- name: Run tests
run: >
poetry run pytest tests/
--cov=firebase_messaging --cov-report=xml
uv run pytest tests/
--cov=${{ env.PACKAGE_NAME }} --cov-report=xml
--cov-report=term-missing --import-mode importlib
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
file: coverage.xml
debug: true
parallel: true
if: ${{ success() && matrix.python-version == '3.12' }}

finish:
name: Finish coverage build
needs: tests
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/[email protected]
with:
parallel-finished: true
142 changes: 114 additions & 28 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,124 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package
name: Publish Python distribution to PyPI and TestPyPI

on:
release:
types: [published]
push:
branches: ["main"]
tags:
- '*'
env:
UV_VERSION: 0.4.5
PYPI_PROJECT: firebase-messaging

# GITHUB_TOKEN must have write access
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/signing-the-distribution-packages

jobs:
deploy:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install uv
run: |-
pipx install uv==${{ env.UV_VERSION }} --python "${{ steps.setup-python.outputs.python-path }}"
- name: Build with uv
run: uv build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/firebase-messaging
url: https://pypi.org/p/${{ env.PYPI_PROJECT }}
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Create github release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Repo clone is required for --notes-from-tag to work
run: |
gh repo clone '${{ github.repository }}'
cd ${{ github.event.repository.name }}
gh release create '${{ github.ref_name }}' --verify-tag --notes-from-tag --title '${{ github.ref_name }}' ${{ contains(github.ref_name, 'dev') && '--prerelease --latest=false' || '--latest=true' }}
cd ..
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'

publish-to-testpypi:
name: Publish to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/${{ env.PYPI_PROJECT }}

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetry==1.8.3
- name: Build
run: |
poetry build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
__pycache__/
.vscode/

.coverage
.tox
htmlcov/
docs/build
dist
.venv
12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
repos:

- repo: https://github.com/python-poetry/poetry
rev: "1.8"
hooks:
- id: poetry-check
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.4.5
hooks:
# Update the uv lockfile
- id: uv-lock

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down Expand Up @@ -34,7 +36,7 @@ repos:
# for more accurate checking than using the pre-commit mypy mirror
- id: mypy
name: mypy
entry: ./run-in-env.sh mypy
entry: uv run mypy
language: system
types_or: [python, pyi]
require_serial: true
Expand Down
Loading