diff --git a/.github/workflows/bencher-archive-closed.yml b/.github/workflows/bencher-archive-closed.yml index 6c1122d3..068ef469 100644 --- a/.github/workflows/bencher-archive-closed.yml +++ b/.github/workflows/bencher-archive-closed.yml @@ -1,17 +1,15 @@ on: - pull_request: + pull_request_target: types: [closed] jobs: - archive_pr_branch: - name: Archive closed PR branch with Bencher - # DO NOT REMOVE: For handling Fork PRs see Pull Requests from Forks - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + archive_fork_pr_branch: + name: Archive closed fork PR branch with Bencher runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: bencherdev/bencher@main - - name: Archive closed PR branch with Bencher + - name: Archive closed fork PR branch with Bencher run: | bencher archive \ --project 21cmfast \ diff --git a/.github/workflows/fork_pr_benchmarks_run.yml b/.github/workflows/fork_pr_benchmarks_run.yml new file mode 100644 index 00000000..0075d6a0 --- /dev/null +++ b/.github/workflows/fork_pr_benchmarks_run.yml @@ -0,0 +1,51 @@ +name: Run Benchmarks + +on: + pull_request: + types: [opened, reopened, edited, synchronize] + +jobs: + benchmark_fork_pr_branch: + name: Run Fork PR Benchmarks + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + permissions: + pull-requests: write + + defaults: + run: + # Adding -l {0} ensures conda can be found properly in each step + shell: bash -l {0} + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Setup Miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + channels: conda-forge,defaults + python-version: 3.11 + channel-priority: true + + - name: Install Non-Python Dependencies + run: | + conda install fftw gsl numba + + - name: Install 21cmFAST + run: | + pip install ".[dev]" + + - name: Run Benchmarking + run: | + pytest --benchmark-json results.json tests/test_integration_features.py + + - name: Upload Benchmark Results + uses: actions/upload-artifact@v4 + with: + name: benchmark_results.json + path: ./results.json + - name: Upload GitHub Pull Request Event + uses: actions/upload-artifact@v4 + with: + name: event.json + path: ${{ github.event_path }} diff --git a/.github/workflows/fork_pr_benchmarks_track.yml b/.github/workflows/fork_pr_benchmarks_track.yml new file mode 100644 index 00000000..ce158b48 --- /dev/null +++ b/.github/workflows/fork_pr_benchmarks_track.yml @@ -0,0 +1,61 @@ +name: Track Benchmarks with Bencher + +on: + workflow_run: + workflows: [Run Benchmarks] + types: [completed] + +jobs: + track_fork_pr_branch: + if: github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write + runs-on: ubuntu-latest + env: + BENCHMARK_RESULTS: results.json + PR_EVENT: event.json + steps: + - name: Download Benchmark Results + uses: dawidd6/action-download-artifact@v6 + with: + name: ${{ env.BENCHMARK_RESULTS }} + run_id: ${{ github.event.workflow_run.id }} + - name: Download PR Event + uses: dawidd6/action-download-artifact@v6 + with: + name: ${{ env.PR_EVENT }} + run_id: ${{ github.event.workflow_run.id }} + - name: Export PR Event Data + uses: actions/github-script@v6 + with: + script: | + let fs = require('fs'); + let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'})); + core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref); + core.exportVariable("PR_HEAD_SHA", prEvent.pull_request.head.sha); + core.exportVariable("PR_BASE", prEvent.pull_request.base.ref); + core.exportVariable("PR_BASE_SHA", prEvent.pull_request.base.sha); + core.exportVariable("PR_NUMBER", prEvent.number); + - uses: bencherdev/bencher@main + - name: Track Benchmarks with Bencher + run: | + bencher run \ + --project 21cmfast \ + --token '${{ secrets.BENCHER_API_TOKEN }}' \ + --branch "$PR_HEAD" \ + --hash "$PR_HEAD_SHA" \ + --start-point "$PR_BASE" \ + --start-point-hash "$PR_BASE_SHA" \ + --start-point-clone-thresholds \ + --start-point-reset \ + --testbed ubuntu-latest \ + --threshold-measure latency \ + --threshold-test percentage \ + --threshold-max-sample-size 64 \ + --threshold-upper-boundary 0.1 \ + --thresholds-reset \ + --err \ + --adapter json \ + --github-actions '${{ secrets.GITHUB_TOKEN }}' \ + --ci-number "$PR_NUMBER" \ + --file "$BENCHMARK_RESULTS" diff --git a/.github/workflows/pr_benchmarks.yml b/.github/workflows/pr_benchmarks.yml deleted file mode 100644 index 6c346fdd..00000000 --- a/.github/workflows/pr_benchmarks.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: PR benchmark - -on: - pull_request: - branches: - - main - -jobs: - benchmark_pr_branch: - name: PR benchmark - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - permissions: - pull-requests: write - runs-on: ubuntu-latest - defaults: - run: - # Adding -l {0} ensures conda can be found properly in each step - shell: bash -l {0} - steps: - - uses: actions/checkout@v6 - - uses: bencherdev/bencher@main - - - name: Setup Miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - channels: conda-forge,defaults - python-version: 3.11 - channel-priority: true - - - name: Install Non-Python Dependencies - run: | - conda install fftw gsl numba - - - name: Install 21cmFAST - run: | - pip install ".[dev]" - - - name: Track base branch benchmarks with Bencher - env: - BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }} - run: | - bencher run \ - --project 21cmfast \ - --branch "$GITHUB_HEAD_REF" \ - --start-point "$GITHUB_BASE_REF" \ - --start-point-clone-thresholds \ - --start-point-reset \ - --testbed ubuntu-latest \ - --threshold-measure latency \ - --threshold-test percentage \ - --threshold-max-sample-size 64 \ - --threshold-upper-boundary 0.1 \ - --thresholds-reset \ - --err \ - --adapter python_pytest \ - --file results.json \ - --github-actions '${{ secrets.GITHUB_TOKEN }}' \ - "pytest --benchmark-json results.json tests/test_integration_features.py"