Skip to content

Commit

Permalink
Merge pull request #7 from Gandi/features/uv-gh-action
Browse files Browse the repository at this point in the history
Features/uv gh action
  • Loading branch information
mardiros authored Feb 13, 2025
2 parents 5284fbc + 10903f2 commit d7ec652
Show file tree
Hide file tree
Showing 31 changed files with 1,763 additions and 508 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Build envsub tarballs for supported python.

name: "Build artifact"

on:
workflow_call:
inputs:
release-version:
required: true
type: string
dry-run:
required: true
type: boolean
python-version:
required: true
type: string
pull_request:
paths:
# When we change pyproject.toml, we want to ensure that the maturin builds still work.
- pyproject.toml
# And when we change this workflow itself...
- .github/workflows/build-artifacts.yml

concurrency:
group: sdist-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
sdist:
name: Build artifact for ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install the project
run: uv sync

- name: Build tarball
run: uv build

- name: "Upload sdist"
uses: actions/upload-artifact@v4
with:
name: pypi_files
path: dist/*
35 changes: 35 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Publish a release to PyPI.
#
name: "Publish to PyPI"

on:
workflow_call:
inputs:
release-version:
required: true
type: string
dry-run:
required: true
type: boolean

jobs:
pypi-publish:
name: Upload to PyPI ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
if: ${{ !inputs.dry-run }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: pypi_files
path: dist
merge-multiple: true

- uses: pdm-project/setup-pdm@v4
with:
python-version: 3.12

- name: Publish package distributions to PyPI
run: pdm publish --no-build
98 changes: 98 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Release

on:
push:
tags:
- 'v*' # Automatically trigger on version tags
- 'dry-run'

workflow_dispatch:
inputs:
tag:
description: "Release Tag"
required: true
default: "dry-run"
type: string

env:
PYTHON_VERSION: "3.12"

permissions:
contents: read
id-token: write
pages: write

jobs:
plan:
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.release-version.outputs.release_version }}
dry-run: ${{ steps.release-version.outputs.dry_run }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set Release Version
id: release-version
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "release_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
if [ "${{ github.ref_name }}" == "dry-run" ]; then
echo "dry_run=true" >> $GITHUB_OUTPUT
else
echo "dry_run=false" >> $GITHUB_OUTPUT
fi
else
version="${{ github.event.inputs.tag || 'dry-run' }}"
if [ "${version}" == "dry-run" ]; then
echo "release_version=latest" >> $GITHUB_OUTPUT
echo "dry_run=true" >> $GITHUB_OUTPUT
else
echo "release_version=${version}" >> $GITHUB_OUTPUT
echo "dry_run=false" >> $GITHUB_OUTPUT
fi
fi
- name: Display Release Version
run: echo "The release version is ${{ steps.release-version.outputs.release_version }}"

unit-tests:
uses: ./.github/workflows/tests.yml
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

build-artifacts:
needs:
- plan
- unit-tests
uses: ./.github/workflows/build-artifacts.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}
python-version: '3.12'

tests-artifacts:
needs:
- plan
- build-artifacts
uses: ./.github/workflows/tests-artifacts.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}

publish-pypi:
needs:
- plan
- tests-artifacts
uses: ./.github/workflows/publish-pypi.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}
permissions:
contents: read
id-token: write

dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}
permissions:
id-token: write
pages: write
41 changes: 41 additions & 0 deletions .github/workflows/tests-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests artifacts

# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
workflow_call:
inputs:
release-version:
required: true
type: string
description: "release number"
dry-run:
required: true
type: boolean
description: "blank run means that the release will not be pushed"

jobs:
test-sdist:
name: test tarball archive of ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/download-artifact@v4
with:
pattern: pypi_files
path: dist
merge-multiple: true

- name: "Install"
run: |
pip install dist/gandi_pyramid_prometheus-*.whl --force-reinstall
- name: "Test sdist"
run: |
python -c "from gandi_pyramid_prometheus import __version__; print(__version__, end='')"
60 changes: 60 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

workflow_dispatch:

workflow_call:
secrets:
CODECOV_TOKEN:
required: true # Ensures CODECOV_TOKEN is required for this workflow


jobs:
CI:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install the project
run: uv sync --group dev


- name: Run tests
run: |
uv run pytest tests --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=gandi_pyramid_prometheus --cov-report=xml --cov-report=html
- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.python-version }}.xml

- name: Upload test results to Codecov
if: ${{ !cancelled() }} && matrix.python-version == '3.12' && github.event_name != 'workflow_dispatch'
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: junit/test-results-${{ matrix.python-version }}.xml

- name: Codecov
if: matrix.python-version == '3.12' && github.event_name != 'workflow_dispatch'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

47 changes: 47 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package := 'gandi_pyramid_prometheus'
default_test_suite := 'tests'

install:
uv sync --group dev

upgrade: && update
uv lock --upgrade

update:
#!/bin/bash
uv sync --group dev
uv export --no-hashes > .gitlab/ci/requirements.txt

test: lint unittest

lint:
uv run ruff check .

unittest test_suite=default_test_suite:
uv run pytest -sxv {{test_suite}}

fmt:
uv run ruff check --fix .
uv run ruff format src tests

cov test_suite=default_test_suite:
rm -f .coverage
rm -rf htmlcov
uv run pytest --cov-report=html --cov={{package}} {{test_suite}}
xdg-open htmlcov/index.html

release major_minor_patch: test && changelog
uvx --with=pdm,pdm-bump --python-preference system pdm bump {{major_minor_patch}}

changelog:
uv run python bin/write_changelog.py
cat CHANGELOG.rst >> CHANGELOG.rst.new
rm CHANGELOG.rst
mv CHANGELOG.rst.new CHANGELOG.rst
$EDITOR CHANGELOG.rst

publish:
git commit -am "Release $(uv run scripts/get_version.py)"
git tag "v$(uv run scripts/get_version.py)"
git push origin "v$(uv run scripts/get_version.py)"
git push origin main
6 changes: 6 additions & 0 deletions bin/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import gandi_pyramid_prometheus

__version__ = gandi_pyramid_prometheus.__version__

if __name__ == "__main__":
print(__version__, end="")
15 changes: 15 additions & 0 deletions bin/write_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
import datetime

import gandi_pyramid_prometheus

header = (
f"{gandi_pyramid_prometheus.__version__} - "
f"Released on {datetime.datetime.now().date().isoformat()}"
)
with open("CHANGELOG.rst.new", "w") as changelog:
changelog.write(header)
changelog.write("\n")
changelog.write("-" * len(header))
changelog.write("\n")
changelog.write("* please write here \n\n")
Loading

0 comments on commit d7ec652

Please sign in to comment.