|
4 | 4 | pull_request: |
5 | 5 |
|
6 | 6 | jobs: |
7 | | - benchmarks: |
| 7 | + benchmark-base: |
8 | 8 | runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + results: ${{ steps.benchmark.outputs.results }} |
| 11 | + sha: ${{ steps.benchmark.outputs.sha }} |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v5 |
| 14 | + with: |
| 15 | + ref: ${{ github.base_ref }} |
| 16 | + - uses: julia-actions/setup-julia@v2 |
| 17 | + with: |
| 18 | + version: '1.11' |
| 19 | + - uses: julia-actions/cache@v2 |
| 20 | + |
| 21 | + - name: Run benchmarks |
| 22 | + id: benchmark |
| 23 | + working-directory: ./benchmarks |
| 24 | + run: | |
| 25 | + # github output can't handle more than 1 line, hence the tail |
| 26 | + julia --project=. -e 'using Pkg; Pkg.instantiate()' |
| 27 | + results=$(julia --project=. benchmarks.jl json | tail -n 1 || true) |
| 28 | + echo $results |
| 29 | + echo "results=$results" >> "$GITHUB_OUTPUT" |
| 30 | + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
9 | 31 |
|
| 32 | + benchmark-head: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + results: ${{ steps.benchmark.outputs.results }} |
| 36 | + sha: ${{ steps.benchmark.outputs.sha }} |
10 | 37 | steps: |
11 | | - - name: Checkout Repository |
12 | | - uses: actions/checkout@v5 |
| 38 | + - uses: actions/checkout@v5 |
13 | 39 | with: |
14 | 40 | ref: ${{ github.event.pull_request.head.sha }} |
15 | | - |
16 | | - - name: Set up Julia |
17 | | - uses: julia-actions/setup-julia@v2 |
| 41 | + - uses: julia-actions/setup-julia@v2 |
18 | 42 | with: |
19 | 43 | version: '1.11' |
20 | | - |
21 | 44 | - uses: julia-actions/cache@v2 |
22 | 45 |
|
23 | | - - name: Install Dependencies |
24 | | - run: julia --project=benchmarks/ -e 'using Pkg; Pkg.instantiate()' |
| 46 | + - name: Run benchmarks |
| 47 | + id: benchmark |
| 48 | + working-directory: ./benchmarks |
| 49 | + run: | |
| 50 | + # github output can't handle more than 1 line, hence the tail |
| 51 | + julia --project=. -e 'using Pkg; Pkg.instantiate()' |
| 52 | + results=$(julia --project=. benchmarks.jl json | tail -n 1 || true) |
| 53 | + echo $results |
| 54 | + echo "results=$results" >> "$GITHUB_OUTPUT" |
| 55 | + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
25 | 56 |
|
26 | | - - name: Run Benchmarks |
27 | | - id: run_benchmarks |
| 57 | + combine-results: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: [benchmark-base, benchmark-head] |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v5 |
| 62 | + with: |
| 63 | + ref: ${{ github.event.pull_request.head.sha }} |
| 64 | + - uses: julia-actions/setup-julia@v2 |
| 65 | + with: |
| 66 | + version: '1.11' |
| 67 | + - uses: julia-actions/cache@v2 |
| 68 | + |
| 69 | + - name: Combine benchmark results |
| 70 | + working-directory: ./benchmarks |
28 | 71 | run: | |
29 | | - # Capture version info into a variable, print it, and set it as an env var for later steps |
30 | 72 | version_info=$(julia -e 'using InteractiveUtils; versioninfo()') |
31 | 73 | echo "$version_info" |
32 | 74 | echo "VERSION_INFO<<EOF" >> $GITHUB_ENV |
33 | 75 | echo "$version_info" >> $GITHUB_ENV |
34 | 76 | echo "EOF" >> $GITHUB_ENV |
35 | 77 |
|
36 | | - # Capture benchmark output into a variable. The sed and tail calls cut out anything but the |
37 | | - # final block of results. |
38 | | - echo "Running Benchmarks..." |
39 | | - benchmark_output=$(\ |
40 | | - julia --project=benchmarks benchmarks/benchmarks.jl \ |
41 | | - | sed -n '/Final results:/,$p' \ |
42 | | - | tail -n +2\ |
43 | | - ) |
| 78 | + # save outputs of previous jobs to json file |
| 79 | + echo "Base results" |
| 80 | + echo "--------------------------------------------------------" |
| 81 | + echo '${{needs.benchmark-base.outputs.results}}' |
| 82 | + echo '${{needs.benchmark-base.outputs.results}}' > base.json |
| 83 | + echo "Head results" |
| 84 | + echo "--------------------------------------------------------" |
| 85 | + echo '${{needs.benchmark-head.outputs.results}}' |
| 86 | + echo '${{needs.benchmark-head.outputs.results}}' > head.json |
44 | 87 |
|
45 | | - # Print benchmark results directly to the workflow log |
46 | | - echo "Benchmark Results:" |
47 | | - echo "$benchmark_output" |
| 88 | + # combine them and save the output as an env var for later steps |
| 89 | + julia --project=. -e 'using Pkg; Pkg.instantiate()' |
| 90 | + results=$(julia --project=. benchmarks.jl combine head.json base.json) |
| 91 | + echo "Combined results" |
| 92 | + echo "--------------------------------------------------------" |
| 93 | + echo "$results" |
48 | 94 |
|
49 | | - # Set the benchmark output as an env var for later steps |
50 | 95 | echo "BENCHMARK_OUTPUT<<EOF" >> $GITHUB_ENV |
51 | | - echo "$benchmark_output" >> $GITHUB_ENV |
| 96 | + echo "$results" >> $GITHUB_ENV |
52 | 97 | echo "EOF" >> $GITHUB_ENV |
53 | 98 |
|
54 | | - # Get the current commit SHA of DynamicPPL |
55 | | - DPPL_COMMIT_SHA=$(git rev-parse HEAD) |
56 | | - echo "DPPL_COMMIT_SHA=$DPPL_COMMIT_SHA" >> $GITHUB_ENV |
57 | | -
|
58 | | - COMMIT_URL="https://github.com/${{ github.repository }}/commit/$DPPL_COMMIT_SHA" |
59 | | - echo "DPPL_COMMIT_URL=$COMMIT_URL" >> $GITHUB_ENV |
60 | | -
|
61 | | - - name: Find Existing Comment |
| 99 | + - name: Find existing benchmark comment |
62 | 100 | uses: peter-evans/find-comment@v4 |
63 | 101 | id: find_comment |
64 | 102 | with: |
65 | 103 | issue-number: ${{ github.event.pull_request.number }} |
66 | 104 | comment-author: github-actions[bot] |
67 | 105 |
|
68 | | - - name: Post Benchmark Results as PR Comment |
| 106 | + - name: Create or update benchmark comment |
69 | 107 | uses: peter-evans/create-or-update-comment@v5 |
70 | 108 | with: |
71 | 109 | issue-number: ${{ github.event.pull_request.number }} |
72 | 110 | body: | |
73 | | - ## Benchmark Report for Commit ${{ env.DPPL_COMMIT_SHA }} |
| 111 | + ## Benchmark Report |
| 112 | +
|
| 113 | + - this PR's head: `${{ needs.benchmark-head.outputs.sha }}` |
| 114 | + - base branch: `${{ needs.benchmark-base.outputs.sha }}` |
| 115 | +
|
74 | 116 | ### Computer Information |
75 | 117 | ``` |
76 | 118 | ${{ env.VERSION_INFO }} |
77 | 119 | ``` |
78 | 120 | ### Benchmark Results |
79 | | - ``` |
| 121 | +
|
80 | 122 | ${{ env.BENCHMARK_OUTPUT }} |
81 | | - ``` |
| 123 | +
|
82 | 124 | comment-id: ${{ steps.find_comment.outputs.comment-id }} |
83 | 125 | edit-mode: replace |
0 commit comments