Skip to content

Commit

Permalink
ci(actions): Test all feature combinations on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Nov 3, 2024
1 parent 3abb450 commit 53d2055
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
34 changes: 34 additions & 0 deletions .github/generate_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# Copyright (c) 2024 Jan Holthuis <[email protected]>
#
# 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 http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

import argparse
import tomllib
import json
import itertools


def generate_matrix(features: list[str]):
for i in range(len(features) + 1):
yield from itertools.combinations(iter(features), i)


def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument("cargo_file", type=argparse.FileType("rb"))
parser.add_argument("output_file", type=argparse.FileType("w"))
args = parser.parse_args(argv)

cargo_toml = tomllib.load(args.cargo_file)
features = [feature for feature in cargo_toml["features"].keys() if feature != "default"]
matrix = {"include": [{"features": "{}".format(",".join(f))} for f in generate_matrix(features=features)]}

args.output_file.write("matrix={}".format(json.dumps(matrix)))


if __name__ == "__main__":
main()
18 changes: 15 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ name: Build
on: [push, pull_request]

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: python .github/generate_matrix.py Cargo.toml "$GITHUB_OUTPUT"

build:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Print Rust version
run: rustc -vV
- name: Run tests
run: cargo test --all-features --verbose
run: cargo test --no-default-features --features "${{ matrix.features }}" --verbose
- name: Run bench
run: cargo bench --all-features --verbose
run: cargo bench --no-default-features --features "${{ matrix.features }}" --verbose
- name: Run doc
run: cargo doc --all-features --verbose
run: cargo doc --no-default-features --features "${{ matrix.features }}" --verbose

0 comments on commit 53d2055

Please sign in to comment.