diff --git a/.github/actions/freebsd-vm/action.yml b/.github/actions/freebsd-vm/action.yml new file mode 100644 index 00000000..dac0a89f --- /dev/null +++ b/.github/actions/freebsd-vm/action.yml @@ -0,0 +1,48 @@ +name: 'FreeBSD VM' +description: 'Install FreeBSD VM with python3, PDM and tox pre-installed' +inputs: + python-version: + description: "Version range or exact version of Python to use, using SemVer's version range syntax." + required: true + run: + description: 'The CI command to run' + required: true + release: + description: 'The release version of FreeBSD vm' + required: false + envs: + description: 'The envs to pass into FreeBSD vm' + required: false + sync: + description: 'How to synchronize the source code to/from the VM, Values can be: rsync(default), and sshfs' + required: false + +runs: + using: 'composite' + steps: + - name: Load PDM configuration from pdm.conf + uses: cardinalby/export-env-action@v2 + with: + envFile: .github/actions/pdm.conf + - name: Load Python configuration + uses: cardinalby/export-env-action@v2 + with: + envFile: ${{ github.action_path }}/python/${{ inputs.python-version }}.conf + - name: Run on VM + uses: vmactions/freebsd-vm@v1 + with: + release: ${{ inputs.release }} + usesh: true + envs: ${{ inputs.envs }} + sync: ${{ inputs.sync }} + prepare: | + set -e + pkg install -y curl git ${{ env.FREEBSD_PORTS_FOR_PYTHON }} + curl -sSL https://pdm-project.org/install-pdm.py | ${{ env.FREEBSD_PYTHON_BIN }} - --version=${{ env.PDM_VERSION }} --path=/usr/local + pdm config check_update false + pdm config install.cache true + run: | + set -e + pdm install --frozen-lockfile --global --project=. --no-self --no-default --dev --group=tox + tox --version + ${{ inputs.run }} diff --git a/.github/actions/freebsd-vm/python/3.11.conf b/.github/actions/freebsd-vm/python/3.11.conf new file mode 100644 index 00000000..790822c4 --- /dev/null +++ b/.github/actions/freebsd-vm/python/3.11.conf @@ -0,0 +1,3 @@ +# py311-sqlite3 is needed for coverage.py +FREEBSD_PORTS_FOR_PYTHON=python311 py311-sqlite3 +FREEBSD_PYTHON_BIN=python3.11 diff --git a/.github/actions/pdm.conf b/.github/actions/pdm.conf new file mode 100644 index 00000000..fe87bc2e --- /dev/null +++ b/.github/actions/pdm.conf @@ -0,0 +1,7 @@ +# This file is loaded in runner environment by: +# - setup-tox +# - freebsd-vm + +PDM_VERSION=2.20.1 +PDM_CHECK_UPDATE=False +WORKFLOW_CACHE_KEY_FILE=.github/.workflow.cache.key diff --git a/.github/actions/setup-tox/action.yml b/.github/actions/setup-tox/action.yml index 0efeb148..cd4a9a1b 100644 --- a/.github/actions/setup-tox/action.yml +++ b/.github/actions/setup-tox/action.yml @@ -9,12 +9,10 @@ inputs: runs: using: 'composite' steps: - - name: Disable PDM update check - run: echo "PDM_CHECK_UPDATE=False" >> $GITHUB_ENV - shell: bash - - name: Get workflow cache key filepath - run: echo "WORKFLOW_CACHE_KEY_FILE=.github/.workflow.cache.key" >> $GITHUB_ENV - shell: bash + - name: Load PDM configuration from pdm.conf + uses: cardinalby/export-env-action@v2 + with: + envFile: .github/actions/pdm.conf - name: Create cache key from workflow run: | echo "Runner=${{ runner.os }}-${{ runner.arch }}; Workflow=${{ github.workflow }}/${{ github.job }}" > $WORKFLOW_CACHE_KEY_FILE @@ -31,7 +29,8 @@ runs: shell: bash # Use a pinned commit to use the new feature added (and which is not currently added to v4) # c.f. https://github.com/pdm-project/setup-pdm/pull/60 - - uses: pdm-project/setup-pdm@2f3a9be7ac56a6e5c1ea605f8e9d0f0500363705 # v4 + - name: Install PDM + uses: pdm-project/setup-pdm@2f3a9be7ac56a6e5c1ea605f8e9d0f0500363705 # v4 id: pdm with: version: '2.20.1' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2258636c..e10c315d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -68,9 +68,10 @@ jobs: run: tox run -f mypy type-hinting-freebsd: - if: | - (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:')) - && (github.event_name != 'pull_request' || github.event.pull_request.draft != true) + # TODO: Add this when the workflow is stable. + # if: | + # (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:')) + # && (github.event_name != 'pull_request' || github.event.pull_request.draft != true) runs-on: ubuntu-24.04 name: type-hinting (freebsd-14) @@ -79,18 +80,9 @@ jobs: with: fetch-depth: 0 - name: Launch checks - uses: vmactions/freebsd-vm@v1 + uses: ./.github/actions/freebsd-vm with: release: '14.1' - usesh: true - prepare: | - set -e - pkg install -y curl git python311 py311-sqlite3 - curl -sSL https://pdm-project.org/install-pdm.py | python3.11 - --version=${{ env.PDM_VERSION }} --path=/usr/local - pdm config check_update false - pdm config install.cache true + python-version: '3.11' run: | - set -e - pdm install --frozen-lockfile --global --project=. --no-self --no-default --dev --group=tox - tox --version tox --workdir /tmp/.tox run -e mypy-full diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78b4f5ec..4fad7e13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,6 @@ concurrency: env: PYTEST_VERBOSE_FLAG: ${{ inputs.verbose && '-v' || '' }} - PDM_VERSION: '2.20.1' # Used by FreeBSD VM jobs: tests: @@ -112,9 +111,10 @@ jobs: Py-${{ matrix.python_version }} test-freebsd: - if: | - (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:')) - && (github.event_name != 'pull_request' || (github.event.pull_request.draft != true && !contains(github.event.pull_request.labels.*.name, 'pr-skip-test'))) + # TODO: Add this when the workflow is stable. + # if: | + # (github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Bump version:')) + # && (github.event_name != 'pull_request' || (github.event.pull_request.draft != true && !contains(github.event.pull_request.labels.*.name, 'pr-skip-test'))) runs-on: ubuntu-24.04 strategy: fail-fast: false @@ -122,11 +122,7 @@ jobs: # TODO: Add test with other python version # c.f. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271673 include: - # py3XX-sqlite3 is needed for coverage.py - python_version: '3.11' - freebsd_ports: >- - python311 - py311-sqlite3 tox_py: py311 name: test (freebsd-14, ${{ matrix.python_version }}) @@ -137,20 +133,11 @@ jobs: - name: Launch tests # Add 5 minutes to let the VM boot and install dependencies timeout-minutes: 25 - uses: vmactions/freebsd-vm@v1 + uses: ./.github/actions/freebsd-vm with: release: '14.1' - usesh: true - prepare: | - set -e - pkg install -y curl git ${{ matrix.freebsd_ports }} - curl -sSL https://pdm-project.org/install-pdm.py | python${{ matrix.python_version }} - --version=${{ env.PDM_VERSION }} --path=/usr/local - pdm config check_update false - pdm config install.cache true + python-version: ${{ matrix.python_version }} run: | - set -e - pdm install --frozen-lockfile --global --project=. --no-self --no-default --dev --group=tox - tox --version tox --workdir /tmp/.tox run -f ${{ matrix.tox_py }} -- ${{ env.PYTEST_VERBOSE_FLAG }} tox --workdir /tmp/.tox run -f coverage - name: Check files in workspace @@ -159,25 +146,25 @@ jobs: # Currently, it is not possible to send several files with per-file tags. # This is why the step is copy-paste twice. # Issue: https://github.com/codecov/codecov-action/issues/1522 - - name: Upload (unit tests) coverage to codecov - if: hashFiles('coverage.unit.xml') != '' # Rudimentary `file.exists()` - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - disable_search: true - files: >- - coverage.unit.xml - flags: >- - test-unit - - name: Upload (functional tests) coverage to codecov - if: hashFiles('coverage.functional.xml') != '' # Rudimentary `file.exists()` - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - disable_search: true - files: >- - coverage.functional.xml - flags: >- - test-functional, - OS-FreeBSD, - Py-${{ matrix.python_version }} + # - name: Upload (unit tests) coverage to codecov + # if: hashFiles('coverage.unit.xml') != '' # Rudimentary `file.exists()` + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # disable_search: true + # files: >- + # coverage.unit.xml + # flags: >- + # test-unit + # - name: Upload (functional tests) coverage to codecov + # if: hashFiles('coverage.functional.xml') != '' # Rudimentary `file.exists()` + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # disable_search: true + # files: >- + # coverage.functional.xml + # flags: >- + # test-functional, + # OS-FreeBSD, + # Py-${{ matrix.python_version }}