Improve CI/CD: Add PR testing, auto-releases, and develop support (#2) #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| tags: | |
| - 'v*' # Trigger on version tags (v1.0.0, v1.2.3, etc.) | |
| pull_request: | |
| branches: [ main, develop ] | |
| jobs: | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies and package | |
| run: | | |
| cd kernagent | |
| uv sync --all-groups | |
| - name: Run pytest | |
| run: | | |
| cd kernagent | |
| uv run pytest ../tests -v | |
| lint: | |
| name: Code Quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| cd kernagent | |
| uv sync --all-groups | |
| - name: Check Python syntax | |
| run: | | |
| cd kernagent | |
| uv run python -m py_compile *.py */**.py | |
| # Build Docker image for PRs and develop branch (test only, no push) | |
| build-test: | |
| name: Build Docker Image (Test) | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' || github.ref == 'refs/heads/develop' | |
| needs: [test, lint] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image for testing | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: false | |
| tags: kernagent:test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| load: true | |
| - name: Run pytest inside Docker container | |
| run: | | |
| docker run --rm \ | |
| -v $(pwd)/tests:/workspace/tests:ro \ | |
| -v $(pwd)/kernagent:/workspace/project/kernagent:ro \ | |
| --entrypoint bash \ | |
| kernagent:test \ | |
| -c "cd /workspace/project && PYTHONPATH=/workspace/project/kernagent:/workspace/project uv run pytest /workspace/tests -v" | |
| - name: Test CLI help command | |
| run: | | |
| docker run --rm kernagent:test --help | |
| # Build and push Docker images for releases (tags only) | |
| build-release: | |
| name: Build & Push Release | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: [test, lint] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest | |
| - name: Build and push multi-platform release | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| # Extract version from tag | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Generate release notes from commits since last tag | |
| PREV_TAG=$(git describe --abbrev=0 --tags ${GITHUB_REF}^ 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "## Changes since $PREV_TAG" > release_notes.md | |
| git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" >> release_notes.md | |
| else | |
| echo "## Initial Release" > release_notes.md | |
| echo "First release of kernagent" >> release_notes.md | |
| fi | |
| # Add installation instructions | |
| cat >> release_notes.md << 'EOF' | |
| ## Installation | |
| **Quick install (Linux/macOS/WSL2):** | |
| ```bash | |
| bash <(curl -fsSL https://raw.githubusercontent.com/Karib0u/kernagent/$VERSION/install.sh) | |
| ``` | |
| **Docker:** | |
| ```bash | |
| docker pull ghcr.io/karib0u/kernagent:$VERSION | |
| ``` | |
| **See the [README](https://github.com/Karib0u/kernagent#readme) for full documentation.** | |
| EOF | |
| # Replace $VERSION placeholder | |
| sed -i "s/\$VERSION/$VERSION/g" release_notes.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Build and push development images (develop branch only) | |
| build-develop: | |
| name: Build & Push Develop | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | |
| needs: [test, lint] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for develop | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=raw,value=develop | |
| type=sha,prefix=dev- | |
| - name: Build and push develop image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false |