From 70baed88f4bef0d71acfef88807a2c492de729c9 Mon Sep 17 00:00:00 2001 From: Thomas Moerkerken <1309462+moerketh@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:24:17 +0200 Subject: [PATCH] add x86 build and run unittests to backend pipeline (#1682) * add build backend for x86_64 * remove unnecessary build steps * install backend dependency * build and run backend unittest * fix cache key * buildx is required, qemu is not. * Add missing steps from Makefile * fix build_command var is unused * select more common test env * update pipeline names and docs * use variable for node version * use correct artifact name * update pipeline references * skip unittest that needs ca-cert installed * correct pipeline name * use nextest pre-built binary; add term color * fix cache permissions warning * update documentation --- .github/workflows/README.md | 21 +- .github/workflows/backend-pr.yaml | 98 -------- .github/workflows/backend.yaml | 234 ++++++++++++++++++ .../{frontend-pr.yaml => frontend.yaml} | 7 +- .github/workflows/product.yaml | 18 +- 5 files changed, 258 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/backend-pr.yaml create mode 100644 .github/workflows/backend.yaml rename .github/workflows/{frontend-pr.yaml => frontend.yaml} (91%) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 2ab5b288a..4235613eb 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -1,20 +1,25 @@ # This folder contains GitHub Actions workflows for building the project -## backend-pr -Runs: when a pull request targets the master branch and changes the libs/ and/or backend/ folders +## backend +Runs: manually (on: workflow_dispatch) or called by product-pipeline (on: workflow_call) -This workflow uses the actions docker/setup-qemu-action@v1 and docker/setup-buildx-action@v1 to prepare the environment for aarch64 cross complilation using docker buildx. -A matrix-strategy has been used for building the v8 snapshot instead of the makefile to allow parallel job execution. +This workflow uses the actions and docker/setup-buildx-action@v1 to prepare the environment for aarch64 cross complilation using docker buildx. +When execution of aarch64 containers is required the action docker/setup-qemu-action@v1 is added. +A matrix-strategy has been used to build for both x86_64 and aarch64 platforms in parallel. -## frontend-pr -Runs: when a pull request targets the master branch and changes the frontend/ folder +### Running unittests + +Unittests are run using [cargo-nextest]( https://nexte.st/). First the sources are (cross-)compiled and archived. The archive is then run on the correct platform. + +## frontend +Runs: manually (on: workflow_dispatch) or called by product-pipeline (on: workflow_call) This workflow builds the frontends. ## product -Runs: when a change to the master branch is made +Runs: when a pull request targets the master or next branch and when a change to the master or next branch is made -This workflow builds everything, re-using the backend-pr and frontend-pr workflows. +This workflow builds everything, re-using the backend and frontend workflows. The download and extraction order of artifacts is relevant to `make`, as it checks the file timestamps to decide which targets need to be executed. Result: eos.img diff --git a/.github/workflows/backend-pr.yaml b/.github/workflows/backend-pr.yaml deleted file mode 100644 index 7719641f3..000000000 --- a/.github/workflows/backend-pr.yaml +++ /dev/null @@ -1,98 +0,0 @@ -name: Backend PR - -on: - workflow_call: - workflow_dispatch: - -jobs: - libs: - name: Build libs - strategy: - matrix: - target: [amd64, arm64] - include: - - target: amd64 - snapshot_command: ./build-v8-snapshot.sh - artifact_name: js_snapshot - artifact_path: libs/js_engine/src/artifacts/JS_SNAPSHOT.bin - - target: arm64 - snapshot_command: ./build-arm-v8-snapshot.sh - artifact_name: arm_js_snapshot - artifact_path: libs/js_engine/src/artifacts/ARM_JS_SNAPSHOT.bin - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - libs/target/ - key: ${{ runner.os }}-cargo-libs-${{ matrix.target }}-${{ hashFiles('libs/Cargo.lock') }} - - - name: Build v8 snapshot - run: ${{ matrix.snapshot_command }} - working-directory: libs - - - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.artifact_name }} - path: ${{ matrix.artifact_path }} - - backend: - name: Build backend - runs-on: ubuntu-latest - needs: libs - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Download arm_js_snapshot artifact - uses: actions/download-artifact@v3 - with: - name: arm_js_snapshot - path: libs/js_engine/src/artifacts/ - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - backend/target/ - key: ${{ runner.os }}-cargo-backend-${{ hashFiles('backend/Cargo.lock') }} - - - name: Build backend - run: make backend - - - name: 'Tar files to preserve file permissions' - run: tar -cvf backend.tar ENVIRONMENT.txt GIT_HASH.txt backend/target/aarch64-unknown-linux-gnu/release/embassy* - - - uses: actions/upload-artifact@v3 - with: - name: backend - path: backend.tar diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml new file mode 100644 index 000000000..5da621d19 --- /dev/null +++ b/.github/workflows/backend.yaml @@ -0,0 +1,234 @@ +name: Backend + +on: + workflow_call: + workflow_dispatch: + +env: + RUST_VERSION: "1.62.1" + +jobs: + build_libs: + name: Build libs + strategy: + fail-fast: false + matrix: + target: [x86_64, aarch64] + include: + - target: x86_64 + snapshot_command: ./build-v8-snapshot.sh + artifact_name: js_snapshot + artifact_path: libs/js_engine/src/artifacts/JS_SNAPSHOT.bin + - target: aarch64 + snapshot_command: ./build-arm-v8-snapshot.sh + artifact_name: arm_js_snapshot + artifact_path: libs/js_engine/src/artifacts/ARM_JS_SNAPSHOT.bin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + if: ${{ matrix.target == 'aarch64' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + if: ${{ matrix.target == 'aarch64' }} + + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + override: true + if: ${{ matrix.target == 'x86_64' }} + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + libs/target/ + key: ${{ runner.os }}-cargo-libs-${{ matrix.target }}-${{ hashFiles('libs/Cargo.lock') }} + + - name: Build v8 snapshot + run: ${{ matrix.snapshot_command }} + working-directory: libs + + - uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact_name }} + path: ${{ matrix.artifact_path }} + + build_backend: + name: Build backend + strategy: + fail-fast: false + matrix: + target: [x86_64, aarch64] + include: + - target: x86_64 + snapshot_download: js_snapshot + - target: aarch64 + snapshot_download: arm_js_snapshot + runs-on: ubuntu-latest + needs: build_libs + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Download ${{ matrix.snapshot_download }} artifact + uses: actions/download-artifact@v3 + with: + name: ${{ matrix.snapshot_download }} + path: libs/js_engine/src/artifacts/ + + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + override: true + if: ${{ matrix.target == 'x86_64' }} + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + backend/target/ + key: ${{ runner.os }}-cargo-backend-${{ matrix.target }}-${{ hashFiles('backend/Cargo.lock') }} + + - name: Install dependencies + run: sudo apt-get install libavahi-client-dev + if: ${{ matrix.target == 'x86_64' }} + + - name: Check Git Hash + run: ./check-git-hash.sh + + - name: Check Environment + run: ./check-environment.sh + + - name: Build backend + run: cargo build --release --target x86_64-unknown-linux-gnu + working-directory: backend + if: ${{ matrix.target == 'x86_64' }} + + - name: Build backend + run: | + docker run --rm \ + -v "/home/runner/.cargo/registry":/root/.cargo/registry \ + -v "$(pwd)":/home/rust/src \ + -P start9/rust-arm-cross:aarch64 \ + sh -c 'cd /home/rust/src/backend && + rustup install ${{ env.RUST_VERSION }} && + rustup override set ${{ env.RUST_VERSION }} && + rustup target add aarch64-unknown-linux-gnu && + cargo build --release --target ${{ matrix.target }}-unknown-linux-gnu' + if: ${{ matrix.target == 'aarch64' }} + + - name: 'Tar files to preserve file permissions' + run: tar -cvf backend-${{ matrix.target }}.tar ENVIRONMENT.txt GIT_HASH.txt backend/target/${{ matrix.target }}-unknown-linux-gnu/release/embassy* + + - uses: actions/upload-artifact@v3 + with: + name: backend-${{ matrix.target }} + path: backend-${{ matrix.target }}.tar + + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Build and archive tests + run: cargo nextest archive --archive-file nextest-archive-${{ matrix.target }}.tar.zst --target ${{ matrix.target }}-unknown-linux-gnu + working-directory: backend + if: ${{ matrix.target == 'x86_64' }} + + - name: Build and archive tests + run: | + docker run --rm \ + -v "$HOME/.cargo/registry":/root/.cargo/registry \ + -v "$(pwd)":/home/rust/src \ + -P start9/rust-arm-cross:aarch64 \ + sh -c 'cd /home/rust/src/backend && + rustup install ${{ env.RUST_VERSION }} && + rustup override set ${{ env.RUST_VERSION }} && + rustup target add aarch64-unknown-linux-gnu && + curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin && + cargo nextest archive --archive-file nextest-archive-${{ matrix.target }}.tar.zst --target ${{ matrix.target }}-unknown-linux-gnu' + if: ${{ matrix.target == 'aarch64' }} + + - name: Reset permissions + run: sudo chown -R $USER target + working-directory: backend + if: ${{ matrix.target == 'aarch64' }} + + - name: Upload archive to workflow + uses: actions/upload-artifact@v3 + with: + name: nextest-archive-${{ matrix.target }} + path: backend/nextest-archive-${{ matrix.target }}.tar.zst + + run_tests_backend: + name: Test backend + strategy: + fail-fast: false + matrix: + target: [x86_64, aarch64] + include: + - target: x86_64 + - target: aarch64 + runs-on: ubuntu-latest + needs: build_backend + env: + CARGO_TERM_COLOR: always + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + if: ${{ matrix.target == 'aarch64' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + if: ${{ matrix.target == 'aarch64' }} + + - run: mkdir -p ~/.cargo/bin + if: ${{ matrix.target == 'x86_64' }} + + - name: Install nextest + uses: taiki-e/install-action@nextest + if: ${{ matrix.target == 'x86_64' }} + + - name: Download archive + uses: actions/download-artifact@v3 + with: + name: nextest-archive-${{ matrix.target }} + + - name: Download nextest (aarch64) + run: wget -O nextest-aarch64.tar.gz https://get.nexte.st/latest/linux-arm + if: ${{ matrix.target == 'aarch64' }} + + - name: Run tests + run: | + ${CARGO_HOME:-~/.cargo}/bin/cargo-nextest nextest run --no-fail-fast --archive-file nextest-archive-${{ matrix.target }}.tar.zst \ + -E 'not (test(system::test_get_temp) | test(net::tor::test) | test(system::test_get_disk_usage) | test(net::ssl::certificate_details_persist) | test(net::ssl::ca_details_persist))' + if: ${{ matrix.target == 'x86_64' }} + + - name: Run tests + run: | + docker run --rm --platform linux/arm64/v8 \ + -v "/home/runner/.cargo/registry":/usr/local/cargo/registry \ + -v "$(pwd)":/home/rust/src \ + -e CARGO_TERM_COLOR=${{ env.CARGO_TERM_COLOR }} \ + -P ubuntu:20.04 \ + sh -c 'cd /home/rust/src && + mkdir -p ~/.cargo/bin && + tar -zxvf nextest-aarch64.tar.gz -C ${CARGO_HOME:-~/.cargo}/bin && + ${CARGO_HOME:-~/.cargo}/bin/cargo-nextest nextest run --archive-file nextest-archive-${{ matrix.target }}.tar.zst \ + -E "not (test(system::test_get_temp) | test(net::tor::test) | test(system::test_get_disk_usage) | test(net::ssl::certificate_details_persist) | test(net::ssl::ca_details_persist) | test(procedure::js_scripts::js_action_fetch) )"' + if: ${{ matrix.target == 'aarch64' }} diff --git a/.github/workflows/frontend-pr.yaml b/.github/workflows/frontend.yaml similarity index 91% rename from .github/workflows/frontend-pr.yaml rename to .github/workflows/frontend.yaml index 421699727..65b92ed58 100644 --- a/.github/workflows/frontend-pr.yaml +++ b/.github/workflows/frontend.yaml @@ -1,9 +1,12 @@ -name: Frontend PR +name: Frontend on: workflow_call: workflow_dispatch: +env: + NODEJS_VERSION: '16' + jobs: frontend: name: Build frontend @@ -15,7 +18,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: ${{ env.NODEJS_VERSION }} - name: Get npm cache directory id: npm-cache-dir diff --git a/.github/workflows/product.yaml b/.github/workflows/product.yaml index 54741b5fe..61344c416 100644 --- a/.github/workflows/product.yaml +++ b/.github/workflows/product.yaml @@ -19,10 +19,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -56,10 +53,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -72,10 +66,10 @@ jobs: path: system-images/utils/utils.tar backend: - uses: ./.github/workflows/backend-pr.yaml + uses: ./.github/workflows/backend.yaml frontend: - uses: ./.github/workflows/frontend-pr.yaml + uses: ./.github/workflows/frontend.yaml image: name: Build image @@ -113,11 +107,11 @@ jobs: - name: Download backend artifact uses: actions/download-artifact@v3 with: - name: backend + name: backend-aarch64 - name: 'Extract backend' run: - tar -mxvf backend.tar + tar -mxvf backend-aarch64.tar - name: Download frontend artifact uses: actions/download-artifact@v3