almost empty

This commit is contained in:
2026-01-30 22:44:32 +01:00
commit b5320bf29a
22 changed files with 1576 additions and 0 deletions

61
scripts/ci/clean-environment.sh Executable file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
# © 2025 Platform Engineering Labs Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Clean Environment Hook
# ======================
# This script is called before AND after conformance tests to clean up
# test resources in your cloud environment.
#
# Purpose:
# - Before tests: Remove orphaned resources from previous failed runs
# - After tests: Clean up resources created during the test run
#
# The script should be idempotent - safe to run multiple times.
# It should delete all resources matching the test resource prefix.
#
# Test resources typically use a naming convention like:
# formae-plugin-sdk-test-{run-id}-*
#
# Implementation varies by provider. Examples:
#
# AWS:
# - List and delete resources with test prefix using AWS CLI
# - Use resource tagging for easier identification
#
# OpenStack:
# - Use openstack CLI to list and delete test resources
# - Clean up in order: instances, volumes, networks, security groups, etc.
#
# Exit with non-zero status only for unexpected errors.
# Missing resources (already cleaned) should not cause failures.
set -euo pipefail
# Prefix used for test resources - should match what conformance tests create
TEST_PREFIX="${TEST_PREFIX:-formae-plugin-sdk-test-}"
echo "clean-environment.sh: Cleaning resources with prefix '${TEST_PREFIX}'"
echo ""
echo "To implement cleanup for your provider, edit this script."
echo "See comments in this file for examples."
echo ""
# Uncomment and modify for your provider:
#
# # AWS - clean up S3 buckets with test prefix
# echo "Cleaning S3 buckets..."
# aws s3api list-buckets --query "Buckets[?starts_with(Name, '${TEST_PREFIX}')].Name" --output text | \
# xargs -r -n1 aws s3 rb --force s3://
#
# # OpenStack - clean up instances
# echo "Cleaning instances..."
# openstack server list --name "^${TEST_PREFIX}" -f value -c ID | \
# xargs -r -n1 openstack server delete --wait
#
# # OpenStack - clean up volumes
# echo "Cleaning volumes..."
# openstack volume list --name "^${TEST_PREFIX}" -f value -c ID | \
# xargs -r -n1 openstack volume delete
echo "clean-environment.sh: Cleanup complete (no-op - not configured)"

174
scripts/run-conformance-tests.sh Executable file
View File

@@ -0,0 +1,174 @@
#!/bin/bash
# © 2025 Platform Engineering Labs Inc.
# SPDX-License-Identifier: FSL-1.1-ALv2
#
# Script to run conformance tests against a specific version of formae.
#
# Usage:
# ./scripts/run-conformance-tests.sh [VERSION]
#
# Arguments:
# VERSION - Optional formae version (e.g., 0.76.0). Defaults to "latest".
#
# Environment variables:
# FORMAE_BINARY - Path to formae binary (skips download if set)
# FORMAE_INSTALL_PREFIX - Installation directory (default: temp directory)
# FORMAE_TEST_FILTER - Filter tests by name pattern (e.g., "s3-bucket")
# FORMAE_TEST_TYPE - Select test type: "all" (default), "crud", or "discovery"
set -euo pipefail
# Cross-platform sed in-place edit (macOS vs Linux)
sed_inplace() {
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
VERSION="${1:-latest}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
# =============================================================================
# Setup Formae Binary
# =============================================================================
# Check if FORMAE_BINARY is already set and valid
if [[ -n "${FORMAE_BINARY:-}" ]] && [[ -x "${FORMAE_BINARY}" ]]; then
echo "Using FORMAE_BINARY from environment: ${FORMAE_BINARY}"
# Extract version from binary if not explicitly provided
if [[ "${VERSION}" == "latest" ]]; then
VERSION=$("${FORMAE_BINARY}" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [[ -z "${VERSION}" ]]; then
echo "Warning: Could not extract version from FORMAE_BINARY, using 'latest'"
VERSION="latest"
else
echo "Detected formae version: ${VERSION}"
fi
fi
else
# Always download formae to temp directory for conformance tests
# Don't use system-installed formae to ensure version consistency
INSTALL_DIR=$(mktemp -d -t formae-conformance-XXXXXX)
echo "Using temp directory: ${INSTALL_DIR}"
trap "rm -rf ${INSTALL_DIR}" EXIT
# Determine OS and architecture
DETECTED_OS=$(uname | tr '[:upper:]' '[:lower:]')
DETECTED_ARCH=$(uname -m | tr -d '_')
# Resolve version if "latest"
if [[ "${VERSION}" == "latest" ]]; then
echo "Resolving latest version..."
VERSION=$(curl -s https://hub.platform.engineering/binaries/repo.json | \
jq -r "[.Packages[] | select(.Version | index(\"-\") | not) | select(.OsArch.OS == \"${DETECTED_OS}\" and .OsArch.Arch == \"${DETECTED_ARCH}\")][0].Version")
if [[ -z "${VERSION}" || "${VERSION}" == "null" ]]; then
echo "Error: Could not determine latest version for ${DETECTED_OS}-${DETECTED_ARCH}"
exit 1
fi
fi
echo "Downloading formae version ${VERSION}..."
PKGNAME="formae@${VERSION}_${DETECTED_OS}-${DETECTED_ARCH}.tgz"
DOWNLOAD_URL="https://hub.platform.engineering/binaries/pkgs/${PKGNAME}"
if ! curl -fsSL "${DOWNLOAD_URL}" -o "${INSTALL_DIR}/${PKGNAME}"; then
echo "Error: Failed to download ${DOWNLOAD_URL}"
exit 1
fi
# Extract to install directory
echo "Extracting..."
tar -xzf "${INSTALL_DIR}/${PKGNAME}" -C "${INSTALL_DIR}"
# Find the formae binary
FORMAE_BINARY="${INSTALL_DIR}/formae/bin/formae"
if [[ ! -x "${FORMAE_BINARY}" ]]; then
# Try alternative locations
if [[ -x "${INSTALL_DIR}/bin/formae" ]]; then
FORMAE_BINARY="${INSTALL_DIR}/bin/formae"
elif [[ -x "${INSTALL_DIR}/formae" ]]; then
FORMAE_BINARY="${INSTALL_DIR}/formae"
else
echo "Error: formae binary not found in ${INSTALL_DIR}"
find "${INSTALL_DIR}" -name "formae" -type f 2>/dev/null || ls -laR "${INSTALL_DIR}"
exit 1
fi
fi
fi
echo ""
echo "Using formae binary: ${FORMAE_BINARY}"
"${FORMAE_BINARY}" --version
# Export environment variables for the tests
# FORMAE_VERSION is required by the plugin SDK to resolve PKL schema paths
export FORMAE_BINARY
export FORMAE_VERSION="${VERSION}"
# Pass through test filter and type if set
if [[ -n "${FORMAE_TEST_FILTER:-}" ]]; then
export FORMAE_TEST_FILTER
echo "Test filter: ${FORMAE_TEST_FILTER}"
fi
if [[ -n "${FORMAE_TEST_TYPE:-}" ]]; then
export FORMAE_TEST_TYPE
echo "Test type: ${FORMAE_TEST_TYPE}"
fi
# =============================================================================
# Update and Resolve PKL Dependencies
# =============================================================================
# Update testdata/PklProject with the resolved formae version, then resolve
# dependencies from the public package registry.
# =============================================================================
echo ""
echo "Updating PKL dependencies for formae version ${VERSION}..."
# Update PklProject files with the resolved formae version
if [[ "${VERSION}" != "latest" ]]; then
# Update schema/pkl/PklProject (plugin schema depends on formae)
if [[ -f "${PROJECT_ROOT}/schema/pkl/PklProject" ]]; then
echo "Updating schema/pkl/PklProject to use formae@${VERSION}..."
sed_inplace "s|formae/formae@[0-9a-zA-Z.\-]*\"|formae/formae@${VERSION}\"|g" "${PROJECT_ROOT}/schema/pkl/PklProject"
fi
# Update testdata/PklProject (test files depend on formae)
if [[ -f "${PROJECT_ROOT}/testdata/PklProject" ]]; then
echo "Updating testdata/PklProject to use formae@${VERSION}..."
sed_inplace "s|formae/formae@[0-9a-zA-Z.\-]*\"|formae/formae@${VERSION}\"|g" "${PROJECT_ROOT}/testdata/PklProject"
fi
fi
# Resolve schema dependencies (if any)
if [[ -f "${PROJECT_ROOT}/schema/pkl/PklProject" ]]; then
echo "Resolving schema/pkl dependencies..."
if ! pkl project resolve "${PROJECT_ROOT}/schema/pkl" 2>&1; then
echo "Error: Failed to resolve schema/pkl dependencies"
echo "Make sure the formae PKL package is accessible at the configured URL"
exit 1
fi
fi
# Resolve testdata dependencies
if [[ -f "${PROJECT_ROOT}/testdata/PklProject" ]]; then
echo "Resolving testdata dependencies..."
if ! pkl project resolve "${PROJECT_ROOT}/testdata" 2>&1; then
echo "Error: Failed to resolve testdata dependencies"
exit 1
fi
fi
echo "PKL dependencies resolved successfully"
# =============================================================================
# Run Conformance Tests
# =============================================================================
echo ""
echo "Running conformance tests..."
cd "${PROJECT_ROOT}"
go test -tags=conformance -v -timeout 30m ./...