From 7f0f16306c7ca647bc883f5080d08bab4e7c7e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augusto=20Elesb=C3=A3o?= Date: Fri, 4 Mar 2022 20:13:30 +0100 Subject: [PATCH] Add template test script --- .github/scripts/test_generate.sh | 50 ++++++++++++++++++++++++++++++++ .github/workflows/check.yml | 27 +++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 .github/scripts/test_generate.sh create mode 100644 .github/workflows/check.yml 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