Skip to content

Commit

Permalink
refactor(ci): build job matrix dinamically
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovalverde committed Jun 18, 2022
1 parent ed2a8df commit 3bcd8a0
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions .github/workflows/build-crates-individually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,37 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- uses: actions-rs/[email protected]
- id: set-matrix
name: Dinamically build crates JSON
run: |
CRATES=$(echo $(cat .github/workflows/scripts/crates.json) | sed 's/ //g' )
echo "::set-output name=matrix::$CRATES"
TEMP_DIR=$(mktemp -d)
CRATES=$(cargo tree --depth 0 --edges no-normal,no-dev,no-build,no-proc-macro --format {p} --prefix none)
echo "$( echo '${CRATES}' | cut -d ' ' -f1 | sed '/^$/d' | awk '{ printf "\"%s\",\n", $0 }' | sed '$ s/.$//')" > $TEMP_DIR/crates.txt
MATRIX=$((
echo '{ "crates" : ['
echo "$(cat $TEMP_DIR/crates.txt)"
echo " ]}"
) | jq -c .)
echo $MATRIX
echo $MATRIX | jq .
echo "::set-output name=matrix::$MATRIX"
test:
name: Test ${{ matrix.crate.name }} crate on ${{ matrix.os }}
name: Test ${{ matrix.crate }} crate
needs: [ matrix ]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
crate: ${{ fromJson(needs.matrix.outputs.matrix) }}
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}

steps:
- uses: actions/[email protected]
Expand All @@ -63,20 +79,20 @@ jobs:
profile: minimal
override: true

- name: Build ${{ matrix.crate.name }} crate normally
- name: Build ${{ matrix.crate }} crate normally
uses: actions-rs/[email protected]
with:
command: build
args: --package ${{ matrix.crate.name }}
args: --package ${{ matrix.crate }}

- name: Build ${{ matrix.crate.name }} crate with all features
uses: actions-rs/[email protected]
with:
command: build
args: --package ${{ matrix.crate.name }} --all-features
args: --package ${{ matrix.crate }} --all-features

- name: Build ${{ matrix.crate.name }} crate with no default features
- name: Build ${{ matrix.crate }} crate with no default features
uses: actions-rs/[email protected]
with:
command: build
args: --package ${{ matrix.crate.name }} --no-default-features
args: --package ${{ matrix.crate }} --no-default-features

0 comments on commit 3bcd8a0

Please sign in to comment.