name: CI - Rust permissions: contents: read on: push: paths: # NOTE: GitHub Actions do not allow using YAML references, the same path # list is used below for the pull request event. Keep both lists in sync!! # this file as well - .github/workflows/ci-rust.yml # any change in the rust subfolder - rust/** # except Markdown documentation - "!rust/**.md" # except the packaging - "!rust/package/**" # except the DBus configuration - "!rust/share/**" pull_request: paths: # NOTE: GitHub Actions do not allow using YAML references, the same path # list is used above for the push event. Keep both lists in sync!! # this file as well - .github/workflows/ci-rust.yml # any change in the rust subfolder - rust/** # except Markdown documentation - "!rust/**.md" # except the packaging - "!rust/package/**" # except the DBus configuration - "!rust/share/**" # allow running manually workflow_dispatch: env: CARGO_TERM_COLOR: always # this makes the build slightly faster and the saved cache smaller CARGO_INCREMENTAL: 0 jobs: fmt: # the default timeout is 6 hours, that's too much if the job gets stuck timeout-minutes: 10 runs-on: ubuntu-latest defaults: run: working-directory: ./rust steps: - name: Git Checkout uses: actions/checkout@v4 - name: Rust toolchain run: | rustup show cargo --version - name: Run rustfmt run: cargo fmt --all -- --check clippy: # the default timeout is 6 hours, that's too much if the job gets stuck timeout-minutes: 20 runs-on: ubuntu-latest container: image: registry.opensuse.org/opensuse/tumbleweed:latest options: --security-opt seccomp=unconfined steps: - name: Configure and refresh repositories # disable unused repositories to have faster refresh run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && ( zypper ref || zypper ref || zypper ref ) - name: Install required packages run: zypper --non-interactive install --allow-downgrade clang-devel findutils gcc-c++ git libopenssl-3-devel libsuseconnect libzypp-devel make openssl-3 pam-devel rustup - name: Configure git run: git config --global --add safe.directory "$GITHUB_WORKSPACE" - name: Git Checkout uses: actions/checkout@v4 - name: Install Rust toolchains run: rustup toolchain install stable - name: Rust toolchain run: | rustup show cargo --version - name: Rust cache uses: actions/cache@v4 with: path: | ~/.cargo rust/target key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }} - name: Run Clang Format check for the C/C++ zypp bindings run: make check working-directory: ./rust/zypp-agama/zypp-agama-sys/c-layer - name: Run clippy linter # deny warnings: clippy or rustc warnings will fail the build run: cargo clippy -- -D warnings working-directory: ./rust tests: # the default timeout is 6 hours, that's too much if the job gets stuck timeout-minutes: 30 runs-on: ubuntu-latest container: image: registry.opensuse.org/opensuse/tumbleweed:latest options: --security-opt seccomp=unconfined env: COVERAGE: 1 steps: - name: Configure and refresh repositories # disable unused repositories to have faster refresh run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && ( zypper ref || zypper ref || zypper ref ) - name: Install required packages run: zypper --non-interactive install --allow-downgrade clang-devel dbus-1-daemon gcc-c++ git glibc-locale golang-github-google-jsonnet jq libopenssl-3-devel libsuseconnect libzypp-devel make openssl-3 pam-devel python-langtable-data python3-openapi_spec_validator rustup timezone util-linux-systemd xkeyboard-config - name: Configure git run: git config --global --add safe.directory "$GITHUB_WORKSPACE" - name: Git Checkout uses: actions/checkout@v4 - name: Install Rust toolchains run: rustup toolchain install stable - name: Rust toolchain run: | rustup show cargo --version - name: Prepare for tests run: | # create the /etc/agama.d/locales file with list of locales mkdir -p /etc/agama.d ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" >/etc/agama.d/locales - name: Installed packages run: rpm -qa - name: Rust cache id: cache-tests uses: actions/cache@v4 with: path: | ~/.cargo rust/target-coverage key: ${{ runner.os }}-cargo-tests-${{ hashFiles('**/Cargo.lock') }} - name: Install Tarpaulin (for code coverage) # skip the step completely if the cache has been restored # this avoids refreshing the crates index and saves few seconds if: steps.cache-tests.outputs.cache-hit != 'true' run: cargo install cargo-tarpaulin working-directory: ./rust - name: Run the tests # Compile into the ./target-coverage directory because tarpaulin uses special compilation # flags, to avoid reusing the previous builds it always starts from scratch. # The --skip-clean skips the cleanup and allows using the cached results. # See https://github.com/xd009642/tarpaulin/discussions/772 run: cargo tarpaulin --workspace --all-targets --doc --engine llvm --out xml --target-dir target-coverage --skip-clean -- --nocapture working-directory: ./rust env: # use the "stable" tool chain (installed by default) instead of the "nightly" default in tarpaulin RUSTC_BOOTSTRAP: 1 RUSTUP_TOOLCHAIN: stable RUST_BACKTRACE: full RUSTFLAGS: --cfg ci # send the code coverage for the Rust part to the coveralls.io - name: Send coverage data to Coveralls timeout-minutes: 10 # ignore errors in this step continue-on-error: true uses: coverallsapp/github-action@v2 with: flag-name: rust base-path: ./rust format: cobertura # Close the parallel build and inherit the Web parts (it needs a separate step, the "carryforward" flag can be used # only with the "parallel-finished: true" option) - name: Close the Coveralls build timeout-minutes: 10 # ignore errors in this step continue-on-error: true uses: coverallsapp/github-action@v2 with: parallel-finished: true carryforward: "rust,service,web" openapi: # the default timeout is 6 hours, that's too much if the job gets stuck timeout-minutes: 30 runs-on: ubuntu-latest container: image: registry.opensuse.org/opensuse/tumbleweed:latest steps: - name: Configure and refresh repositories # disable unused repositories to have faster refresh run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && ( zypper ref || zypper ref || zypper ref ) - name: Install required packages run: zypper --non-interactive install --allow-downgrade clang-devel gcc-c++ git libopenssl-3-devel libsuseconnect libzypp-devel make openssl-3 pam-devel python3-openapi_spec_validator rustup - name: Git Checkout uses: actions/checkout@v4 - name: Install Rust toolchains run: rustup toolchain install stable - name: Rust toolchain run: | rustup show cargo --version - name: Installed packages run: rpm -qa - name: Rust cache uses: actions/cache@v4 with: path: | ~/.cargo rust/target key: ${{ runner.os }}-cargo-openapi-${{ hashFiles('**/Cargo.lock') }} - name: Generate the OpenAPI specification run: cargo xtask openapi working-directory: ./rust - name: Validate the OpenAPI specification run: openapi-spec-validator out/openapi/* working-directory: ./rust