Bump actions/download-artifact from 6 to 8 #48
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/CD | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| inputs: | |
| test_pypi: | |
| description: 'Publish to Test PyPI instead of PyPI' | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| test: | |
| name: Test on macOS | |
| runs-on: macos-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.12', '3.13'] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python ${{ matrix.python-version }} | |
| run: uv python install ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Run linting (if configured) | |
| run: | | |
| # Add linting commands here if you add ruff or similar | |
| echo "Linting step placeholder" | |
| continue-on-error: true | |
| - name: Run tests | |
| run: uv run pytest -v | |
| - name: Run tests with coverage | |
| run: uv run pytest --cov=screenshots_cleaner --cov-report=xml --cov-report=term | |
| - name: Check coverage threshold | |
| run: | | |
| COVERAGE=$(uv run pytest --cov=screenshots_cleaner --cov-report=term | grep "TOTAL" | awk '{print $4}' | sed 's/%//') | |
| echo "Coverage: ${COVERAGE}%" | |
| if [ "${COVERAGE%.*}" -lt 90 ]; then | |
| echo "::warning::Coverage is below 90% (${COVERAGE}%)" | |
| exit 1 | |
| fi | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| file: ./coverage.xml | |
| flags: unittests | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| continue-on-error: true | |
| integration-test: | |
| name: Integration Tests | |
| runs-on: macos-latest | |
| needs: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| run: uv python install 3.12 | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Run integration tests | |
| run: uv run pytest tests/integration_test.py -v | |
| - name: Test CLI commands | |
| run: | | |
| # Create test directory with dummy screenshots | |
| mkdir -p /tmp/test-screenshots | |
| touch "/tmp/test-screenshots/Screen Shot 2024-01-01.png" | |
| # Test preview command | |
| uv run screenshot-cleaner preview --path=/tmp/test-screenshots --days=1 | |
| # Test clean with dry-run | |
| uv run screenshot-cleaner clean --path=/tmp/test-screenshots --days=1 --dry-run | |
| # Cleanup | |
| rm -rf /tmp/test-screenshots | |
| build: | |
| name: Build Distribution | |
| needs: [test, integration-test] | |
| runs-on: ubuntu-latest | |
| # Only build on tags or manual workflow dispatch | |
| if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| run: uv python install 3.12 | |
| - name: Build package | |
| run: uv build | |
| - name: Store distribution packages | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| publish-to-pypi: | |
| name: Publish to PyPI | |
| needs: build | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/screenshots-cleaner | |
| permissions: | |
| id-token: write # IMPORTANT: mandatory for trusted publishing | |
| steps: | |
| - name: Download distributions | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| publish-to-test-pypi: | |
| name: Publish to Test PyPI | |
| needs: build | |
| if: github.event_name == 'workflow_dispatch' && inputs.test_pypi | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: test-pypi | |
| url: https://test.pypi.org/p/screenshot-cleaner | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download distributions | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish to Test PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| github-release: | |
| name: Create GitHub Release | |
| needs: publish-to-pypi | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Download distributions | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Extract version from tag | |
| id: get_version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| - name: Extract changelog for version | |
| id: changelog | |
| run: | | |
| VERSION=${{ steps.get_version.outputs.VERSION }} | |
| # Extract the section for this version from CHANGELOG.md | |
| CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d') | |
| if [ -z "$CHANGELOG" ]; then | |
| CHANGELOG="Release $VERSION" | |
| fi | |
| echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| body: ${{ steps.changelog.outputs.CHANGELOG }} | |
| files: dist/* | |
| draft: false | |
| prerelease: false |