Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Benchmarking and site | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: # This allows manual triggering | |
jobs: | |
benchmark: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
- name: Clean previous docs folder | |
run: | | |
rm -rf docs/src/hyperfine.md | |
rm -rf docs/src/criterion.md | |
rm -rf docs/src/criterion_reports | |
# Set up Rust environment | |
- name: Set up Rust | |
uses: dtolnay/rust-toolchain@stable | |
# Install dependencies (gnuplot required for Criterion) | |
- name: Install hyperfine and gnuplot | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y hyperfine gnuplot | |
# Build the Rust project (for Hyperfine and Criterion) | |
- name: Build Release | |
run: cargo build --release | |
# Hyperfine Benchmark | |
- name: Run hyperfine benchmark | |
run: | | |
mkdir -p docs/src | |
echo "| File | Line num | Mean [ms] | Min [ms] | Max [ms] |" > docs/src/hyperfine.md | |
echo "|------|----------|-----------|----------|----------|" >> docs/src/hyperfine.md | |
for file in $(ls -S samples); do | |
file_name=$(basename "$file" .cls) | |
file_path="samples/$file" | |
line_count=$(wc -l < "$file_path") | |
file_url="https://github.com/${{ github.repository }}/blob/main/samples/$file" | |
file_link="[$file_name]($file_url)" | |
hyperfine --runs 100 --warmup 5 -i "./target/release/afmt -f $file_path" --export-markdown temp_results.md | |
mean=$(grep -oP '(?<=\| )[0-9.]+(?= ±)' temp_results.md | head -1) | |
min=$(grep -oP '(?<=\| )[0-9.]+(?= )' temp_results.md | head -2 | tail -1) | |
max=$(grep -oP '(?<=\| )[0-9.]+(?= )' temp_results.md | head -3 | tail -1) | |
if [ -n "$mean" ]; then | |
echo "| $file_link | $line_count | $mean | $min | $max |" >> docs/src/hyperfine.md | |
else | |
echo "| $file_link | $line_count | N/A | N/A | N/A |" >> docs/src/hyperfine.md | |
fi | |
done | |
# Criterion Benchmark | |
- name: Run Criterion benchmark | |
run: | | |
mkdir -p docs/src/ | |
cargo bench --bench afmt_benchmark | |
cp -r target/criterion ./docs/src/ | |
# Create Criterion results in mdBook using iframe | |
- name: Generate Criterion report | |
run: | | |
mkdir -p docs/src | |
echo "# Criterion Benchmark Result" > docs/src/criterion.md | |
echo '<iframe src="criterion/report/index.html" width="100%" height="600px" frameborder="0"></iframe>' >> docs/src/criterion.md | |
# Install and run mdBook | |
- name: Install mdBook | |
run: cargo install mdbook | |
- name: Build mdBook | |
run: | | |
cd docs | |
mdbook build | |
# Upload artifacts for GitHub Pages | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./docs/book | |
# Commit and push changes | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add docs | |
git commit -m "Update benchmark results and build mdBook" || echo "No changes to commit" | |
git push origin HEAD:main | |
deploy: | |
needs: benchmark | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |