From a2d031fa4807391948518d6bec8b51e6d4ee25e1 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 11 Dec 2024 09:35:20 -0500 Subject: [PATCH] chore(ci): Handle external libraries in compilation timing report (#6750) Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- .github/workflows/reports.yml | 126 +++++++++++++++++++++++++++- test_programs/compilation_report.sh | 18 +++- 2 files changed, 139 insertions(+), 5 deletions(-) diff --git a/.github/workflows/reports.yml b/.github/workflows/reports.yml index 24a0ce8951..c84b32dbd8 100644 --- a/.github/workflows/reports.yml +++ b/.github/workflows/reports.yml @@ -38,7 +38,6 @@ jobs: path: ./dist/* retention-days: 3 - compare_gates_reports: name: Circuit sizes needs: [build-nargo] @@ -262,8 +261,133 @@ jobs: working-directory: ./test_programs run: | ./compilation_report.sh + cat compilation_report.json mv compilation_report.json ../compilation_report.json + - name: Upload compilation report + uses: actions/upload-artifact@v4 + with: + name: in_progress_compilation_report + path: compilation_report.json + retention-days: 3 + overwrite: true + + external_repo_compilation_report: + needs: [build-nargo] + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + include: + - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts } + - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/parity-root } + - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner } + - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset } + # TODO: Bring these back once they no longer time out + #- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-private } + #- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-public } + + name: External repo compilation report - ${{ matrix.project.repo }}/${{ matrix.project.path }} + steps: + - name: Download nargo binary + uses: actions/download-artifact@v4 + with: + name: nargo + path: ./nargo + + - name: Set nargo on PATH + run: | + nargo_binary="${{ github.workspace }}/nargo/nargo" + chmod +x $nargo_binary + echo "$(dirname $nargo_binary)" >> $GITHUB_PATH + export PATH="$PATH:$(dirname $nargo_binary)" + nargo -V + + - uses: actions/checkout@v4 + with: + path: scripts + sparse-checkout: | + test_programs/compilation_report.sh + sparse-checkout-cone-mode: false + + - name: Checkout + uses: actions/checkout@v4 + with: + repository: ${{ matrix.project.repo }} + path: test-repo + ref: ${{ matrix.project.ref }} + + - name: Generate compilation report + 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 + id: report + shell: bash + run: | + PACKAGE_NAME=${{ matrix.project.path }} + PACKAGE_NAME=$(basename $PACKAGE_NAME) + mv ./test-repo/${{ matrix.project.path }}/compilation_report.json ./compilation_report_$PACKAGE_NAME.json + echo "compilation_report_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT + + - name: Upload compilation report + uses: actions/upload-artifact@v4 + with: + name: compilation_report_${{ steps.report.outputs.compilation_report_name }} + path: compilation_report_${{ steps.report.outputs.compilation_report_name }}.json + retention-days: 3 + overwrite: true + + upload_compilation_report: + name: Upload compilation report + needs: [generate_compilation_report, 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 initial compilation report + uses: actions/download-artifact@v4 + with: + name: in_progress_compilation_report + + - name: Download matrix compilation reports + uses: actions/download-artifact@v4 + with: + pattern: compilation_report_* + path: ./reports + + - name: Merge compilation reports using jq + run: | + echo "Merging reports" + + combined_reports="[]" + + # Iterate over each report and merge them + for report in ./reports/*; do + # The report is saved under ./compilation_report_{ matrix_report }/compilation_report_{ matrix_report }.json + REPORT_NAME=$(echo $(ls $report)) + # Extract the 'compilation_reports' array from each report and merge it + combined_reports=$(jq '[.compilation_reports[]] + '"$combined_reports" <<< "$(cat "$report/$REPORT_NAME")") + done + + combined_reports=$(jq '[.compilation_reports[]] + '"$combined_reports" <<< "$(cat ./compilation_report.json)") + + # Wrap the merged compilation reports into a new object as to keep the 'compilation_reports' key + final_report="{\"compilation_reports\": $combined_reports}" + + echo "$final_report" > compilation_report.json + + cat compilation_report.json + - name: Parse compilation report id: compilation_report uses: noir-lang/noir-bench-report@0d7464a8c39170523932d7846b6e6b458a294aea diff --git a/test_programs/compilation_report.sh b/test_programs/compilation_report.sh index 08cee7ba4a..13e74f0d7d 100755 --- a/test_programs/compilation_report.sh +++ b/test_programs/compilation_report.sh @@ -3,12 +3,18 @@ set -e current_dir=$(pwd) base_path="$current_dir/execution_success" -test_dirs=$(ls $base_path) # Tests to be profiled for compilation report tests_to_profile=("sha256_regression" "regression_4709" "ram_blowup_regression") + echo "{\"compilation_reports\": [ " > $current_dir/compilation_report.json +# If there is an argument that means we want to generate a report for only the current directory +if [ "$#" -ne 0 ]; then + base_path="$current_dir" + tests_to_profile=(".") +fi + ITER="1" NUM_ARTIFACTS=${#tests_to_profile[@]} @@ -23,9 +29,14 @@ for dir in ${tests_to_profile[@]}; do cd $base_path/$dir - COMPILE_TIME=$((time nargo compile --force) 2>&1 | grep real | grep -oE '[0-9]+m[0-9]+.[0-9]+s') - echo -e " {\n \"artifact_name\":\"$dir\",\n \"time\":\"$COMPILE_TIME\"\n" >> $current_dir/compilation_report.json + PACKAGE_NAME=$dir + if [ "$#" -ne 0 ]; then + PACKAGE_NAME=$(basename $current_dir) + fi + COMPILE_TIME=$((time nargo compile --force --silence-warnings) 2>&1 | grep real | grep -oE '[0-9]+m[0-9]+.[0-9]+s') + echo -e " {\n \"artifact_name\":\"$PACKAGE_NAME\",\n \"time\":\"$COMPILE_TIME\"" >> $current_dir/compilation_report.json + if (($ITER == $NUM_ARTIFACTS)); then echo "}" >> $current_dir/compilation_report.json else @@ -36,4 +47,3 @@ for dir in ${tests_to_profile[@]}; do done echo "]}" >> $current_dir/compilation_report.json -