mirror of
https://github.com/pufereq/python-template.git
synced 2025-12-15 07:39:32 +00:00
ci: rework workflows for uv
This commit is contained in:
104
.github/workflows/commit_checks.yaml
vendored
Normal file
104
.github/workflows/commit_checks.yaml
vendored
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
name: Commit Checks
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 🔀 checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: 📦 install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
|
- name: 🐍 python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
|
- name: 📦 sync depedencies
|
||||||
|
run: |
|
||||||
|
uv sync
|
||||||
|
uv sync --group test
|
||||||
|
|
||||||
|
- name: 🧪 run tests
|
||||||
|
id: test
|
||||||
|
run: |
|
||||||
|
uv run pytest -v
|
||||||
|
coverage:
|
||||||
|
name: Check coverage
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 🔀 checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: 📦 install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
|
- name: 🐍 python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
|
- name: 📦 sync depedencies
|
||||||
|
run: |
|
||||||
|
uv sync
|
||||||
|
uv sync --group test
|
||||||
|
|
||||||
|
- name: 🧪 run tests
|
||||||
|
id: test
|
||||||
|
run: |
|
||||||
|
uv run pytest -v --cov
|
||||||
|
|
||||||
|
- name: 📊 generate coverage report
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
uv run coverage json
|
||||||
|
cov_percent=$(jq '.totals.percent_covered' coverage.json)
|
||||||
|
cov_percent_rounded=$(python3 -c "print(round(${cov_percent}, 2))")
|
||||||
|
cov_lines=$(jq '.totals.covered_lines' coverage.json)
|
||||||
|
cov_missing=$(jq '.totals.missing_lines' coverage.json)
|
||||||
|
cov_total=$(jq '.totals.num_statements' coverage.json)
|
||||||
|
cov_excluded=$(jq '.totals.excluded_lines' coverage.json)
|
||||||
|
report_success=$(python3 -c "print(str(${cov_percent} == 100).lower())")
|
||||||
|
|
||||||
|
if (( $(echo "$cov_percent >= 100" | bc -l) )); then
|
||||||
|
badge_color="brightgreen"
|
||||||
|
elif (( $(echo "$cov_percent >= 90" | bc -l) )); then
|
||||||
|
badge_color="yellow"
|
||||||
|
else
|
||||||
|
badge_color="red"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "## 📊 Coverage Report" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
echo "| Total Lines | Covered | Missing | Excluded |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "|-------------|---------|---------|----------|" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| $cov_total | $cov_lines | $cov_missing | $cov_excluded |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
echo "<details>" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "<summary>Details</summary>" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||||
|
uv run coverage report >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "</details>" >> $GITHUB_STEP_SUMMARY
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Code coverage
|
name: PR Checks
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -7,43 +7,42 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
comment_coverage:
|
comment_coverage:
|
||||||
|
name: Comment coverage on PR
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: GH_TOKEN
|
|
||||||
if: env.GH_TOKEN == ''
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: 🔀 checkout
|
- name: 🔀 checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: "${{ env.GH_TOKEN }}"
|
token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: 📦 install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
- name: 🐍 python
|
- name: 🐍 python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
- name: 📦 setup pdm
|
- name: 📦 sync depedencies
|
||||||
uses: pdm-project/setup-pdm@v4
|
|
||||||
with:
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: 📦 install dependencies
|
|
||||||
run: |
|
run: |
|
||||||
pdm install
|
uv sync
|
||||||
|
uv sync --group test
|
||||||
|
|
||||||
|
|
||||||
- name: configure git
|
- name: configure git
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
- name: 🧪 run coverage
|
- name: 🧪 run coverage
|
||||||
run: |
|
run: |
|
||||||
pdm run pytest --cov --junitxml=pytest.xml --cov-report=term-missing | tee pytest-coverage.txt
|
uv run pytest --cov --junitxml=pytest.xml --cov-report=term-missing | tee pytest-coverage.txt
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: 📊 comment coverage
|
- name: 📊 comment coverage
|
||||||
uses: MishaKav/pytest-coverage-comment@main
|
uses: MishaKav/pytest-coverage-comment@main
|
||||||
with:
|
with:
|
||||||
pytest-coverage-path: pytest-coverage.txt
|
pytest-coverage-path: pytest-coverage.txt
|
||||||
junitxml-path: pytest.xml
|
junitxml-path: pytest.xml
|
||||||
46
.github/workflows/release.yaml
vendored
46
.github/workflows/release.yaml
vendored
@@ -34,40 +34,30 @@ on:
|
|||||||
- 'beta'
|
- 'beta'
|
||||||
- 'rc'
|
- 'rc'
|
||||||
- 'post'
|
- 'post'
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
bump_version:
|
bump_version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Bump version and create release
|
name: Bump version and create release
|
||||||
steps:
|
steps:
|
||||||
- name: GH_TOKEN
|
|
||||||
if: env.GH_TOKEN == ''
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: 🔀 checkout
|
- name: 🔀 checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: "${{ env.GH_TOKEN }}"
|
token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
submodules: 'recursive'
|
submodules: 'recursive'
|
||||||
|
|
||||||
|
- name: 📦 install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
- name: 🐍 python
|
- name: 🐍 python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version-file: "pyproject.toml"
|
||||||
|
|
||||||
- name: 📦 setup pdm
|
- name: 📦 sync depedencies
|
||||||
uses: pdm-project/setup-pdm@v4
|
|
||||||
with:
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: 📦 install dependencies
|
|
||||||
run: |
|
run: |
|
||||||
pdm install
|
uv sync
|
||||||
|
uv sync --group bump
|
||||||
|
|
||||||
- name: configure git
|
- name: configure git
|
||||||
run: |
|
run: |
|
||||||
@@ -78,40 +68,38 @@ jobs:
|
|||||||
if: ${{ github.event.inputs.auto_bump == 'true' }}
|
if: ${{ github.event.inputs.auto_bump == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
|
if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
|
||||||
pdm run semantic-release version --no-changelog --no-commit --no-push --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
|
uv run semantic-release version --no-changelog --no-commit --no-push --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
|
||||||
else
|
else
|
||||||
pdm run semantic-release version --no-changelog --no-commit --no-push
|
uv run semantic-release version --no-changelog --no-commit --no-push
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: 📦 bump version (manual)
|
- name: 📦 bump version (manual)
|
||||||
if: ${{ github.event.inputs.auto_bump == 'false' }}
|
if: ${{ github.event.inputs.auto_bump == 'false' }}
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
|
if [ "${{ github.event.inputs.as_pre_release }}" == "true" ]; then
|
||||||
pdm run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }} --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
|
uv run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }} --as-prerelease --prerelease-token ${{ github.event.inputs.prerelease_type }}
|
||||||
else
|
else
|
||||||
pdm run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }}
|
uv run semantic-release version --no-changelog --no-commit --no-push --${{ github.event.inputs.bump_type }}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: 📦 get new version
|
- name: 📦 get new version
|
||||||
id: get_version
|
id: get_version
|
||||||
run: echo "BUMPED_VERSION=$(cat ${{ github.event.repository.name }}/__init__.py | grep __version__ | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
|
run: echo "BUMPED_VERSION=$(cat pyproject.toml | grep -e "^version = " | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: 📝 create changelog
|
- name: 📝 create changelog
|
||||||
run: |
|
run: |
|
||||||
pdm run git-cliff -s header -l > release_body.md
|
uv run git-cliff -s header -l > release_body.md
|
||||||
echo "Changes:" && cat release_body.md
|
echo "Changes:" && cat release_body.md
|
||||||
pdm run git-cliff > CHANGELOG.md
|
uv run git-cliff > CHANGELOG.md
|
||||||
|
|
||||||
- name: 📤 push changes
|
- name: 📤 push changes
|
||||||
run: |
|
run: |
|
||||||
git add CHANGELOG.md pyproject.toml ${{ github.event.repository.name }}/__init__.py
|
git add CHANGELOG.md pyproject.toml src/*/__init__.py
|
||||||
git commit -m "chore(release): ${{ steps.get_version.outputs.BUMPED_VERSION }}"
|
git commit -m "chore(release): ${{ steps.get_version.outputs.BUMPED_VERSION }}"
|
||||||
git push origin main
|
git push origin main
|
||||||
|
|
||||||
- name: create release
|
- name: create release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }} ${{ steps.get_version.outputs.BUMPED_VERSION }} - ${{ github.event.inputs.short_description }}
|
name: ${{ github.event.repository.name }} ${{ steps.get_version.outputs.BUMPED_VERSION }} - ${{ github.event.inputs.short_description }}
|
||||||
tag_name: ${{ steps.get_version.outputs.BUMPED_VERSION }}
|
tag_name: ${{ steps.get_version.outputs.BUMPED_VERSION }}
|
||||||
@@ -126,7 +114,7 @@ jobs:
|
|||||||
- name: 📤 merge into develop
|
- name: 📤 merge into develop
|
||||||
run: |
|
run: |
|
||||||
git checkout develop
|
git checkout develop
|
||||||
git merge main --no-ff
|
git merge main
|
||||||
git push origin develop
|
git push origin develop
|
||||||
|
|
||||||
- name: ✅ done
|
- name: ✅ done
|
||||||
|
|||||||
38
.github/workflows/test.yaml
vendored
38
.github/workflows/test.yaml
vendored
@@ -1,38 +0,0 @@
|
|||||||
name: Run tests only
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: 🔀 checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: 🐍 python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.x'
|
|
||||||
|
|
||||||
- name: 📦 setup pdm
|
|
||||||
uses: pdm-project/setup-pdm@v4
|
|
||||||
with:
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: 📦 install dependencies
|
|
||||||
run: |
|
|
||||||
pdm install
|
|
||||||
|
|
||||||
- name: 🧪 run tests
|
|
||||||
id: test
|
|
||||||
run: |
|
|
||||||
pdm run pytest -v
|
|
||||||
Reference in New Issue
Block a user