diff --git a/.github/containers/nox-cross-arch/README.md b/.github/containers/nox-cross-arch/README.md new file mode 100644 index 000000000..9cc615e85 --- /dev/null +++ b/.github/containers/nox-cross-arch/README.md @@ -0,0 +1,21 @@ +# Cross-Arch Testing Containers + +This directory containers dockerfiles that can be used in the CI to test the +python package in non-native machine architectures, e.g., `aarch64`. + +The dockerfiles here follow a naming scheme so that they can be easily used in +build matrices in the CI, in `nox-cross-arch` job. The naming scheme is: + +``` +--python-.Dockerfile +``` + +E.g., + +``` +arm64-ubuntu-20.04-python-3.11.Dockerfile +``` + +If a dockerfile for your desired target architecture, OS, and python version +does not exist here, please add one before proceeding to add your options to the +test matrix. diff --git a/.github/containers/nox-cross-arch/arm64-ubuntu-20.04-python-3.11.Dockerfile b/.github/containers/nox-cross-arch/arm64-ubuntu-20.04-python-3.11.Dockerfile new file mode 100644 index 000000000..b0c8fe55d --- /dev/null +++ b/.github/containers/nox-cross-arch/arm64-ubuntu-20.04-python-3.11.Dockerfile @@ -0,0 +1,28 @@ +FROM docker.io/library/ubuntu:20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +# Install Python 3.11 and curl to install pip later +RUN apt-get update -y && \ + apt-get install --no-install-recommends -y \ + software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ + apt-get install --no-install-recommends -y \ + ca-certificates \ + curl \ + git \ + python3.11 \ + python3.11-distutils && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install pip +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 + +RUN update-alternatives --install \ + /usr/local/bin/python python /usr/bin/python3.11 1 && \ + python -m pip install --upgrade --no-cache-dir pip + +COPY entrypoint.bash /usr/bin/entrypoint.bash + +ENTRYPOINT ["/usr/bin/entrypoint.bash"] diff --git a/.github/containers/nox-cross-arch/entrypoint.bash b/.github/containers/nox-cross-arch/entrypoint.bash new file mode 100755 index 000000000..7caa46013 --- /dev/null +++ b/.github/containers/nox-cross-arch/entrypoint.bash @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "System details:" $(uname -a) +echo "Machine:" $(uname -m) + +pip install -e .[dev-noxfile] + +exec "$@" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 335c54280..e29997b7f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -79,6 +79,86 @@ jobs: run: nox -R -e "$NOX_SESSION" timeout-minutes: 10 + nox-cross-arch: + name: Cross-arch tests with nox + if: github.event_name == 'merge_group' + strategy: + fail-fast: false + # Before adding new items to this matrix, make sure that a dockerfile + # exists for the combination of items in the matrix. + # Refer to .github/containers/nox-cross-arch/README.md to learn how to + # add and name new dockerfiles. + matrix: + arch: + - arm64 + os: + - ubuntu-20.04 + python: + - "3.11" + nox-session: + - "pytest_min" + runs-on: ${{ matrix.os }} + + steps: + - name: Fetch sources + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: linux/${{ matrix.arch }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # This is a workaround to prevent the cache from growing indefinitely. + # https://docs.docker.com/build/ci/github-actions/cache/#local-cache + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Cache container layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-nox-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }} + + - name: Build image + uses: docker/build-push-action@v4 + with: + context: .github/containers/nox-cross-arch + file: .github/containers/nox-cross-arch/${{ matrix.arch }}-${{ matrix.os }}-python-${{ matrix.python }}.Dockerfile + platforms: linux/${{ matrix.arch }} + tags: localhost/nox-cross-arch:latest + push: false + load: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + # Refer to the workaround mentioned above + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + # Cache nox downloads + - name: Cache nox downloads + uses: actions/cache@v3 + with: + path: | + .nox/${{ matrix.nox-session }} + key: nox-${{ matrix.nox-session }}-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Run nox + run: | + docker run \ + --rm \ + -v $(pwd):/${{ github.workspace }} \ + -w ${{ github.workspace }} \ + --net=host \ + --platform linux/${{ matrix.arch }} \ + localhost/nox-cross-arch:latest \ + nox -R -e ${{ matrix.nox-session }} + timeout-minutes: 30 + build: name: Build distribution packages runs-on: ubuntu-20.04 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cfafe7258..adfccb54c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -115,6 +115,10 @@ That said, if you want to test the actual website in **your fork**, you can always use `mike deploy --push --remote your-fork-remote`, and then access the GitHub pages produced for your fork. +## Cross-Arch Testing + +This project has built-in support for testing across multiple architectures. Currently, our CI conducts tests on `aarch64` machines using QEMU emulation. We also have the flexibility to expand this support to include additional architectures in the future. For more information, see [Cross-Arch Testing](.github/containers/nox-cross-arch/README.md). + ## Releasing These are the steps to create a new release: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 96417a1b8..d541a128e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -18,6 +18,7 @@ - A new class `Fuse` has been added to represent fuses. This class has a member variable `max_current` which represents the maximum current that can course through the fuse. If the current flowing through a fuse is greater than this limit, then the fuse will break the circuit. +- The CI now runs cross-arch tests on `aarch64` architectures. ## Bug Fixes diff --git a/docs/.github/containers/nox-cross-arch/README.md b/docs/.github/containers/nox-cross-arch/README.md new file mode 100644 index 000000000..f68b378be --- /dev/null +++ b/docs/.github/containers/nox-cross-arch/README.md @@ -0,0 +1 @@ +--8<-- ".github/containers/nox-cross-arch/README.md"