summaryrefslogtreecommitdiff
path: root/.github/workflows/benchmark.yml
blob: 74b88e65d7dd242f18e7f1d5398c2080020d5c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Benchmark

on:
  pull_request:
    branches: [master]
  push:
    branches: [master]
  workflow_dispatch:

# Cancel in-flight benchmark runs for the same PR/branch so only the latest commit is benchmarked.
concurrency:
  group: benchmark-${{ github.ref }}
  cancel-in-progress: true

jobs:
  benchmark:
    name: Run CIBenchmark
    if: github.repository == 'atlarge-research/opendc'
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - uses: actions/checkout@v4

      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          java-version: "21"
          distribution: temurin

      - name: Set up Gradle
        uses: gradle/actions/setup-gradle@v4

      - name: Run CIBenchmark
        run: >
          ./gradlew :opendc-experiments:opendc-experiments-base:jmh
          -PjmhIncludes=.*CIBenchmark.*

      - name: Upload benchmark results
        uses: actions/upload-artifact@v4
        with:
          name: benchmark-results
          path: opendc-experiments/opendc-experiments-base/build/results/jmh/results.json
          retention-days: 7

      # Store the PR number so the comment workflow (which runs with write permissions)
      # knows which PR to comment on. Only needed for pull_request runs.
      - name: Save PR number
        if: github.event_name == 'pull_request'
        run: echo "${{ github.event.pull_request.number }}" > pr-number.txt

      - name: Upload PR number
        if: github.event_name == 'pull_request'
        uses: actions/upload-artifact@v4
        with:
          name: pr-number
          path: pr-number.txt
          retention-days: 1

  # ── Master push: store results in the benchmark-data GitHub Release ───────────
  store-results:
    name: Store benchmark results
    if: github.event_name == 'push' && github.repository == 'atlarge-research/opendc'
    needs: benchmark
    runs-on: ubuntu-latest

    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

      - name: Download current results
        uses: actions/download-artifact@v4
        with:
          name: benchmark-results
          path: current-results

      - name: Download existing benchmark history
        run: |
          gh release download benchmark-data \
            --repo atlarge-research/opendc \
            -A benchmark-history.json \
            -O existing-history.json 2>/dev/null \
            || echo "[]" > existing-history.json
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Update history
        run: |
          python3 .github/scripts/update_history.py \
            current-results/results.json \
            existing-history.json \
            updated-history.json \
            "${{ github.sha }}"

      - name: Upload to release
        run: |
          gh release upload benchmark-data updated-history.json#benchmark-history.json \
            --repo atlarge-research/opendc \
            --clobber 2>/dev/null \
            || gh release create benchmark-data \
              --repo atlarge-research/opendc \
              --title "Benchmark Data" \
              --notes "Permanent storage for benchmark history. Managed automatically by CI." \
              updated-history.json#benchmark-history.json
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}