Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uv in GitHub Actions #89

Open
philgyford opened this issue Jan 9, 2025 · 1 comment
Open

Use uv in GitHub Actions #89

philgyford opened this issue Jan 9, 2025 · 1 comment
Assignees

Comments

@philgyford
Copy link
Owner

They're working OK with pip now, but would be nice to change over.

Use the setup-uv action.

See adamchainz's repos for examples, e.g. https://github.com/adamchainz/django-upgrade/blob/main/.github/workflows/main.yml

@philgyford philgyford self-assigned this Jan 9, 2025
philgyford added a commit that referenced this issue Jan 15, 2025
philgyford added a commit that referenced this issue Jan 15, 2025
Got this for all runs:

    Run uv pip install --system ruff tox tox-gh-actions tox-uv
    error: No system Python installation found for Python 3.12

For #89
philgyford added a commit that referenced this issue Jan 16, 2025
See if it solves the "Error: Process completed with exit code 255." problem

For #89
philgyford added a commit that referenced this issue Jan 16, 2025
For some reason GitHub Actions started complaining about invalid
toml in `pyproject.toml`

    Error: Inline lists must be a single type, not a mix of string and inline-table at row 173, col 57, pos 4638:

For #89
philgyford added a commit that referenced this issue Jan 16, 2025
philgyford added a commit that referenced this issue Jan 16, 2025
philgyford added a commit that referenced this issue Jan 16, 2025
philgyford added a commit that referenced this issue Jan 16, 2025
Seems like envs that are supposed to be using, say, Django 4.2.0
are actually using django main instead? See if this stops the confusion

For #89
philgyford added a commit that referenced this issue Jan 16, 2025
- Use `actions/setup-python@v5` to install python, not do it with uv
- Try and get uv caching working

For #89
philgyford added a commit that referenced this issue Jan 16, 2025
philgyford added a commit that referenced this issue Jan 16, 2025
philgyford added a commit that referenced this issue Jan 16, 2025
@philgyford
Copy link
Owner Author

As you can see this was a struggle.

The issue seemed to be that if one of a python group failed, they were all marked as failed.

So, python311-djangomain would fail (because on djangomain, format_html() requires args or kwargs, which my code currently isn't using.

But it would mark not only python311-djangomain as failing, but also python311-django42 and python311-django51 as failing too.

Ran out of random things to try. This is where we got to:

name: Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

env:
  FORCE_COLOR: 1

jobs:
  test:
    name: "Python ${{ matrix.python-version }}, Django ${{ matrix.django-version}}"
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
        django-version: ["4.2", "5.1", "main"]
        exclude:
          - python-version: "3.13"
            django-version: "4.2"
          - python-version: "3.9"
            django-version: "5.1"
          - python-version: "3.9"
            django-version: "main"

    steps:
      - name: Git clone
        uses: actions/checkout@v4

      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install uv
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: False
          # cache-dependency-glob: "pyproject.toml"
          # cache-suffix: ${{ matrix.python-version }}
          # cache-suffix: ${{ matrix.python-version }}-${{ matrix.django-version}}

      - name: Sync uv
        run: uv sync --dev

      - name: Test with Tox
        run: uv run --with tox --with tox-uv --with tox-gh-actions tox --parallel auto
        env:
          DJANGO: ${{ matrix.django-version }}

      - name: Upload Coverage to Codecov
        uses: codecov/codecov-action@v5
        with:
          flags: ${{ matrix.python-version }}
          name: Python ${{ matrix.python-version }}
          token: ${{ secrets.CODECOV_TOKEN }}

  ruff:
    name: Run ruff
    runs-on: ubuntu-latest

    steps:
      - name: Git clone
        uses: actions/checkout@v4

      - name: Install uv and set Python version
        uses: astral-sh/setup-uv@v5
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: uv pip install ruff tox tox-gh-actions tox-uv

      - name: Run ruff
        run: tox -e ruff

  slack:
    # https://github.com/8398a7/action-slack/issues/72#issuecomment-649910353
    name: Slack notification
    runs-on: ubuntu-latest
    needs: [test, ruff]

    # this is required, otherwise it gets skipped if any needed jobs fail.
    # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds
    if: always() # Pick up events even if the job fails or is cancelled.

    steps:
      - uses: technote-space/workflow-conclusion-action@v3

      - name: Send Slack notification
        uses: 8398a7/action-slack@v3
        with:
          status: ${{ job.status }}
          # fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message)
          fields: repo,message,commit,author,action
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.ACTIONS_CI_SLACK_HOOK }}

philgyford added a commit that referenced this issue Jan 16, 2025
Giving up on uv for GA at the moment.

For #89
philgyford added a commit that referenced this issue Jan 17, 2025
Can't get the tox config working correctly with GitHub Actions.

It seems to run tests across each Django version in turn, for
eacn environment. And if the tests fail for one of the Django
versions, it marks the entire environment as having failed.

e.g,

py311-django42 will run tess using Python 3.11 and Django 4.2,
Django 5.1 and Django main. The latter currently fails, so the
environment py311-django42 will appear as failed, even though
the tests pass with Python 3.11 and Django 4.2.

I created a minimal test repo to try and solve this but had to
give up https://github.com/philgyford/github-actions-tryout

For #89
philgyford added a commit that referenced this issue Jan 17, 2025
philgyford added a commit that referenced this issue Jan 17, 2025
Everything was failing for no apparent reason

For #89
philgyford added a commit that referenced this issue Jan 17, 2025
Everything's still failing for no clear reason

For #89
philgyford added a commit that referenced this issue Jan 17, 2025
Didn't make everything magically work

For #89
philgyford added a commit that referenced this issue Jan 17, 2025
philgyford added a commit that referenced this issue Jan 17, 2025
philgyford added a commit that referenced this issue Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant