Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,66 @@ jobs:
else
echo "No integration tests found, skipping..."
fi

# The app `amber new` generates (SQLite, Grant, asset_pipeline) links no
# regex engine, before and after a scaffold adds a Grant model. The stock
# tarballs link PCRE2 statically, so the check reads symbols as well as
# libraries, and a control program that uses Regex must show them.
generated-app-linkage:
name: Generated app links no PCRE2 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: test
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
crystal_version: 1.22.2
crystal_tarball: crystal-1.22.2-1-linux-x86_64-bundled.tar.gz
crystal_sha256: 0dc5c3ff1b5710c3981e207a6241fc06cc28fadb6622d5fdb21999adf1ca2309
- os: macos-15
crystal_version: 1.22.2
crystal_tarball: crystal-1.22.2-1-darwin-universal.tar.gz
crystal_sha256: 9c73ddd00aa8c9bf9f8fdc5aebdde99a92a63c2e2539b8ad5f9b8a27813ddc6f

steps:
- name: Checkout code
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false

- name: Install the generated app's system libraries (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libsqlite3-dev libyaml-dev libssl-dev libgmp-dev zlib1g-dev

- name: Install the generated app's system libraries (macOS)
if: runner.os == 'macOS'
run: brew install libyaml gmp

- name: Install Crystal ${{ matrix.crystal_version }} (sha256-verified)
env:
CRYSTAL_TARBALL: ${{ matrix.crystal_tarball }}
CRYSTAL_SHA256: ${{ matrix.crystal_sha256 }}
CRYSTAL_VERSION: ${{ matrix.crystal_version }}
run: |
set -euo pipefail
archive="$RUNNER_TEMP/$CRYSTAL_TARBALL"
curl -fsSL --retry 3 -o "$archive" \
"https://github.com/crystal-lang/crystal/releases/download/$CRYSTAL_VERSION/$CRYSTAL_TARBALL"
echo "$CRYSTAL_SHA256 $archive" | shasum -a 256 -c -
tar -xzf "$archive" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/crystal-$CRYSTAL_VERSION-1/bin" >> "$GITHUB_PATH"

- name: Build pinned Minecart
run: scripts/install_pinned_minecart.sh

- name: Install dependencies
run: minecart install --frozen --skip-ai-docs

- name: Compile CLI
run: crystal build src/amber_cli.cr --no-debug -o amber

- name: Check what the generated app links
run: scripts/check_generated_app_linkage.sh ./amber "$RUNNER_TEMP/generated-app-linkage"
14 changes: 8 additions & 6 deletions scripts/check_beta_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ test "$shard_version" = "2.0.10"
test "$cli_version" = "$shard_version"

grep -F 'github: amberframework/amber' src/amber_cli/commands/new_command.cr
grep -F 'commit: #{AmberRelease::COMMIT} # #{AmberRelease::VERSION} on v2-dev' src/amber_cli/commands/new_command.cr
grep -F 'COMMIT = "d775841a0af43bf512f1c9b704906fccdf8863f7"' src/amber_cli/amber_release.cr
grep -F 'TREE = "e06f26daef02a30e91114b2c71224920e0c097de"' src/amber_cli/amber_release.cr
grep -F 'CHECKSUM = "sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d"' src/amber_cli/amber_release.cr
grep -F 'commit: #{AmberRelease::COMMIT} # #{AmberRelease::VERSION}, fix/1425-respond-with-named-tuple (amberframework/amber#1451)' src/amber_cli/commands/new_command.cr
grep -F 'COMMIT = "43a361419514b49388d5716c97e5b95d170ba5a8"' src/amber_cli/amber_release.cr
grep -F 'TREE = "332d04b4e88fc045f4b0784157eea21e33297b42"' src/amber_cli/amber_release.cr
grep -F 'CHECKSUM = "sha256-v2:f58fc614bc2c719985a1ca0bae9a206c75d57a42ef75fe8781116d45b9e88ba7"' src/amber_cli/amber_release.cr
grep -F 'template: ecr' src/amber_cli/commands/new_command.cr
grep -F 'model: grant' src/amber_cli/commands/new_command.cr
grep -F 'database: #{database}' src/amber_cli/commands/new_command.cr
grep -F 'github: crimson-knight/grant' src/amber_cli/commands/new_command.cr
grep -F 'github: amberframework/asset_pipeline' src/amber_cli/commands/new_command.cr
grep -F 'commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1' src/amber_cli/commands/new_command.cr
grep -F 'commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd # 0.38.0, regex-free-default-require (amberframework/asset_pipeline#25)' src/amber_cli/commands/new_command.cr
grep -F 'github: amberframework/asset_pipeline' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd # 0.38.0, regex-free-default-require (amberframework/asset_pipeline#25)' src/amber_cli/templates/app/shard.yml.ecr
grep -F 'github: amberframework/amber' src/amber_cli/generators/native_app.cr
grep -F 'commit: d291e0930dd22b14a2d10f75a9de063abb0e64e4 # v2.0.0-beta.10' src/amber_cli/generators/native_app.cr
grep -F 'version: ~> 0.37.1' src/amber_cli/generators/native_app.cr
Expand All @@ -43,6 +43,8 @@ if grep -F '# schema = #{class_name}Schema.new(data)' src/amber_cli/commands/g
fi

grep -F 'scripts/smoke_generated_web.sh ./amber' .github/workflows/release.yml
test -x scripts/check_generated_app_linkage.sh
grep -F 'scripts/check_generated_app_linkage.sh ./amber' .github/workflows/ci.yml
if grep -R -F 'AMBER_CANDIDATE_FRAMEWORK' .github/workflows; then
echo "CI workflows must test the published framework emitted by the template" >&2
exit 1
Expand Down
122 changes: 122 additions & 0 deletions scripts/check_generated_app_linkage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash
# Checks that the app `amber new` generates links no regex engine.
#
# 1. scripts/linkage/regex_control.cr links PCRE2, which proves the check can fail.
# 2. `amber new linkage_probe -d sqlite` builds into a binary that links no
# libpcre2 and holds no pcre2_ symbol, and its home page answers 200.
# 3. After `amber generate scaffold` adds a Grant model, controller and schema,
# the rebuilt binary still links no PCRE2 and its specs pass.
#
# usage: scripts/check_generated_app_linkage.sh /path/to/amber [OUTPUT_DIR]
# Set CRYSTAL to choose the compiler; crystal-alpha is preferred when present.
# Minecart must be on PATH (scripts/install_pinned_minecart.sh puts it there).
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "usage: $0 /path/to/amber [output-directory]" >&2
exit 64
fi

script_dir="$(cd "$(dirname "$0")" && pwd)"
cli_path="$1"
if [[ "$cli_path" != /* ]]; then
cli_path="$(cd "$(dirname "$cli_path")" && pwd)/$(basename "$cli_path")"
fi
output_directory="${2:-${TMPDIR:-/tmp}/amber-generated-app-linkage}"
probe_port="${LINKAGE_PROBE_PORT:-39128}"
if [[ -z "${CRYSTAL:-}" ]]; then
if command -v crystal-alpha >/dev/null 2>&1; then CRYSTAL=crystal-alpha; else CRYSTAL=crystal; fi
fi
command -v minecart >/dev/null 2>&1 || { echo "Minecart is required to generate the app" >&2; exit 1; }

rm -rf "$output_directory"
mkdir -p "$output_directory"
app_path="$output_directory/linkage_probe"
server_pid=""

cleanup() {
if [[ -n "$server_pid" ]] && kill -0 "$server_pid" 2>/dev/null; then
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
fi
}
trap cleanup EXIT

list_libraries() {
if [[ "$(uname -s)" == "Darwin" ]]; then
otool -L "$1" | tail -n +2 | awk '{print $1}'
else
ldd "$1" | awk '{print $1}'
fi
}

count_pcre2_libraries() {
list_libraries "$1" | grep -c pcre2 || true
}

count_pcre2_symbols() {
nm "$1" 2>/dev/null | grep -c pcre2_ || true
}

status=0

# Fails the run when the binary reaches PCRE2, and prints what it links.
check_binary_is_pcre2_free() {
local label="$1" binary="$2"
echo "$label links:"
list_libraries "$binary" | sed 's/^/ /'
local library_count symbol_count
library_count="$(count_pcre2_libraries "$binary")"
symbol_count="$(count_pcre2_symbols "$binary")"
if [[ "$library_count" -ne 0 || "$symbol_count" -ne 0 ]]; then
echo "FAIL: $label reaches PCRE2 ($library_count libraries, $symbol_count pcre2_ symbols)"
status=1
else
echo "ok: $label links no PCRE2 and holds no pcre2_ symbol"
fi
}

"$CRYSTAL" --version | head -1

"$CRYSTAL" build "$script_dir/linkage/regex_control.cr" -o "$output_directory/regex_control"
control_library_count="$(count_pcre2_libraries "$output_directory/regex_control")"
control_symbol_count="$(count_pcre2_symbols "$output_directory/regex_control")"
if [[ "$control_library_count" -eq 0 && "$control_symbol_count" -eq 0 ]]; then
echo "FAIL: regex_control shows no PCRE2, so this check cannot see it"
status=1
else
echo "ok: regex_control reaches PCRE2 ($control_library_count libraries, $control_symbol_count pcre2_ symbols), so the check can fail"
fi

(cd "$output_directory" && "$cli_path" new linkage_probe -d sqlite -y --skip-agent-setup)
cd "$app_path"

mkdir -p bin
"$CRYSTAL" build src/linkage_probe.cr -o bin/linkage_probe
check_binary_is_pcre2_free "default app" bin/linkage_probe

AMBER_ENV=development AMBER_SERVER_PORT="$probe_port" bin/linkage_probe > "$output_directory/server.log" 2>&1 &
server_pid=$!
home_status="000"
for _ in $(seq 1 50); do
home_status="$(curl --silent --output /dev/null --max-time 1 --write-out '%{http_code}' "http://127.0.0.1:$probe_port/" || true)"
[[ "$home_status" == "200" ]] && break
sleep 0.2
done
if [[ "$home_status" == "200" ]]; then
echo "ok: the default app answers GET / with 200"
else
echo "FAIL: the default app answered GET / with $home_status"
tail -20 "$output_directory/server.log"
status=1
fi
cleanup
server_pid=""

"$cli_path" generate scaffold Pet name:string:required species:string:required adopted:bool
"$CRYSTAL" build src/linkage_probe.cr -o bin/linkage_probe_scaffold
check_binary_is_pcre2_free "scaffolded app" bin/linkage_probe_scaffold
AMBER_ENV=test "$cli_path" database migrate
AMBER_ENV=test "$CRYSTAL" spec

exit $status
4 changes: 4 additions & 0 deletions scripts/linkage/regex_control.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Control program for scripts/check_generated_app_linkage.sh. It uses Regex,
# so its binary must show PCRE2; that proves the linkage check can fail.
pattern = Regex.new("a+b")
exit(pattern.matches?(ARGV[0]? || "aab") ? 0 : 1)
8 changes: 4 additions & 4 deletions scripts/smoke_generated_web.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $amberConfig = [System.IO.File]::ReadAllText($amberConfigPath)
if (-not $manifest.Contains("github: amberframework/amber")) {
throw "Generated shard.yml does not include Amber"
}
if (-not $manifest.Contains("commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev")) {
if (-not $manifest.Contains("commit: 43a361419514b49388d5716c97e5b95d170ba5a8 # 2.0.0-beta.10, fix/1425-respond-with-named-tuple (amberframework/amber#1451)")) {
throw "Generated shard.yml does not pin the supported Amber beta"
}
if (-not $manifest.Contains("github: crimson-knight/grant")) {
Expand All @@ -55,7 +55,7 @@ if ($manifest.Contains("crystal-sqlite3")) {
if (-not $manifest.Contains("github: amberframework/asset_pipeline")) {
throw "Generated shard.yml does not include Asset Pipeline"
}
if (-not $manifest.Contains("commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1")) {
if (-not $manifest.Contains("commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd # 0.38.0, regex-free-default-require (amberframework/asset_pipeline#25)")) {
throw "Generated shard.yml does not pin the supported Asset Pipeline release"
}
if (-not (Test-Path (Join-Path $appPath ".claude/CLAUDE.md"))) {
Expand All @@ -74,7 +74,7 @@ if (-not $amberConfig.Contains("database: sqlite") -or -not $amberConfig.Contain

if ($FrameworkCommit) {
$releasedRepository = " github: amberframework/amber"
$releasedFramework = " commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev"
$releasedFramework = " commit: 43a361419514b49388d5716c97e5b95d170ba5a8 # 2.0.0-beta.10, fix/1425-respond-with-named-tuple (amberframework/amber#1451)"
if (-not $manifest.Contains($releasedRepository)) {
throw "Generated shard.yml does not contain the expected Amber repository"
}
Expand Down Expand Up @@ -118,7 +118,7 @@ try {
$expectedAmberCommit = $FrameworkCommit
$expectedAmberGit = "https://github.com/$FrameworkRepository.git"
} else {
$expectedAmberCommit = "d775841a0af43bf512f1c9b704906fccdf8863f7"
$expectedAmberCommit = "43a361419514b49388d5716c97e5b95d170ba5a8"
$expectedAmberGit = "https://github.com/amberframework/amber.git"
}
if ($amberEntry -notmatch "(?m)^ git: $([regex]::Escape($expectedAmberGit))\r?$") {
Expand Down
16 changes: 8 additions & 8 deletions scripts/smoke_generated_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ grep -F 'AMBER_ENV=test crystal spec' "$script_dir/../src/amber_cli/templates/ap
! grep -F 'crystal-alpha' "$script_dir/../src/amber_cli/templates/app/.amber.yml.ecr"

grep -F "github: amberframework/amber" "$app_path/shard.yml"
grep -F "commit: d775841a0af43bf512f1c9b704906fccdf8863f7 # 2.0.0-beta.10 on v2-dev" "$app_path/shard.yml"
grep -F "commit: 43a361419514b49388d5716c97e5b95d170ba5a8 # 2.0.0-beta.10, fix/1425-respond-with-named-tuple (amberframework/amber#1451)" "$app_path/shard.yml"
grep -F "github: crimson-knight/grant" "$app_path/shard.yml"
grep -F "github: amberframework/asset_pipeline" "$app_path/shard.yml"
grep -F "commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1" "$app_path/shard.yml"
grep -F "commit: 623c4bcad284fcee000244c8b26651f925e23ceb" "$app_path/shard.yml"
grep -F "commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd # 0.38.0, regex-free-default-require (amberframework/asset_pipeline#25)" "$app_path/shard.yml"
grep -F "commit: fe59cbc5b409f67035cf4383e7293c60674ddb3e" "$app_path/shard.yml"
! grep -F "crystal-sqlite3" "$app_path/shard.yml"
grep -F "template: ecr" "$app_path/.amber.yml"
grep -F "database: sqlite" "$app_path/.amber.yml"
Expand All @@ -68,7 +68,7 @@ fi

if [[ -n "$framework_commit" ]]; then
sed -i.bak -E "s# github: amberframework/amber# github: ${framework_repository}#" "$app_path/shard.yml"
sed -i.bak -E "s/ commit: d775841a0af43bf512f1c9b704906fccdf8863f7( # [^#]+)?$/ commit: ${framework_commit}/" "$app_path/shard.yml"
sed -i.bak -E "s/ commit: 43a361419514b49388d5716c97e5b95d170ba5a8( # [^#]+)?$/ commit: ${framework_commit}/" "$app_path/shard.yml"
rm -f "$app_path/shard.yml.bak"
fi

Expand All @@ -86,7 +86,7 @@ else
minecart install --frozen
fi
test -s shard.lock
grep -F "version: 0.23.4+git.commit.623c4bcad284fcee000244c8b26651f925e23ceb" shard.lock
grep -F "version: 0.24.0+git.commit.fe59cbc5b409f67035cf4383e7293c60674ddb3e" shard.lock
grep -F "version: 0.14.0" shard.lock
# Each shard entry carries exactly one checksum.
awk '
Expand All @@ -100,14 +100,14 @@ if [[ -n "$framework_commit" ]]; then
expected_amber_commit="$framework_commit"
expected_amber_git="https://github.com/${framework_repository}.git"
else
expected_amber_commit="d775841a0af43bf512f1c9b704906fccdf8863f7"
expected_amber_commit="43a361419514b49388d5716c97e5b95d170ba5a8"
expected_amber_git="https://github.com/amberframework/amber.git"
fi
grep -qxF " git: ${expected_amber_git}" <<<"$amber_entry"
grep -qE "^ version: [^ ]+\+git\.commit\.${expected_amber_commit}$" <<<"$amber_entry"
if [[ -z "$framework_commit" ]]; then
grep -qxF " version: 2.0.0-beta.10+git.commit.d775841a0af43bf512f1c9b704906fccdf8863f7" <<<"$amber_entry"
grep -qxF " checksum: sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d" <<<"$amber_entry"
grep -qxF " version: 2.0.0-beta.10+git.commit.43a361419514b49388d5716c97e5b95d170ba5a8" <<<"$amber_entry"
grep -qxF " checksum: sha256-v2:f58fc614bc2c719985a1ca0bae9a206c75d57a42ef75fe8781116d45b9e88ba7" <<<"$amber_entry"
fi
"$cli_path" assets build
"$cli_path" assets check
Expand Down
6 changes: 3 additions & 3 deletions spec/commands/new_command_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ describe AmberCLI::Commands::NewCommand do

shard = File.read(File.join(destination, "shard.yml"))
shard.should contain("github: amberframework/amber")
shard.should contain("commit: #{AmberCLI::AmberRelease::COMMIT} # #{AmberCLI::AmberRelease::VERSION} on v2-dev")
shard.should contain("commit: #{AmberCLI::AmberRelease::COMMIT} # #{AmberCLI::AmberRelease::VERSION}, fix/1425-respond-with-named-tuple (amberframework/amber#1451)")
shard.should contain("grant:")
shard.should contain("github: crimson-knight/grant")
shard.should contain("commit: 623c4bcad284fcee000244c8b26651f925e23ceb")
shard.should contain("commit: fe59cbc5b409f67035cf4383e7293c60674ddb3e")
shard.should contain("asset_pipeline:")
shard.should contain("github: amberframework/asset_pipeline")
shard.should contain("commit: ac630a4c948080bf45e9b1e66451c48da9a69349")
shard.should contain("commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd")
shard.should_not contain("version: ~> 0.37.1")
shard.should_not contain("crystal-sqlite3")
shard.should_not contain("crystal-pg")
Expand Down
12 changes: 9 additions & 3 deletions src/amber_cli/amber_release.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module AmberCLI
# `shard.yml`, pinned by commit, and the checksums Minecart must record for
# it. A release of Amber CLI that moves to a new Amber release changes all of
# them together.
#
# INTEGRATION PINS (beta.11): COMMIT, TREE and CHECKSUM point at the head of
# amberframework/amber#1451 so the regex-free Grant and asset_pipeline
# branches can be proven together. Before this branch merges they become the
# tagged v2.0.0-beta.11 commit, its tree and its Minecart checksum, and
# VERSION becomes "2.0.0-beta.11".
module AmberRelease
VERSION = "2.0.0-beta.10"
COMMIT = "d775841a0af43bf512f1c9b704906fccdf8863f7"
TREE = "e06f26daef02a30e91114b2c71224920e0c097de"
COMMIT = "43a361419514b49388d5716c97e5b95d170ba5a8"
TREE = "332d04b4e88fc045f4b0784157eea21e33297b42"
# What Minecart 2025.11.25.9 and newer record for this tree in `shard.lock`.
CHECKSUM = "sha256-v2:e1099a4f7a25db316b2abdf80f999a2753a0fcc056834f3abe6d9b5a88ae945d"
CHECKSUM = "sha256-v2:f58fc614bc2c719985a1ca0bae9a206c75d57a42ef75fe8781116d45b9e88ba7"
end
end
9 changes: 6 additions & 3 deletions src/amber_cli/commands/new_command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ module AmberCLI::Commands
info "Created project structure"
end

# INTEGRATION PINS (beta.11): Grant and asset_pipeline point at the heads of
# crimson-knight/grant#73 and amberframework/asset_pipeline#25. Before this
# branch merges they become the commits of those shards' release tags.
private def create_shard_yml(path : String, name : String)
shard_content = <<-SHARD
name: #{name}
Expand All @@ -410,13 +413,13 @@ targets:
dependencies:
amber:
github: amberframework/amber
commit: #{AmberRelease::COMMIT} # #{AmberRelease::VERSION} on v2-dev
commit: #{AmberRelease::COMMIT} # #{AmberRelease::VERSION}, fix/1425-respond-with-named-tuple (amberframework/amber#1451)
grant:
github: crimson-knight/grant
commit: 623c4bcad284fcee000244c8b26651f925e23ceb # 0.23.4
commit: fe59cbc5b409f67035cf4383e7293c60674ddb3e # 0.24.0, grant-regex-free-default-path (crimson-knight/grant#73)
asset_pipeline:
github: amberframework/asset_pipeline
commit: ac630a4c948080bf45e9b1e66451c48da9a69349 # 0.37.1
commit: abbef01db50e2d4a91b09b5356c0f9309347a8fd # 0.38.0, regex-free-default-require (amberframework/asset_pipeline#25)
#{database_shard_dependency}
SHARD

Expand Down
Loading
Loading