swc/scripts/github/create-matrix.sh

52 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-02-24 09:06:03 +03:00
set -u
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
function prepend() { while read line; do echo "${1}${line}"; done; }
crates=$(\
cargo metadata --format-version 1 \
| jq -r '.workspace_members[]' \
| cut -f1 -d" " \
| sort \
)
2022-02-24 09:06:03 +03:00
# yq query syntax is weird, so we have to use jq
json_str="$(yq -o=json $SCRIPT_DIR/tests.yml)"
2022-02-24 09:06:03 +03:00
for crate in $crates
do
echo "- crate: $crate"
echo " os: ubuntu-latest"
2022-09-06 19:47:06 +03:00
if echo $json_str | jq -e "select(.host.\"$crate\")" > /dev/null; then
echo " runner: " `echo $json_str | jq -e -r ".host.\"$crate\""`
else
echo " runner: ubuntu-latest"
fi
if echo $json_str | jq -e ".check.\"$crate\"" > /dev/null; then
2022-02-24 09:06:03 +03:00
echo " check: |"
check_commands=$(echo $json_str | jq -e -r ".check.\"$crate\" | .[]")
2022-02-24 09:06:03 +03:00
while IFS= read -r line; do
2022-09-06 19:47:06 +03:00
echo " $line"
2022-02-24 09:06:03 +03:00
done <<< "$check_commands"
fi
2022-09-06 19:47:06 +03:00
if echo $json_str | jq -e "select(.os.macos | index(\"$crate\"))" > /dev/null; then
echo "- crate: $crate"
echo " os: macos-latest"
2022-09-06 19:47:06 +03:00
echo " runner: macos-latest"
fi
2022-09-06 19:47:06 +03:00
if echo $json_str | jq -e "select(.os.windows | index(\"$crate\"))" > /dev/null; then
echo "- crate: $crate"
echo " os: windows-latest"
2022-09-06 19:47:06 +03:00
echo " runner: windows-latest"
fi
done