From 92a355fee6bda8d60c816e623c14c83d9383f3c5 Mon Sep 17 00:00:00 2001 From: Tom Arne Pedersen Date: Wed, 8 Jan 2025 11:03:58 +0100 Subject: [PATCH] Updating workflows --- .../_build_and_publish_documentation.yml | 27 +++--- .github/workflows/_build_package.yml | 49 +++------- .github/workflows/_code_quality.yml | 97 ++++++++++++------- .github/workflows/_merge_into_release.yml | 8 +- .github/workflows/_requirements_files.yml | 34 ------- .github/workflows/_test.yml | 24 ++--- .github/workflows/_test_future.yml | 28 +++--- .github/workflows/nightly_build.yml | 6 -- .github/workflows/publish_release.yml | 40 ++++---- .github/workflows/pull_request_to_main.yml | 4 - .github/workflows/push.yml | 4 - .github/workflows/push_to_main.yml | 7 +- .github/workflows/push_to_release.yml | 3 - 13 files changed, 139 insertions(+), 192 deletions(-) delete mode 100644 .github/workflows/_requirements_files.yml diff --git a/.github/workflows/_build_and_publish_documentation.yml b/.github/workflows/_build_and_publish_documentation.yml index d4ba53f..2fed60c 100644 --- a/.github/workflows/_build_and_publish_documentation.yml +++ b/.github/workflows/_build_and_publish_documentation.yml @@ -15,19 +15,18 @@ jobs: - name: Checkout active branch uses: actions/checkout@v4 with: - fetch-depth: 1 lfs: true - - name: Install Python - uses: actions/setup-python@v5 + - name: Install uv + uses: astral-sh/setup-uv@v2 with: - python-version: '3.11' - cache: 'pip' # cache pip dependencies - - uses: actions/download-artifact@v4 + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: Set up Python + uses: actions/setup-python@v5 with: - name: requirements-files - - name: Install dependencies - run: | - pip install -r requirements-docs.txt + python-version-file: "pyproject.toml" + - name: Install the project + run: uv sync --upgrade - name: Print debugging information run: | echo "github.ref:" ${{github.ref}} @@ -39,17 +38,15 @@ jobs: git branch git branch -a git remote -v - python -V - pip list --not-required - pip list + uv run python -V + uv pip list # Build documentation - uses: sphinx-doc/github-problem-matcher@master - name: Build documentation run: | cd docs - sphinx-apidoc -f -e -M -o . ../src/trafficgen - make html + uv run make html - name: Clone and cleanup gh-pages branch run: | diff --git a/.github/workflows/_build_package.yml b/.github/workflows/_build_package.yml index f6fe883..362d3aa 100644 --- a/.github/workflows/_build_package.yml +++ b/.github/workflows/_build_package.yml @@ -9,46 +9,21 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 1 lfs: true + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" - uses: actions/setup-python@v5 with: - python-version: '3.11' - cache: 'pip' # cache pip dependencies - - name: Install build and twine - run: pip install build twine - - name: Run build - run: python -m build + python-version-file: "pyproject.toml" + - name: Build source distribution and wheel + run: uv build - name: Run twine check - run: twine check --strict dist/* + run: uvx twine check --strict dist/* - uses: actions/upload-artifact@v4 with: - path: ./dist/*.tar.gz - - # build_wheels: - # name: Build wheels for ${{ matrix.platform }} - # needs: - # - black - # - ruff - # - pyright - # - test - # runs-on: ${{ matrix.platform }} - # strategy: - # matrix: - # platform: [ubuntu-latest, macos-latest, windows-latest] - # steps: - # - uses: actions/checkout@v4 - # with: - # fetch-depth: 1 - # lfs: true - # - uses: actions/setup-python@v5 - # with: - # python-version: '3.11' - # cache: 'pip' # cache pip dependencies - # - name: Install cibuildwheel - # run: python -m pip install cibuildwheel==2.16 - # - name: Build wheels - # run: python -m cibuildwheel --output-dir wheels - # - uses: actions/upload-artifact@v4 - # with: - # path: ./wheels/*.whl + path: | + dist/*.tar.gz + dist/*.whl diff --git a/.github/workflows/_code_quality.yml b/.github/workflows/_code_quality.yml index 60f44f0..d3e65a7 100644 --- a/.github/workflows/_code_quality.yml +++ b/.github/workflows/_code_quality.yml @@ -3,55 +3,78 @@ name: Code Quality on: workflow_call jobs: - black: - name: black + ruff_format: runs-on: ubuntu-latest + name: ruff format steps: - uses: actions/checkout@v4 - - uses: psf/black@stable + - name: Install uv + uses: astral-sh/setup-uv@v2 with: - options: '--check --diff' - src: '.' - jupyter: true - version: '==23.12' + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: Install the project + run: uv sync --upgrade + - name: Run ruff format + run: uv run ruff format --diff - ruff: + ruff_check: runs-on: ubuntu-latest - name: ruff + name: ruff check steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - cache: 'pip' # cache pip dependencies - - uses: actions/download-artifact@v4 - with: - name: requirements-files - - name: Install dependencies - run: | - pip install -r requirements.txt - - name: Install ruff - run: pip install ruff==0.1.8 - - name: Run ruff - run: ruff . + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: Install the project + run: uv sync --upgrade + - name: Run ruff check + run: uv run ruff check --diff pyright: runs-on: ubuntu-latest name: pyright steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - cache: 'pip' # cache pip dependencies - - uses: actions/download-artifact@v4 - with: - name: requirements-files - - name: Install dependencies - run: | - pip install -r requirements.txt - pip install pytest - - name: Install pyright - run: pip install pyright==1.1.338 + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: Install the project + run: uv sync --upgrade - name: Run pyright - run: pyright . + run: uv run pyright + + mypy: + runs-on: ubuntu-latest + name: mypy + steps: + - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + - name: Install the project + run: uv sync --upgrade + - name: Run mypy + run: uv run mypy diff --git a/.github/workflows/_merge_into_release.yml b/.github/workflows/_merge_into_release.yml index cec3964..3396509 100644 --- a/.github/workflows/_merge_into_release.yml +++ b/.github/workflows/_merge_into_release.yml @@ -22,4 +22,10 @@ jobs: with: type: now target_branch: release - github_token: ${{ secrets.RELEASE_TOKEN }} + # @TODO: A dedicated RELEASE_TOKEN should be created in the repo settings + # and used for this task when in production. + # It is set here to the default GITHUB_TOKEN only + # for demonstration purposes, enabling the workflow in the repo template + # to run without additional configuration. + # github_token: ${{ secrets.RELEASE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/_requirements_files.yml b/.github/workflows/_requirements_files.yml deleted file mode 100644 index 7e3b34d..0000000 --- a/.github/workflows/_requirements_files.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Requirements Files - -on: workflow_call - -jobs: - requirements: - name: Create requirements files from poetry - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.11' - cache: 'pip' # cache pip dependencies - - name: Create requirements files from poetry.lock file - run: | - pip install poetry - pip install poetry-plugin-export - poetry lock - poetry export -o requirements.txt --without-hashes --format requirements.txt - poetry export -o requirements-dev.txt --without-hashes --format requirements.txt --with dev - poetry export -o requirements-docs.txt --without-hashes --format requirements.txt --with docs - - name: Upload requirements files as artifact - uses: actions/upload-artifact@v4 - with: - name: requirements-files - path: | - poetry.lock - requirements.txt - requirements-dev.txt - requirements-docs.txt - - name: Delete poetry.lock file - run: | - rm -f poetry.lock diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 504c4a7..15ce426 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -4,32 +4,32 @@ on: workflow_call jobs: test: - name: Test on ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}} + name: Test on ${{matrix.python.version}}-${{matrix.platform.runner}} runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: ubuntu-latest - toxenv: linux - runner: windows-latest - toxenv: windows + # - runner: macos-latest python: - - version: '3.9' - toxenv: 'py39' - version: '3.10' - toxenv: 'py310' - version: '3.11' - toxenv: 'py311' - version: '3.12' - toxenv: 'py312' steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" - name: Install Python ${{ matrix.python.version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python.version }} - cache: 'pip' # cache pip dependencies - - name: Install tox - run: python -m pip install tox + - name: Install the project + run: uv sync -p ${{ matrix.python.version }} -U --no-dev - name: Run pytest - run: tox -e ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}} + run: > + uv run --with pytest --with pytest-cov + pytest --cov diff --git a/.github/workflows/_test_future.yml b/.github/workflows/_test_future.yml index aed952a..71de688 100644 --- a/.github/workflows/_test_future.yml +++ b/.github/workflows/_test_future.yml @@ -1,31 +1,35 @@ -name: Unit Tests (py312) -# Test also with Python 3.12 (experimental; workflow will not fail on error.) +name: Unit Tests (py313) +# Test also with Python 3.13 (experimental; workflow will not fail on error.) on: workflow_call jobs: - test312: - name: Test on ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}} (experimental) + test313: + name: Test on ${{matrix.python.version}}-${{matrix.platform.runner}} (experimental) continue-on-error: true runs-on: ${{ matrix.platform.runner }} strategy: matrix: platform: - runner: ubuntu-latest - toxenv: linux - runner: windows-latest - toxenv: windows python: - - version: '3.13.0a2' - toxenv: 'py313' + - version: '3.13.0-alpha - 3.13.0' + uvpy: '3.13' steps: - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" - name: Install Python ${{ matrix.python.version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python.version }} - cache: 'pip' # cache pip dependencies - - name: Install tox - run: python -m pip install tox + - name: Install the project + run: uv sync -p ${{ matrix.python.uvpy }} -U --no-dev - name: Run pytest - run: tox -e ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}} + run: > + uv run --with pytest --with pytest-cov + pytest --cov diff --git a/.github/workflows/nightly_build.yml b/.github/workflows/nightly_build.yml index d5b14c7..28f6868 100644 --- a/.github/workflows/nightly_build.yml +++ b/.github/workflows/nightly_build.yml @@ -6,20 +6,14 @@ on: - cron: '30 5 * * *' jobs: - requirements_files: - uses: ./.github/workflows/_requirements_files.yml code_quality: - needs: requirements_files uses: ./.github/workflows/_code_quality.yml test: - needs: requirements_files uses: ./.github/workflows/_test.yml test_future: - needs: requirements_files uses: ./.github/workflows/_test_future.yml build_package: needs: - - code_quality - test uses: ./.github/workflows/_build_package.yml build_and_publish_documentation: diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 2275117..faff098 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -7,28 +7,24 @@ on: - v* jobs: - # requirements_files: - # uses: ./.github/workflows/_requirements_files.yml - # build_package: - # needs: - # - requirements_files - # uses: ./.github/workflows/_build_package.yml - # publish_package: - # name: Publish package - # needs: - # - build_package - # runs-on: ubuntu-latest - # environment: release - # permissions: - # id-token: write - # steps: - # - uses: actions/download-artifact@v4 - # with: - # name: artifact - # path: dist - # - uses: pypa/gh-action-pypi-publish@release/v1 - # # with: # Uncomment this line to publish to testpypi - # # repository-url: https://test.pypi.org/legacy/ # Uncomment this line to publish to testpypi + build_package: + uses: ./.github/workflows/_build_package.yml + publish_package: + name: Publish package + needs: + - build_package + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: artifact + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1 + # with: # Uncomment this line to publish to testpypi + # repository-url: https://test.pypi.org/legacy/ # Uncomment this line to publish to testpypi merge_into_release: uses: ./.github/workflows/_merge_into_release.yml secrets: diff --git a/.github/workflows/pull_request_to_main.yml b/.github/workflows/pull_request_to_main.yml index 97d2742..2bff438 100644 --- a/.github/workflows/pull_request_to_main.yml +++ b/.github/workflows/pull_request_to_main.yml @@ -17,13 +17,9 @@ concurrency: cancel-in-progress: true jobs: - requirements_files: - uses: ./.github/workflows/_requirements_files.yml code_quality: - needs: requirements_files uses: ./.github/workflows/_code_quality.yml test: - needs: requirements_files uses: ./.github/workflows/_test.yml # build_package: # needs: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 5cc0fbf..08debf2 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -12,11 +12,7 @@ concurrency: cancel-in-progress: true jobs: - requirements_files: - uses: ./.github/workflows/_requirements_files.yml code_quality: - needs: requirements_files uses: ./.github/workflows/_code_quality.yml test: - needs: requirements_files uses: ./.github/workflows/_test.yml diff --git a/.github/workflows/push_to_main.yml b/.github/workflows/push_to_main.yml index 1e5257e..735f70b 100644 --- a/.github/workflows/push_to_main.yml +++ b/.github/workflows/push_to_main.yml @@ -11,13 +11,9 @@ concurrency: cancel-in-progress: true jobs: - requirements_files: - uses: ./.github/workflows/_requirements_files.yml code_quality: - needs: requirements_files uses: ./.github/workflows/_code_quality.yml test: - needs: requirements_files uses: ./.github/workflows/_test.yml build_package: needs: @@ -25,5 +21,6 @@ jobs: - test uses: ./.github/workflows/_build_package.yml build_and_publish_documentation: - needs: build_package + needs: + - build_package uses: ./.github/workflows/_build_and_publish_documentation.yml diff --git a/.github/workflows/push_to_release.yml b/.github/workflows/push_to_release.yml index 083caaf..8880838 100644 --- a/.github/workflows/push_to_release.yml +++ b/.github/workflows/push_to_release.yml @@ -11,8 +11,5 @@ concurrency: cancel-in-progress: true jobs: - requirements_files: - uses: ./.github/workflows/_requirements_files.yml build_and_publish_documentation: - needs: requirements_files uses: ./.github/workflows/_build_and_publish_documentation.yml