name: Build crates individually # Ensures that only one workflow task will run at a time. Previous builds, if # already in process, will get cancelled. Only the latest commit will be allowed # to run, cancelling any workflows in between concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true on: workflow_dispatch: push: branches: - main paths: # production code and test code - '**/*.rs' # dependencies - '**/Cargo.toml' - '**/Cargo.lock' # configuration files - '.cargo/config.toml' - '**/clippy.toml' # workflow definitions - '.github/workflows/build-crates-individually.yml' pull_request: paths: # production code and test code - '**/*.rs' # dependencies - '**/Cargo.toml' - '**/Cargo.lock' # configuration files - '.cargo/config.toml' - '**/clippy.toml' # workflow definitions - '.github/workflows/build-crates-individually.yml' env: CARGO_INCREMENTAL: ${{ vars.CARGO_INCREMENTAL }} RUST_LOG: ${{ vars.RUST_LOG }} RUST_BACKTRACE: ${{ vars.RUST_BACKTRACE }} RUST_LIB_BACKTRACE: ${{ vars.RUST_LIB_BACKTRACE }} COLORBT_SHOW_HIDDEN: ${{ vars.COLORBT_SHOW_HIDDEN }} jobs: matrix: name: Generate crates matrix runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - uses: actions/checkout@v3.5.3 - uses: r7kamura/rust-problem-matchers@v1.3.0 # Setup Rust with stable toolchain and minimal profile - name: Setup Rust run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal # This step is meant to dynamically create a JSON containing the values of each crate # available in this repo in the root directory. We use `cargo tree` to accomplish this task. # # The result from `cargo tree` is then transform to JSON values between double quotes, # and separated by commas, then added to a `crates.txt` and assigned to a $JSON_CRATES variable. # # A JSON object is created and assigned to a $MATRIX variable, which is use to create an output # named `matrix`, which is then used as the input in following steps, # using ` ${{ fromJson(needs.matrix.outputs.matrix) }}` - id: set-matrix name: Dynamically build crates JSON run: | TEMP_DIR=$(mktemp -d) echo "$(cargo tree --depth 0 --edges no-normal,no-dev,no-build,no-proc-macro --prefix none | cut -d ' ' -f1 | sed '/^$/d' | awk '{ printf "\"%s\",\n", $0 }' | sed '$ s/.$//')" > $TEMP_DIR/crates.txt MATRIX=$( ( echo '{ "crate" : [' echo "$(cat $TEMP_DIR/crates.txt)" echo " ]}" ) | jq -c .) echo $MATRIX echo $MATRIX | jq . echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT" check-matrix: name: Check crates matrix runs-on: ubuntu-latest needs: [ matrix ] steps: - name: Install json2yaml run: | sudo npm install -g json2yaml - name: Check matrix definition run: | matrix='${{ needs.matrix.outputs.matrix }}' echo $matrix echo $matrix | jq . echo $matrix | json2yaml build: name: Build ${{ matrix.crate }} crate needs: [ matrix, check-matrix ] runs-on: ubuntu-latest strategy: fail-fast: true matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} steps: - uses: actions/checkout@v3.5.3 with: persist-credentials: false - uses: r7kamura/rust-problem-matchers@v1.3.0 - name: Install last version of Protoc uses: arduino/setup-protoc@v2.0.0 with: # TODO: increase to latest version after https://github.com/arduino/setup-protoc/issues/33 is fixed version: '23.x' repo-token: ${{ secrets.GITHUB_TOKEN }} # Setup Rust with stable toolchain and minimal profile - name: Setup Rust run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal # We could use `features: ['', '--all-features', '--no-default-features']` as a matrix argument, # but it's faster to run these commands sequentially, so they can re-use the local cargo cache. # # Some Zebra crates do not have any features, and most don't have any default features. - name: Build ${{ matrix.crate }} crate with no default features run: | cargo build --package ${{ matrix.crate }} --no-default-features - name: Build ${{ matrix.crate }} crate normally run: | cargo build --package ${{ matrix.crate }} - name: Build ${{ matrix.crate }} crate with all features run: | cargo build --package ${{ matrix.crate }} --all-features