Skip to content

Add snapshot testing for AST pretty printing #2555

Add snapshot testing for AST pretty printing

Add snapshot testing for AST pretty printing #2555

Workflow file for this run

name: CI Build
on: [push, pull_request]
env:
CARGO_TEST_RESULT_NAME: cargo_test_results.json
CONFORMANCE_REPORT_NAME: cts_report.json
COMPARISON_REPORT_NAME: cts-comparison-report.md
jobs:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
steps:
- name: Remove MSys64 MingW64 Binaries
if: runner.os == 'Windows'
# remove this because there is a bad libclang.dll that confuses bindgen
run: Remove-Item -LiteralPath "C:\msys64\mingw64\bin" -Force -Recurse
- name: Install Dependencies
if: runner.os == 'Windows'
run: choco install llvm -y
- name: Git Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Rust Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy, rustfmt
- name: Cargo Build
run: cargo build --verbose --workspace
- name: Cargo Test excluding conformance tests
run: cargo test --verbose --workspace
- name: Rustfmt Check
if: matrix.os == 'ubuntu-20.04'
run: cargo fmt --verbose --all -- --check
- name: Run Clippy
if: matrix.os == 'ubuntu-20.04'
uses: actions-rs/clippy-check@v1
with:
# Adding comments to the PR requires the GITHUB_TOKEN secret.
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
# Cache the `cargo build` so future jobs can reuse build
- name: Cache cargo build
if: matrix.os == 'ubuntu-20.04'
uses: actions/cache@v3
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
# Run cargo-deny check and report.
# Fails if any of the following are found used in the crate or its dependencies.
# - any banned crates
# - disallowed open source licenses
# - use of disallowed repository sources
# Reports, but does not fail on:
# - security advisories
# See: https://embarkstudios.github.io/cargo-deny/index.html
cargo-deny:
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources
# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check ${{ matrix.checks }}
# Conformance report generation and comparison report generation job will run only after the `Build and Test` job
# succeeds.
conformance-report:
name: Create conformance report for `push` and `pull_request` events
runs-on: ubuntu-20.04
steps:
# Pull down the cached `partiql-lang-rust` build from the `Build and Test` job. This allows us to reuse without
# needing to rebuild. If pulling the build fails, the subsequent `cargo test` will rebuild.
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Rust Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-06-09
- uses: actions/cache@v3
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
# Run the conformance tests (i.e. `cargo test`) and save to a json file. This uses the "format" unstable compile
# option to save as json. In the future, may want to use the `cargo_metadata` crate (https://crates.io/crates/cargo_metadata)
# to format and use the output.
- name: Cargo Test of the conformance tests (can fail) and save to json file
continue-on-error: true
run: cargo test --verbose --package partiql-conformance-tests --features "conformance_test" --release -- -Z unstable-options --format json > ${{ env.CARGO_TEST_RESULT_NAME }}
# Create a conformance report from the `cargo test` json file
- run: cargo run --features report_tool --bin generate_cts_report ${{ env.CARGO_TEST_RESULT_NAME }} ${GITHUB_SHA} ${{ env.CONFORMANCE_REPORT_NAME }}
# Upload conformance report for comparison with future runs
- name: Upload conformance report
uses: actions/upload-artifact@v3
with:
path: ${{ env.CONFORMANCE_REPORT_NAME }}
# Cache the `cargo build` and conformance report for `conformance-report-comparison` job (pull_request event only)
- name: Cache `cargo build` and conformance report
if: github.event_name == 'pull_request'
uses: actions/cache@v3
id: restore-build-and-conformance
with:
path: ./*
key: ${{ github.sha }}-conformance-report
conformance-report-comparison:
name: Create comparison report for `pull_request` event
runs-on: ubuntu-20.04
needs: [conformance-report]
if: github.event_name == 'pull_request'
steps:
# Pull down cached `cargo build` and conformance report
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Rust Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-06-09
- uses: actions/cache@v3
id: restore-build-and-conformance
with:
path: ./*
key: ${{ github.sha }}-conformance-report
# Download conformance report from target branch to create comparison report. If target branch has no conformance
# report, pull down target branch and rebuild conformance report.
- name: Download conformance report from target branch
uses: dawidd6/action-download-artifact@v2
id: download-report
continue-on-error: true
with:
workflow: ci_build_test.yml
commit: ${{ github.event.pull_request.base.sha }}
# (If download of target branch report fails) Run the conformance tests (i.e. `cargo test`) and save to a JSON file.
- name: (If download of target branch conformance report fails) Checkout target branch
uses: actions/checkout@v3
if: ${{ steps.download-report.outcome == 'failure' }}
with:
submodules: recursive
path: ${{ github.event.pull_request.base.sha }}
ref: ${{ github.event.pull_request.base.sha }}
- name: (If download of target branch conformance report fails) Run conformance tests for target branch
if: ${{ steps.download-report.outcome == 'failure' }}
continue-on-error: true
run: |
cd ${{ github.event.pull_request.base.sha }}
cargo test --verbose --package partiql-conformance-tests --features "conformance_test" --release -- -Z unstable-options --format json > ${{ env.CARGO_TEST_RESULT_NAME }}
- name: (If download of target branch conformance report fails) Generate conformance test report for target branch
if: ${{ steps.download-report.outcome == 'failure' }}
continue-on-error: true
run: |
cd ${{ github.event.pull_request.base.sha }}
cargo run --features report_tool --bin generate_cts_report ${{ env.CARGO_TEST_RESULT_NAME }} ${GITHUB_SHA} ${{ env.CONFORMANCE_REPORT_NAME }}
- name: (If download of target branch conformance report fails) Move conformance test report of target branch to ./artifact directory
if: ${{ steps.download-report.outcome == 'failure' }}
continue-on-error: true
run: |
mkdir -p $GITHUB_WORKSPACE/artifact
cp -r $GITHUB_WORKSPACE/${{ github.event.pull_request.base.sha }}/$CONFORMANCE_REPORT_NAME $GITHUB_WORKSPACE/artifact/$CONFORMANCE_REPORT_NAME
# Run conformance report comparison. Generates comparison report
- run: cargo run --features report_tool --bin generate_comparison_report ./artifact/${{ env.CONFORMANCE_REPORT_NAME }} ${{ env.CONFORMANCE_REPORT_NAME }} ${{ env.COMPARISON_REPORT_NAME }}
# Print conformance report to GitHub actions workflow summary page
- name: print markdown in run
run: cat ${{ env.COMPARISON_REPORT_NAME }} >> $GITHUB_STEP_SUMMARY
# Find comment w/ conformance comparison if previous comment published
- name: Find Comment
uses: peter-evans/find-comment@v2
continue-on-error: true
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Conformance
# Create or update (if previous comment exists) with markdown version of comparison report
- name: Create or update comment
continue-on-error: true
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-file: ${{ env.COMPARISON_REPORT_NAME }}
edit-mode: replace