Skip to content

Update GitHub Actions workflow to enhance test reporting #157

Update GitHub Actions workflow to enhance test reporting

Update GitHub Actions workflow to enhance test reporting #157

Workflow file for this run

name: CloudProxy CI/CD Pipeline
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'docs/**'
jobs:
test:
name: 🧪 Test Suite
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🐍 Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: 📚 Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-mock pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: 🧪 Run pytest
run: |
pytest --cov=. --cov-report=xml --junitxml=junit.xml -o junit_family=legacy
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
prepare-release:
name: 🏷️ Prepare Release
needs: test
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.set_outputs.outputs.new_version }}
permissions:
contents: write
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔍 Get latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git tag -l --sort=-v:refname "v*" | head -n 1 || echo "v0.0.0")
echo "Latest tag: $latest_tag"
echo "LATEST_TAG=$latest_tag" >> "$GITHUB_ENV"
- name: 🔢 Calculate new version
id: bump_version
run: |
latest_version=${LATEST_TAG#v}
IFS='.' read -r major minor patch <<< "$latest_version"
new_version="v$major.$minor.$((patch + 1))"
echo "NEW_VERSION=$new_version" >> "$GITHUB_ENV"
echo "New version will be: $new_version"
- name: ✅ Verify version uniqueness
id: check_tag
run: |
if git tag -l | grep -q "^${{ env.NEW_VERSION }}$"; then
echo "Warning: Tag ${{ env.NEW_VERSION }} already exists"
# Increment patch version again if tag exists
latest_version=${NEW_VERSION#v}
IFS='.' read -r major minor patch <<< "$latest_version"
new_version="v$major.$minor.$((patch + 1))"
echo "Using incremented version: $new_version"
echo "NEW_VERSION=$new_version" >> "$GITHUB_ENV"
fi
- name: 📤 Export version for other jobs
id: set_outputs
run: |
echo "new_version=${{ env.NEW_VERSION }}" >> "$GITHUB_OUTPUT"
- name: 🚀 Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
name: Release ${{ env.NEW_VERSION }}
body: |
Automated release for changes in main branch
Changes in this release:
${{ github.event.head_commit.message }}
draft: false
prerelease: false
publish-docker:
name: 🐳 Publish Docker Image
needs: prepare-release
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🏗️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🔑 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🚢 Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
laffin/cloudproxy:latest
laffin/cloudproxy:${{ needs.prepare-release.outputs.new_version }}
publish-pypi:
name: 📦 Publish PyPI Package
needs: prepare-release
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: 📝 Update version in pyproject.toml
run: |
# Strip the 'v' prefix from the version
VERSION=${{ needs.prepare-release.outputs.new_version }}
VERSION=${VERSION#v}
# Use sed to update the version in pyproject.toml to match the release
sed -i "s/version = \"[0-9]*\.[0-9]*\.[0-9]*\"/version = \"$VERSION\"/" pyproject.toml
cat pyproject.toml | grep version
- name: 📚 Install PyPI publishing dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: 📤 Build and publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine check dist/*
twine upload dist/*