diff --git a/.github/scripts/test_generate.sh b/.github/scripts/test_generate.sh new file mode 100755 index 0000000..834ecc5 --- /dev/null +++ b/.github/scripts/test_generate.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -u -o errexit -o nounset -o pipefail +command -v shellcheck > /dev/null && shellcheck "$0" + +REPO_ROOT="$(realpath "$(dirname "$0")/../..")" +TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/XXXXXXXXX") + +echo "Navigating to $TMP_DIR" +cd "$TMP_DIR" + +function test-template() { + TEMPLATE="${1}" + PROJECT_NAME="${TEMPLATE//\//-}" + echo "#######################################" + echo "# Testing template $TEMPLATE" + echo "#######################################" + ( + GIT_BRANCH=$(git -C "$REPO_ROOT" branch --show-current) + + echo "Generating project from local repository (branch $GIT_BRANCH) ..." + cargo generate --git "$REPO_ROOT" --name "$PROJECT_NAME" --branch "$GIT_BRANCH" "$TEMPLATE" + + ( + cd "$PROJECT_NAME" + echo "This is what was generated" + ls -lA + + # Check formatting + echo "Checking formatting ..." + cargo fmt -- --check + + echo "Running clippy ..." + cargo clippy -- -D warnings + + # Debug builds first to fail fast + echo "Running unit tests ..." + cargo unit-test + echo "Creating schema ..." + cargo schema + + echo "Building wasm ..." + cargo wasm + ) + ) +} + +find "$REPO_ROOT" -name Cargo.toml -exec dirname {} \; | while read -r TEMPLATE; do + test-template "${TEMPLATE//$REPO_ROOT\//}" + echo +done diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..3918dc9 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,27 @@ +on: [push, pull_request] + +name: Check Templates + +jobs: + test-generate: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + override: true + profile: minimal + + - name: Install cargo-generate + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-generate --features vendored-openssl + + - name: Test all templates + run: ${{ github.workspace }}/.github/scripts/test_generate.sh