From 9597ce90b5f69157b4dbb39520f4f4ee94d95081 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 16 Dec 2024 23:13:01 +0000 Subject: [PATCH] chore(ci): print protocol circuits gate counts --- .github/scripts/merge-gates-reports.sh | 21 +++++++ .../scripts/single_artifact_gates_report.sh | 12 ++++ .github/workflows/reports.yml | 60 ++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/merge-gates-reports.sh create mode 100755 .github/scripts/single_artifact_gates_report.sh diff --git a/.github/scripts/merge-gates-reports.sh b/.github/scripts/merge-gates-reports.sh new file mode 100755 index 00000000000..11b5ad3f4e5 --- /dev/null +++ b/.github/scripts/merge-gates-reports.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -eu + +REPORT_NAME=$1 +NAME_PLURAL=""$REPORT_NAME"s" + +combined_reports='{"programs": []}' + +# Iterate over each report and merge them +for report in ./reports/*; do + # The report is saved under ./$REPORT_NAME_{ matrix_report }/$REPORT_NAME_{ matrix_report }.json + FILE_PATH=$(echo $(ls $report)) + + # Extract the $NAME_PLURAL array from each report and merge it + combined_reports=$(jq --argjson COMBINED_REPORTS "$combined_reports" '.programs += $COMBINED_REPORTS.programs' <<< "$(cat "$report/$FILE_PATH")") +done + +# Wrap the merged memory reports into a new object as to keep the $NAME_PLURAL key + +echo "$combined_reports" + diff --git a/.github/scripts/single_artifact_gates_report.sh b/.github/scripts/single_artifact_gates_report.sh new file mode 100755 index 00000000000..50308a78717 --- /dev/null +++ b/.github/scripts/single_artifact_gates_report.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +BACKEND=${BACKEND:-bb} + +ARTIFACT_PATH=$1 +ARTIFACT_NAME=$(basename "$ARTIFACT_PATH") + +GATES_INFO=$($BACKEND gates -b $ARTIFACT_PATH) +MAIN_FUNCTION_INFO=$(echo $GATES_INFO | jq -r '.functions[0] | .name = "main"') +echo "{\"programs\": [ {\"package_name\": \"$ARTIFACT_NAME\", \"functions\": [$MAIN_FUNCTION_INFO]} ]}" + diff --git a/.github/workflows/reports.yml b/.github/workflows/reports.yml index 0a03add8338..95e6620ac97 100644 --- a/.github/workflows/reports.yml +++ b/.github/workflows/reports.yml @@ -300,6 +300,7 @@ jobs: with: path: scripts sparse-checkout: | + .github/scripts/single_artifact_gates_report.sh test_programs/compilation_report.sh sparse-checkout-cone-mode: false @@ -314,7 +315,6 @@ jobs: working-directory: ./test-repo/${{ matrix.project.path }} run: | mv /home/runner/work/noir/noir/scripts/test_programs/compilation_report.sh ./compilation_report.sh - chmod +x ./compilation_report.sh ./compilation_report.sh 1 - name: Move compilation report @@ -334,6 +334,26 @@ jobs: retention-days: 3 overwrite: true + # While we've got the compiled artifacts, we measure the number of gates in the circuits. + + - name: Generate gates report + working-directory: ./test-repo/${{ matrix.project.path }} + run: | + PACKAGE_NAME=${{ matrix.project.path }} + PACKAGE_NAME=$(basename $PACKAGE_NAME) + mv /home/runner/work/noir/noir/.github/scripts/single_artifact_gates_report.sh ./single_artifact_gates_report.sh + ./single_artifact_gates_report.sh ./temp/target/* > gates_report_$PACKAGE_NAME.json + echo "gates_report_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT + + + - name: Upload gates report + uses: actions/upload-artifact@v4 + with: + name: gates_report_${{ steps.report.outputs.gates_report_name }} + path: gates_report_${{ steps.report.outputs.gates_report_name }}.json + retention-days: 3 + overwrite: true + upload_compilation_report: name: Upload compilation report needs: [generate_compilation_report, external_repo_compilation_report] @@ -378,6 +398,43 @@ jobs: header: compilation message: ${{ steps.compilation_report.outputs.markdown }} + upload_gates_report: + name: Upload gates report + needs: [external_repo_compilation_report] + # We want this job to run even if one variation of the matrix in `external_repo_compilation_report` fails + if: always() + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - uses: actions/checkout@v4 + + - name: Download matrix gates reports + uses: actions/download-artifact@v4 + with: + pattern: gates_report_* + path: ./reports + + - name: Merge gates reports using jq + run: | + mv ./.github/scripts/merge-gates-reports.sh merge-gates-reports.sh + ./merge-gates-reports.sh > protocol_circuits_gates_report.json + + - name: Compare gates reports + id: gates_diff + uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87 + with: + report: protocol_circuits_gates_report.json + summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%) + + - name: Add memory report to sticky comment + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: protocol_gates + message: ${{ steps.gates_diff.outputs.markdown }} + external_repo_memory_report: needs: [build-nargo] runs-on: ubuntu-latest @@ -427,7 +484,6 @@ jobs: working-directory: ./test-repo/${{ matrix.project.path }} run: | mv /home/runner/work/noir/noir/scripts/test_programs/memory_report.sh ./memory_report.sh - chmod +x ./memory_report.sh ./memory_report.sh 1 - name: Move compilation report