Skip to content

Refactor CI workflows to remove pytest dependency and update test exe… #7

Refactor CI workflows to remove pytest dependency and update test exe…

Refactor CI workflows to remove pytest dependency and update test exe… #7

Workflow file for this run

name: Build and Release
on:
push:
branches: [ main ]
paths:
- '**/*.py'
- 'pyproject.toml'
- 'requirements*.txt'
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual trigger'
required: false
default: 'Manual release'
permissions:
contents: write
id-token: write # For PyPI trusted publishing
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build toml
- name: Build package
run: |
python -m build
- name: Install package
run: |
pip install dist/*.whl
- name: Test installation
run: |
python -c "import diffgetr; print('Package imported successfully')"
python -c "from diffgetr.diff_get import main; print('CLI function available')"
- name: Run unit tests
run: |
python -m unittest discover diffgetr.tests -v
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish-pypi:
runs-on: ubuntu-latest
needs: build-and-test
environment: release
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
create-github-release:
runs-on: ubuntu-latest
needs: [build-and-test, publish-pypi]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for changelog
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install toml
- name: Get version and create release
run: |
python -c "
import toml
import os
# Read version from pyproject.toml
with open('pyproject.toml', 'r') as f:
data = toml.load(f)
version = data['project']['version']
description = data['project']['description']
# Set environment variables for next step
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f'VERSION={version}\n')
f.write(f'DESCRIPTION={description}\n')
"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Generate changelog
run: |
echo "## Changes" > CHANGELOG.md
echo "" >> CHANGELOG.md
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
echo "Changes since $LAST_TAG:" >> CHANGELOG.md
git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md
else
echo "Initial release" >> CHANGELOG.md
git log --pretty=format:"- %s (%h)" >> CHANGELOG.md
fi
echo "" >> CHANGELOG.md
echo "## Package Files" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "The following files are available for download:" >> CHANGELOG.md
for file in dist/*; do
echo "- $(basename $file)" >> CHANGELOG.md
done
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
name: Release v${{ env.VERSION }}
body_path: CHANGELOG.md
files: dist/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}