Skip to content

Commit

Permalink
CI: Merged FreeBSD VM setup in a github action
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia committed Nov 11, 2024
1 parent 1a4a8fc commit c16cedc
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 62 deletions.
48 changes: 48 additions & 0 deletions .github/actions/freebsd-vm/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .github/actions/freebsd-vm/python/3.11.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# py311-sqlite3 is needed for coverage.py
FREEBSD_PORTS_FOR_PYTHON=python311 py311-sqlite3
FREEBSD_PYTHON_BIN=python3.11
7 changes: 7 additions & 0 deletions .github/actions/pdm.conf
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions .github/actions/setup-tox/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
20 changes: 6 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
69 changes: 28 additions & 41 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ concurrency:

env:
PYTEST_VERBOSE_FLAG: ${{ inputs.verbose && '-v' || '' }}
PDM_VERSION: '2.20.1' # Used by FreeBSD VM

jobs:
tests:
Expand Down Expand Up @@ -112,21 +111,18 @@ 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
matrix:
# 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 }})
Expand All @@ -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
Expand All @@ -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 }}

0 comments on commit c16cedc

Please sign in to comment.