Skip to content

release: promote adze-swarm state #2027

release: promote adze-swarm state

release: promote adze-swarm state #2027

Workflow file for this run

name: Golden-Master Tests
# Routed by grammar/golden risk pack: PR runs only when grammar surfaces are
# touched, or when 'ci:golden' / 'full-ci' is set. See
# docs/ci/adze-rollout-plan.md (PR 12) and policy/ci-risk-packs.toml.
#
# Note: a workflow-level `paths:` filter would be evaluated by GitHub *before*
# the job-level `if:`, so a PR labeled `ci:golden` outside the listed paths
# would never start the workflow at all. Path detection therefore lives in a
# `paths` setup job and is consumed by the matrix job's `if:`.
on:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action == 'synchronize' }}
jobs:
paths:
name: Detect Grammar Paths
if: |
github.event_name != 'pull_request' ||
github.event.action != 'labeled' ||
github.event.label.name == 'ci:golden' ||
github.event.label.name == 'full-ci' ||
github.event.label.name == 'skip-golden'
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
grammar_changed: ${{ steps.detect.outputs.grammar_changed }}
steps:
- uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- id: detect
run: |
set -euo pipefail
if [ "${{ github.event_name }}" != "pull_request" ]; then
echo "grammar_changed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
changed=$(git diff --name-only "$BASE_SHA...$HEAD_SHA" || true)
if echo "$changed" | grep -qE '^(golden-tests/|grammars/|corpus/|glr-core/|tablegen/|runtime/|runtime2/|\.github/workflows/golden-tests\.yml$)'; then
echo "grammar_changed=true" >> "$GITHUB_OUTPUT"
else
echo "grammar_changed=false" >> "$GITHUB_OUTPUT"
fi
golden-tests:
name: Golden Tests - ${{ matrix.language }}
needs: paths
if: |
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'ci:golden') ||
contains(github.event.pull_request.labels.*.name, 'full-ci') ||
(
needs.paths.outputs.grammar_changed == 'true' &&
!contains(github.event.pull_request.labels.*.name, 'skip-golden')
)
runs-on: ubuntu-latest
strategy:
matrix:
language: [python, javascript]
steps:
- uses: actions/checkout@v6.0.2
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Check whether references already exist
id: refs
run: |
ref_dir="golden-tests/${{ matrix.language }}/expected"
if [ -d "$ref_dir" ] && [ -n "$(ls -A "$ref_dir" 2>/dev/null)" ]; then
echo "missing=false" >> "$GITHUB_OUTPUT"
echo "References already present for ${{ matrix.language }}"
else
echo "missing=true" >> "$GITHUB_OUTPUT"
echo "References missing for ${{ matrix.language }}"
fi
- name: Install Node.js
if: steps.refs.outputs.missing == 'true'
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Tree-sitter CLI
if: steps.refs.outputs.missing == 'true'
run: npm install -g tree-sitter-cli
- name: Clone and prepare Tree-sitter grammar
if: steps.refs.outputs.missing == 'true'
run: |
cd /tmp
if [ "${{ matrix.language }}" = "python" ]; then
git clone --depth 1 https://github.com/tree-sitter/tree-sitter-python
cd tree-sitter-python
else
git clone --depth 1 https://github.com/tree-sitter/tree-sitter-javascript
cd tree-sitter-javascript
fi
tree-sitter generate
tree-sitter build
- name: Generate reference files if missing
if: steps.refs.outputs.missing == 'true'
run: |
cd golden-tests
if [ ! -d "${{ matrix.language }}/expected" ] || [ -z "$(ls -A ${{ matrix.language }}/expected)" ]; then
echo "Generating reference files for ${{ matrix.language }}..."
grammar_dir="/tmp/tree-sitter-${{ matrix.language }}"
TREE_SITTER_GRAMMAR_DIR="$grammar_dir" ./generate_references.sh "${{ matrix.language }}"
fi
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Run golden tests
run: |
cd golden-tests
cargo test --features ${{ matrix.language }}-grammar -- --nocapture
env:
RUST_BACKTRACE: 1
- name: Upload test artifacts on failure
if: failure()
uses: actions/upload-artifact@v7.0.0
with:
name: golden-test-failures-${{ matrix.language }}
path: |
golden-tests/${{ matrix.language }}/expected/*.actual.sexp
golden-tests/${{ matrix.language }}/expected/*.sexp
golden-tests/${{ matrix.language }}/expected/*.sha256