diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d9ee50f..3afdb303 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,11 +76,6 @@ jobs: benchmark: runs-on: ubuntu-latest needs: build - permissions: - # To allow writing comments to the PR in forked repositorites. - # See https://github.com/thollander/actions-comment-pull-request/issues/181 - pull-requests: write - env: PROJECT_DIR: . steps: @@ -93,16 +88,13 @@ jobs: ref: main path: _canbench_main_branch - - name: Cache Cargo - uses: actions/cache@v2 + - uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target - key: ${{ matrix.build }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ matrix.build }}-cargo- + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-1 - name: Install Rust run: | @@ -112,17 +104,25 @@ jobs: - name: Benchmark run: | - bash .github/workflows/canbench_ci_run_benchmark.sh $PROJECT_DIR + bash ./scripts/ci_run_benchmark.sh $PROJECT_DIR ${{ github.job }} + + - uses: actions/upload-artifact@v4 + with: + name: canbench_result_${{github.job}} + path: /tmp/canbench_result_${{ github.job }} + + - name: Save PR number + run: | + echo ${{ github.event.number }} > /tmp/pr_number - - name: Post comment - uses: thollander/actions-comment-pull-request@v2 + - uses: actions/upload-artifact@v4 with: - filePath: /tmp/canbench_comment_message.txt - comment_tag: ${{ env.PROJECT_DIR }} + name: pr_number + path: /tmp/pr_number - name: Pass or fail run: | - bash .github/workflows/canbench_ci_post_run_benchmark.sh + bash ./scripts/ci_post_run_benchmark.sh checks-pass: # Always run this job! diff --git a/.github/workflows/canbench_ci_download_artifacts.sh b/scripts/ci_download_canbench_artifacts.sh similarity index 99% rename from .github/workflows/canbench_ci_download_artifacts.sh rename to scripts/ci_download_canbench_artifacts.sh index 515f261d..6b5d2b46 100644 --- a/.github/workflows/canbench_ci_download_artifacts.sh +++ b/scripts/ci_download_canbench_artifacts.sh @@ -27,4 +27,3 @@ json_array+="]" # Output the benchmarks and PR number to be used by the next job. echo "matrix={\"benchmark\": $json_array}" >> "$GITHUB_OUTPUT" echo "pr_number=$(cat ./pr_number/pr_number)" >> "$GITHUB_OUTPUT" - diff --git a/.github/workflows/canbench_ci_post_run_benchmark.sh b/scripts/ci_post_run_benchmark.sh similarity index 100% rename from .github/workflows/canbench_ci_post_run_benchmark.sh rename to scripts/ci_post_run_benchmark.sh diff --git a/.github/workflows/canbench_ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh similarity index 75% rename from .github/workflows/canbench_ci_run_benchmark.sh rename to scripts/ci_run_benchmark.sh index a3dca99c..94cb5d13 100644 --- a/.github/workflows/canbench_ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -7,8 +7,11 @@ set -Eexuo pipefail # Path to run `canbench` from. CANISTER_PATH=$1 +# The name of the job in CI +CANBENCH_JOB_NAME=$2 + # Must match the file specified in the github action. -COMMENT_MESSAGE_PATH=/tmp/canbench_comment_message.txt +COMMENT_MESSAGE_PATH=/tmp/canbench_result_${CANBENCH_JOB_NAME} # Github CI is expected to have the main branch checked out in this folder. MAIN_BRANCH_DIR=_canbench_main_branch @@ -45,7 +48,7 @@ fi popd -echo "# \`canbench\` 🏋" > $COMMENT_MESSAGE_PATH +echo "# \`canbench\` 🏋 (dir: $CANISTER_PATH)" > "$COMMENT_MESSAGE_PATH" # Detect if there are performance changes relative to the main branch. if [ -f "$MAIN_BRANCH_RESULTS_FILE" ]; then @@ -54,23 +57,15 @@ if [ -f "$MAIN_BRANCH_RESULTS_FILE" ]; then # Run canbench to compare result to main branch. pushd "$CANISTER_PATH" - set +e - canbench --less-verbose > $CANBENCH_OUTPUT - RES=$? - set -e + canbench --less-verbose > "$CANBENCH_OUTPUT" popd - if [ "$RES" -eq 0 ]; then - if grep -q "(regress\|(improved by" "${CANBENCH_OUTPUT}"; then - echo "**Significant performance change detected! ⚠️** - " >> $COMMENT_MESSAGE_PATH; - else - echo "**No significant performance changes detected ✅** - " >> $COMMENT_MESSAGE_PATH - fi + if grep -q "(regress\|(improved by" "${CANBENCH_OUTPUT}"; then + echo "**Significant performance change detected! ⚠️** + " >> "$COMMENT_MESSAGE_PATH" else - echo "Failed to run \`canbench\` against main branch ⚠️ - " >> $COMMENT_MESSAGE_PATH + echo "**No significant performance changes detected ✅** + " >> "$COMMENT_MESSAGE_PATH" fi fi @@ -81,7 +76,7 @@ fi echo "\`\`\`" cat "$CANBENCH_OUTPUT" echo "\`\`\`" -} >> $COMMENT_MESSAGE_PATH +} >> "$COMMENT_MESSAGE_PATH" # Output the comment to stdout. -cat $COMMENT_MESSAGE_PATH +cat "$COMMENT_MESSAGE_PATH"