From 9004fc1440583d06a3ae2cc1e8bedf6915dbd391 Mon Sep 17 00:00:00 2001 From: Filippos Christou Date: Mon, 4 Mar 2024 17:22:20 +0100 Subject: [PATCH] Trivial change, test PR (#347) * Trivial change, test PR * Add PR write permission * Test full permissions * Granular permissions * try write-all * try label event * labeled in pull_request * Store results as artifact and trigger a consecutive workflow_run * Workflow chain almost complete (WIP) * correct .benchmarkci path * Add benchx support branch * Just try pull_request_target instead * Remove target * Get rid of s to get the chain going --------- Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> --- .github/workflows/postbench.yml | 61 +++++++++++++++++++ ...{benchmarkpr.yml => runbenchandupload.yml} | 44 ++++++++----- benchmark/benchmarks.jl | 3 +- 3 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/postbench.yml rename .github/workflows/{benchmarkpr.yml => runbenchandupload.yml} (66%) diff --git a/.github/workflows/postbench.yml b/.github/workflows/postbench.yml new file mode 100644 index 000000000..e0995c814 --- /dev/null +++ b/.github/workflows/postbench.yml @@ -0,0 +1,61 @@ +name: PostBenchmarks +on: + workflow_run: + workflows: [RunUploadBenchmarks] + types: [completed] + branches: [master, benchx] +jobs: + on-success: + runs-on: ubuntu-latest + # if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - run: echo 'The triggering workflow passed' + - name: 'Download artifact' + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "BenchmarkResults" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/BenchmarkResults.zip`, Buffer.from(download.data)); + + - name: 'Unzip artifact' + run: unzip BenchmarkResults.zip -d .benchmarkci/ + - name: 'Post results test 1' + run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: 'Comment on PR test 2' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + let fs = require('fs'); + let issue_number = Number(fs.readFileSync('./pr_number')); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: 'Thank you for the PR!' + }); + - name: 'Comment on PR test 3' + run: gh pr comment "$NUMBER" --body "$BODY" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NUMBER: ${{ github.event.pull_request.number }} + BODY: > + This pr comment is testing. + **This should be bold** diff --git a/.github/workflows/benchmarkpr.yml b/.github/workflows/runbenchandupload.yml similarity index 66% rename from .github/workflows/benchmarkpr.yml rename to .github/workflows/runbenchandupload.yml index 999093593..82e8d0318 100644 --- a/.github/workflows/benchmarkpr.yml +++ b/.github/workflows/runbenchandupload.yml @@ -1,21 +1,24 @@ -name: performance tracking +name: RunUploadBenchmarks env: JULIA_NUM_THREADS: 2 on: pull_request: + # types: [labeled] branches: - - master - - benchx + - master + - benchx push: branches: - - master - - benchx + - master + - benchx tags: '*' jobs: benchmark: + # if: ${{ github.event.label.name == 'to-benchmark' }} name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.allow_failure }} + permissions: write-all strategy: fail-fast: false matrix: @@ -52,14 +55,22 @@ jobs: run: julia -e " using BenchmarkCI, PkgBenchmark; jd=BenchmarkCI.judge(baseline=\"origin/${GITHUB_BASE_REF}\"); - writeresults(\"targetbenchout.json\", jd.target_results); - writeresults(\"baselinebenchout.json\", jd.baseline_results); " - - name: Post results if pull request - if: github.event_name == 'pull_request' - run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Post results if pull request + # if: github.event_name == 'pull_request' + # run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()' + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Add comment + # if: github.event_name == 'pull_request' + # run: gh pr comment "$NUMBER" --body "$BODY" + # env: + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # GH_REPO: ${{ github.repository }} + # NUMBER: ${{ github.event.pull_request.number }} + # BODY: > + # This pr comment is testing. + # **This should be bold** - name: Run benchmark if push/merge if: github.event_name == 'push' run: julia --project=benchmark -e " @@ -71,8 +82,13 @@ jobs: br_median = BenchmarkResults(br.name, br.commit, median(br.benchmarkgroup), br.date, br.julia_commit, br.vinfo, br.benchmarkconfig); writeresults(\"medianbenchout.json\", br_median); " + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > .benchmarkci/pr_number - uses: actions/upload-artifact@v3 with: - name: Store benchmark result - path: ./*benchout.json + name: BenchmarkResults + path: .benchmarkci/ diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index e9c220a24..932b78157 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -1,5 +1,4 @@ -using BenchmarkTools -using Graphs +using BenchmarkTools, Graphs const BENCHDIR = dirname(@__FILE__)