From 9de0a6e320f40e2555909e6631068f23ad3769fa Mon Sep 17 00:00:00 2001 From: MountainGod2 Date: Fri, 27 Sep 2024 18:05:32 -0600 Subject: [PATCH] chore: update ci-cd.yml to use uv as the package manager and cache uv dependencies --- .github/workflows/ci-cd.yml | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 415fd4c1..2b746d9f 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -7,53 +7,56 @@ on: branches: [ main ] jobs: + ci: runs-on: ubuntu-latest + env: + # Configure a constant location for the uv cache + UV_CACHE_DIR: /tmp/.uv-cache + steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v5 + - name: Install uv + uses: astral-sh/setup-uv@v3.1.3 with: - python-version: "3.12" + enable-cache: true + cache-dependency-glob: "uv.lock" - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: false - virtualenvs-in-project: true + - name: Set up Python + id: setup-python + run: uv python install - - name: Load cached venv - id: cached-poetry-dependencies + - name: Restore uv cache uses: actions/cache@v4 with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + path: /tmp/.uv-cache + key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} + restore-keys: | + uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} + uv-${{ runner.os }} - - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root - - - name: Install library - run: poetry install --no-interaction + - name: Install dependencies and project + if: steps.setup-python.outputs.cache-hit != 'true' + run: uv sync - name: Format with ruff - run: poetry run ruff format ./ + run: uv run ruff format ./ - name: Lint with ruff and fix issues - run: poetry run ruff check --fix ./ + run: uv run ruff check --fix ./ - name: Type check with mypy - run: poetry run mypy ./ + run: uv run mypy ./ - name: Test with pytest env: CB_USERNAME: ${{ secrets.CB_USERNAME }} CB_TOKEN: ${{ secrets.CB_TOKEN }} - run: poetry run pytest --cov-report term --cov-report xml:coverage.xml --cov=chaturbate_poller + run: uv run pytest - name: Scan with SonarCloud uses: SonarSource/sonarcloud-github-action@v3.0.0 @@ -68,7 +71,7 @@ jobs: fail_ci_if_error: true - name: Build documentation - run: poetry run make clean html --directory docs/ + run: uv run make clean html --directory docs/ - name: Upload documentation to GitHub Pages uses: peaceiris/actions-gh-pages@v4 @@ -76,6 +79,8 @@ jobs: personal_token: ${{ secrets.PERSONAL_TOKEN }} publish_dir: docs/_build/html + - name: Minimize uv cache + run: uv cache prune --ci cd: permissions: id-token: write @@ -148,6 +153,7 @@ jobs: type=sha type=raw,value=latest,enable={{is_default_branch}} + - name: Checkout repository uses: actions/checkout@v4 with: @@ -173,7 +179,8 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: | ${{ steps.meta.outputs.tags }} - ${{ steps.release.outputs.version }} + # Add version tag + ${{ steps.meta.outputs.tags }}-v${{ steps.meta.outputs.version }} labels: ${{ steps.meta.outputs.labels }}