Skip to content
Merged
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
58 changes: 58 additions & 0 deletions .github/scripts/stage-build-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -euo pipefail

if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 <build-dir> <artifact-dir> [--include-tests]" >&2
exit 1
fi

build_dir="$1"
artifact_dir="$2"
include_tests="${3:-}"

mkdir -p "$artifact_dir"

shopt -s nullglob

entrypoints=(./*.dpr)
if [ "${#entrypoints[@]}" -eq 0 ]; then
echo "::error::No top-level .dpr entrypoints found"
exit 1
fi

for src in "${entrypoints[@]}"; do
name="$(basename "${src%.dpr}")"
copied_binary=0

for candidate in "$build_dir/$name" "$build_dir/$name.exe"; do
if [ -f "$candidate" ]; then
cp "$candidate" "$artifact_dir/"
copied_binary=1
fi
done

if [ "$copied_binary" -eq 0 ]; then
echo "::error::Missing compiled binary for $src in $build_dir"
exit 1
fi
done

if [ "$include_tests" = "--include-tests" ]; then
copied_test=0

for test_bin in "$build_dir"/Goccia.*.Test "$build_dir"/Goccia.*.Test.exe; do
if [ -f "$test_bin" ]; then
cp "$test_bin" "$artifact_dir/"
copied_test=1
fi
done

if [ "$copied_test" -eq 0 ]; then
echo "::error::No Pascal unit test binaries found in $build_dir"
exit 1
fi
fi

echo "Staged artifacts:"
ls -la "$artifact_dir"
40 changes: 24 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ jobs:
echo "rtl-generics units: $(ls "$GEN_DIR"/*.ppu 2>/dev/null | wc -l) .ppu files"
echo "fcl-process units: $(ls "$FCL_DIR"/*.ppu 2>/dev/null | wc -l) .ppu files"

# Build main binaries
for src in ScriptLoader.dpr TestRunner.dpr BenchmarkRunner.dpr REPL.dpr; do
name="${src%.dpr}"
# Build top-level program entrypoints
shopt -s nullglob
entrypoints=(./*.dpr)
if [ "${#entrypoints[@]}" -eq 0 ]; then
echo "::error::No top-level .dpr entrypoints found"
exit 1
fi

for src in "${entrypoints[@]}"; do
name="$(basename "${src%.dpr}")"
echo ""
echo "=== Building ${name} for ${TARGET} ==="
"$CROSS_FPC" -T"${OS}" -O4 -dPRODUCTION -Xs -CX -XX -B \
Expand Down Expand Up @@ -149,12 +156,15 @@ jobs:
echo "=== Build artifacts for ${TARGET} ==="
ls -la build/

- name: Stage build artifacts
run: bash ./.github/scripts/stage-build-artifacts.sh build ci-artifacts --include-tests

- name: Upload build artifacts
uses: actions/upload-artifact@v5
with:
name: gocciascript-${{ matrix.target }}
retention-days: 1
path: build/
path: ci-artifacts/*

test:
needs: build
Expand Down Expand Up @@ -511,26 +521,25 @@ jobs:
- x86_64-win64
- i386-win32
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Download build
uses: actions/download-artifact@v5
with:
name: gocciascript-${{ matrix.target }}
path: build/

- name: Upload release artifacts
- name: Stage release artifacts
run: bash ./.github/scripts/stage-build-artifacts.sh build release-artifacts
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

- name: Upload release artifact bundle
uses: actions/upload-artifact@v5
with:
name: gocciascript-release-${{ matrix.target }}
if-no-files-found: ignore
path: |
build/ScriptLoader
build/ScriptLoader.exe
build/TestRunner
build/TestRunner.exe
build/BenchmarkRunner
build/BenchmarkRunner.exe
build/REPL
build/REPL.exe
path: release-artifacts/*

release:
needs: [test, benchmark, examples]
Expand Down Expand Up @@ -575,9 +584,8 @@ jobs:
display="${DISPLAY_NAMES[$target]}"
archive_name="gocciascript-${VERSION}-${display}"
pkg_dir="${archive_name}"
mkdir -p "$pkg_dir"
bash ./.github/scripts/stage-build-artifacts.sh "$artifact_dir" "$pkg_dir"

find "$artifact_dir" -maxdepth 1 -type f ! -name '*.Test' ! -name '*.Test.exe' -exec cp {} "$pkg_dir/" \;
cp -r tests/ "$pkg_dir/tests/"
cp -r benchmarks/ "$pkg_dir/benchmarks/"
cp -r examples/ "$pkg_dir/examples/"
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ jobs:
- name: Build all
run: ./build.pas --prod

- name: Stage build artifacts
run: bash ./.github/scripts/stage-build-artifacts.sh build pr-artifacts --include-tests

- name: Upload build
uses: actions/upload-artifact@v5
with:
name: build-pr
retention-days: 1
path: |
build/ScriptLoader
build/TestRunner
build/BenchmarkRunner
build/REPL
build/Goccia.*.Test
build/Goccia.*.Test.exe
path: pr-artifacts/*

test:
needs: build
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ See [docs/build-system.md](docs/build-system.md) for build system details.
- Shared path config: `config.cfg`
- Shared directives: `units/Goccia.inc` (overflow/range checks conditional on `PRODUCTION` define)
- Output directory: `build/`
- CI: Two workflow files — `ci.yml` (main + tags, full matrix, all checks + release) and `pr.yml` (PRs, ubuntu-latest x64 only, JavaScript tests, Pascal unit tests, examples, and benchmark comparison comment). All matrix strategies use `fail-fast: false`. Post-build jobs (`test`, `benchmark`, `examples`) are independent. The `examples` jobs smoke-test stdin execution for `ScriptLoader`, and the `benchmark` jobs smoke-test stdin execution for `BenchmarkRunner`. Windows artifacts are labeled x86 (FPC produces i386-win32 binaries on the x64 runner).
- CI: Two workflow files — `ci.yml` (main + tags, full matrix, all checks + release) and `pr.yml` (PRs, ubuntu-latest x64 only, JavaScript tests, Pascal unit tests, examples, and benchmark comparison comment). All matrix strategies use `fail-fast: false`. Post-build jobs (`test`, `benchmark`, `examples`) are independent. The PR `build` job uploads a staged `build-pr` artifact containing binaries derived from the repo's top-level `*.dpr` entrypoints plus Pascal test executables. The `examples` jobs smoke-test stdin execution for `ScriptLoader`, and the `benchmark` jobs smoke-test stdin execution for `BenchmarkRunner`. Intermediate artifacts stage binaries derived from the repo's top-level `*.dpr` entrypoints; release archives bundle those shipped binaries plus `tests/`, `benchmarks/`, and `examples/`. Windows artifacts are labeled x86 (FPC produces i386-win32 binaries on the x64 runner).
- Auto-formatter: `./format.pas` (instantfpc script, no build step) — auto-fixes uses clause ordering, PascalCase function names, and parameter `A` prefix naming
- Pre-commit hook: [Lefthook](https://github.com/evilmartians/lefthook) (`lefthook.yml`) — requires `lefthook install` after cloning
- Editor setup: `.vscode/settings.json` (format-on-save) + `.vscode/extensions.json` (recommended extensions)
Expand Down
15 changes: 9 additions & 6 deletions docs/build-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,33 +250,36 @@ Runs on the full platform matrix:
| macOS Latest | x64, ARM64 |
| Windows Latest | x86 (i386-win32) |

**`build`** — Installs FPC, compiles all binaries with `--prod`, uploads them as intermediate artifacts.
**`build`** — Installs FPC, compiles the top-level `*.dpr` programs with `--prod`, stages those binaries plus Pascal test executables, and uploads that staged set as intermediate artifacts.

**`test`** (needs build) — Runs all JavaScript tests and Pascal unit tests on all platforms.

**`benchmark`** (needs build) — Runs all benchmarks on all platforms. On main (ubuntu-latest x64), saves benchmark results as JSON to `actions/cache` for PR comparison.

**`examples`** (needs build) — Runs all example scripts from the `examples/` folder on all platforms.

**`artifacts`** (needs test + benchmark + examples, main only) — Uploads production binaries after all checks pass.
**`artifacts`** (needs test + benchmark + examples, main only) — Uploads production binaries after all checks pass, deriving the executable names from the top-level `*.dpr` entrypoints.

**`release`** (needs test + benchmark + examples, tags only) — Downloads all platform build artifacts, bundles them with `tests/`, `benchmarks/`, and `examples/` into per-platform archives (`.tar.gz` for Linux/macOS, `.zip` for Windows), and creates a GitHub release using `softprops/action-gh-release`.
**`release`** (needs test + benchmark + examples, tags only) — Downloads all platform build artifacts, stages only the shipped binaries derived from the top-level `*.dpr` entrypoints, bundles them with `tests/`, `benchmarks/`, and `examples/` into per-platform archives (`.tar.gz` for Linux/macOS, `.zip` for Windows), and creates a GitHub release using `softprops/action-gh-release`.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

### `pr.yml` — Pull requests

```
build → test (JS only)
build → test (JS + native)
→ benchmark → PR comment (comparison)
→ examples
```

Runs on **ubuntu-latest x64 only** (single runner, no matrix).

**`build`** — Installs FPC, compiles all binaries with `--prod`.
**`build`** — Installs FPC, compiles all binaries with `--prod`, stages the top-level `*.dpr` binaries plus Pascal test executables, and uploads that staged set as `build-pr`.

**`test`** (needs build) — Runs all JavaScript tests. No native tests.
**`test`** (needs build) — Runs all JavaScript tests and Pascal unit tests.

**`benchmark`** (needs build) — Restores the cached benchmark baseline JSON from main, runs all benchmarks with JSON output, and posts a collapsible comparison comment on the PR grouped by file. Each file section shows the cached baseline and PR `opsPerSec` point estimates side by side, with each point estimate carrying its min/max ops/sec range in brackets. Classification uses range overlap: fully above the baseline range is an improvement, fully below is a regression, and overlapping ranges are treated as unchanged noise. Percentage deltas are still shown as secondary context, and files with significant changes are auto-expanded. If no baseline exists, shows results without comparison.

**`examples`** (needs build) — Runs all example scripts from the `examples/` folder.

FPC is only installed once per platform in the `build` job. Test, benchmark, and example jobs run in parallel, using pre-built binaries.

## Auto-Formatter
Expand Down
Loading