| # SPDX-License-Identifier: MPL-2.0 | |
| # | |
| # libpathrs: safe path resolution on Linux | |
| # Copyright (C) 2019-2025 SUSE LLC | |
| # Copyright (C) 2026 Aleksa Sarai <cyphar@cyphar.com> | |
| # | |
| # This Source Code Form is subject to the terms of the Mozilla Public | |
| # License, v. 2.0. If a copy of the MPL was not distributed with this | |
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main ] | |
| release: | |
| types: [ published ] | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| name: e2e-tests | |
| permissions: | |
| contents: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| # BATS_COMMIT must be the commit that the v$BATS_VERSION tag points to: | |
| # git ls-remote https://github.com/bats-core/bats-core "refs/tags/v$BATS_VERSION^{}" | |
| # renovate: datasource=github-tags depName=bats-core/bats-core extractVersion=^v(?<version>.+)$ | |
| BATS_VERSION: "1.14.0" | |
| BATS_COMMIT: "eb7f42f8d608ac693d7a4b67474f6714ea68cfc5" | |
| # renovate: datasource=github-releases depName=docker/buildx | |
| BUILDX_VERSION: "v0.38.0" | |
| CI_IMAGE: cyphar/libpathrs:ci-latest | |
| jobs: | |
| e2e-test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| lang: | |
| - go | |
| - rust | |
| - python | |
| run-as: | |
| - "" | |
| - "root" | |
| lang-desc: [""] | |
| include: | |
| # Test minimum python version. | |
| # TODO: Switch to python 3.10 (pathrs bindings version). | |
| # typing.Self: python >= 3.11 | |
| # match: python >= 3.10 | |
| - lang: python | |
| lang-desc: python3.11 | |
| python-version: "3.11" | |
| # Test minimum Go version. | |
| # TODO: Switch to Go 1.18 (go-pathrs bindings version). | |
| # strings.FieldsFuncSeq: go >= 1.24 | |
| # urfave/cli/v3: go >= 1.22 | |
| - lang: go | |
| lang-desc: go1.24 | |
| go-version: "1.24" | |
| # FIXME: This is horrific. | |
| name: >- | |
| run e2e-tests | |
| ${{ | |
| format('({0}{1})', | |
| matrix.lang-desc || matrix.lang, | |
| matrix.run-as && format(', {0}', matrix.run-as) || '' | |
| ) | |
| }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: install package | |
| run: |- | |
| sudo apt-get update -y | |
| sudo apt-get install -y moreutils | |
| # Build and install libpathrs.so. | |
| - name: install rust toolchain | |
| if: ${{ matrix.lang != 'rust' }} | |
| run: |- | |
| rustup toolchain install --profile minimal --no-self-update stable | |
| rustup default stable | |
| - if: ${{ matrix.lang != 'rust' }} | |
| name: build libpathrs | |
| run: make release | |
| - if: ${{ matrix.lang != 'rust' }} | |
| name: install libpathrs | |
| run: sudo ./install.sh --prefix=/usr --libdir=/usr/lib | |
| # Setup go. | |
| - if: ${{ matrix.lang == 'go' }} | |
| name: install go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | |
| with: | |
| go-version: ${{ matrix.go-version || 'stable' }} | |
| check-latest: true | |
| cache: false | |
| # Setup python. | |
| - if: ${{ matrix.lang == 'python' }} | |
| name: install pypa/build | |
| uses: $/.github/actions/python-deps | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| name: build | |
| # Install bats. | |
| - name: checkout bats-core v${{ env.BATS_VERSION }} | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| repository: bats-core/bats-core | |
| ref: ${{ env.BATS_COMMIT }} | |
| path: .tmp/bats-core | |
| persist-credentials: false | |
| - name: install bats | |
| run: |- | |
| # Make sure BATS_COMMIT actually matches the BATS_VERSION release. | |
| git -C .tmp/bats-core fetch --depth=1 origin tag "v$BATS_VERSION" | |
| tag_commit="$(git -C .tmp/bats-core rev-parse "v$BATS_VERSION^{commit}")" | |
| if [[ "$tag_commit" != "$BATS_COMMIT" ]]; then | |
| echo "::error::bats v$BATS_VERSION is commit $tag_commit, not $BATS_COMMIT" | |
| exit 1 | |
| fi | |
| sudo .tmp/bats-core/install.sh /usr/local | |
| # Run tests. | |
| - name: make -C e2e-tests test-${{ matrix.lang }} | |
| run: |- | |
| BATS="$(which bats)" | |
| export BATS | |
| make -C e2e-tests RUN_AS=${{ matrix.run-as }} test-${{ matrix.lang }} | |
| ctr-ci-image: | |
| runs-on: ubuntu-latest | |
| name: build ci docker image | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: setup docker buildx | |
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | |
| with: | |
| version: ${{ env.BUILDX_VERSION }} | |
| # Avoid GHA cache poisoning of the buildx binary. | |
| cache-binary: false | |
| - name: build and cache ci image | |
| uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 | |
| with: | |
| context: . | |
| tags: ${{ env.CI_IMAGE }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| ctr-e2e-test: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - ctr-ci-image | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| lang: | |
| - python | |
| - go | |
| - rust | |
| runtime: | |
| - docker | |
| run-as: | |
| - unpriv | |
| - CAP_SYS_ADMIN | |
| env: | |
| CONTAINER_RUNTIME: ${{ matrix.runtime }} | |
| # NOTE: For the root tests we need to disable AppArmor because it blocks | |
| # mount operations, even in child mount namespaces. | |
| CONTAINER_RUN_ARGS: >- | |
| ${{ matrix.run-as == 'CAP_SYS_ADMIN' && '--cap-add sys_admin --security-opt=apparmor=unconfined' || '' }} | |
| ${{ matrix.run-as == 'unpriv' && '--user 1000:1000' || '' }} | |
| E2E_LANG: ${{ matrix.lang }} | |
| name: >- | |
| (${{ matrix.runtime }}) | |
| run e2e-tests | |
| (${{ matrix.lang }}, ${{ matrix.run-as }}) | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| # Pull the image from the cache by triggering a "new build". | |
| - name: setup docker buildx | |
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | |
| with: | |
| version: ${{ env.BUILDX_VERSION }} | |
| # Avoid GHA cache poisoning of the buildx binary. | |
| cache-binary: false | |
| # TODO: Ideally we would be able to pull the image from the cache without | |
| # needing to trigger another build. In the worst case we could just | |
| # upload the CI image in the ctr-ci-image job and load it here. | |
| - name: build and cache ci image | |
| uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 | |
| with: | |
| context: . | |
| tags: ${{ env.CI_IMAGE }} | |
| load: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # Run the tests. | |
| - run: >- | |
| mkdir -p ./target && chmod a+rwx ./target | |
| - name: ${{ matrix.runtime }} run ${{ matrix.lang }} e2e-tests (run as ${{ matrix.run-as }}) | |
| run: |- | |
| # shellcheck disable=SC2086 # CONTAINER_RUN_ARGS needs word-splitting. | |
| "$CONTAINER_RUNTIME" run --rm $CONTAINER_RUN_ARGS \ | |
| -v "$PWD/target:/usr/src/libpathrs/target" \ | |
| "$CI_IMAGE" \ | |
| make -C e2e-tests "test-$E2E_LANG" | |
| e2e-complete: | |
| needs: | |
| - e2e-test | |
| - ctr-e2e-test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: echo "End-to-end test CI jobs completed successfully." |