Skip to content

Commit

Permalink
Add template test script
Browse files Browse the repository at this point in the history
aelesbao committed Mar 4, 2022

Verified

This commit was signed with the committer’s verified signature.
aelesbao Augusto Elesbão
1 parent f5860a7 commit 7f0f163
Showing 2 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/scripts/test_generate.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7f0f163

Please sign in to comment.