From 35a27a8d04bff4b091f885c6d2a91f9a762c8d79 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Fri, 25 Mar 2022 09:46:57 +0000 Subject: [PATCH] ci: avoid race between bench and guide --- .github/workflows/bench.yml | 99 ----------------- .github/workflows/{guide.yml => gh-pages.yml} | 102 +++++++++++++++++- 2 files changed, 97 insertions(+), 104 deletions(-) delete mode 100644 .github/workflows/bench.yml rename .github/workflows/{guide.yml => gh-pages.yml} (55%) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml deleted file mode 100644 index 162a26bd..00000000 --- a/.github/workflows/bench.yml +++ /dev/null @@ -1,99 +0,0 @@ -on: - push: - branches: - - main - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} - cancel-in-progress: true - -name: Benchmark - -jobs: - benchmark: - name: Cargo benchmark - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: cargo-${{ runner.os }}-bench-${{ hashFiles('**/Cargo.toml') }} - continue-on-error: true - - - name: Run benchmarks - run: | - for bench in call dict gil list pyclass pyobject set tuple; do - cargo bench --features hashbrown --bench "bench_$bench" -- --output-format bencher | tee -a output.txt - done - - # Download previous benchmark result from cache (if exists) - - name: Download previous benchmark data - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-benchmark - - # Run `github-action-benchmark` action - - name: Store benchmark result - uses: rhysd/github-action-benchmark@v1 - with: - name: pyo3-bench - # What benchmark tool the output.txt came from - tool: "cargo" - # Where the output from the benchmark tool is stored - output-file-path: output.txt - # GitHub API token to make a commit comment - github-token: ${{ secrets.GITHUB_TOKEN }} - auto-push: ${{ github.event_name != 'pull_request' }} - - pytest-benchmark: - name: pytest benchmark - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: cargo-${{ runner.os }}-pytest-bench-${{ hashFiles('**/Cargo.toml') }} - continue-on-error: true - - - name: Download previous benchmark data - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-pytest-benchmark - - - name: Run benchmarks - run: | - pip install nox - nox -f pytests/noxfile.py -s bench -- --benchmark-json $(pwd)/output.json - - name: Store benchmark result - uses: rhysd/github-action-benchmark@v1 - with: - name: pytest-bench - tool: "pytest" - output-file-path: output.json - github-token: ${{ secrets.GITHUB_TOKEN }} - auto-push: ${{ github.event_name != 'pull_request' }} diff --git a/.github/workflows/guide.yml b/.github/workflows/gh-pages.yml similarity index 55% rename from .github/workflows/guide.yml rename to .github/workflows/gh-pages.yml index 531abd96..3529810f 100644 --- a/.github/workflows/guide.yml +++ b/.github/workflows/gh-pages.yml @@ -1,4 +1,4 @@ -name: guide +name: gh-pages on: push: @@ -16,7 +16,7 @@ env: CARGO_TERM_COLOR: always jobs: - build: + guide-build: runs-on: ubuntu-latest outputs: tag_name: ${{ steps.prepare_tag.outputs.tag_name }} @@ -59,7 +59,7 @@ jobs: destination_dir: internal full_commit_message: "Upload internal documentation" - - name: Clear the extra artefacts created earlier + - name: Clear the extra artefacts created earlier run: rm -rf target # This builds the book in gh-pages-build. See https://github.com/rust-lang-nursery/mdBook/issues/698 @@ -83,8 +83,9 @@ jobs: publish_dir: ./gh-pages-build/ destination_dir: ${{ steps.prepare_tag.outputs.tag_name }} full_commit_message: "Upload documentation for ${{ steps.prepare_tag.outputs.tag_name }}" - release: - needs: build + + guide-release: + needs: guide-build runs-on: ubuntu-latest if: ${{ github.event_name == 'release' }} steps: @@ -103,3 +104,94 @@ jobs: publish_dir: ./public/ full_commit_message: "Release ${{ needs.build.outputs.tag_name }}" keep_files: true + + cargo-benchmark: + if: ${{ github.ref_name == 'main' }} + name: Cargo benchmark + needs: guide-build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: cargo-${{ runner.os }}-bench-${{ hashFiles('**/Cargo.toml') }} + continue-on-error: true + + - name: Run benchmarks + run: | + for bench in call dict gil list pyclass pyobject set tuple; do + cargo bench --features hashbrown --bench "bench_$bench" -- --output-format bencher | tee -a output.txt + done + + # Download previous benchmark result from cache (if exists) + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + # Run `github-action-benchmark` action + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + name: pyo3-bench + # What benchmark tool the output.txt came from + tool: "cargo" + # Where the output from the benchmark tool is stored + output-file-path: output.txt + # GitHub API token to make a commit comment + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: ${{ github.event_name != 'pull_request' }} + + pytest-benchmark: + if: ${{ github.ref_name == 'main' }} + name: Pytest benchmark + needs: cargo-benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: cargo-${{ runner.os }}-pytest-bench-${{ hashFiles('**/Cargo.toml') }} + continue-on-error: true + + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-pytest-benchmark + + - name: Run benchmarks + run: | + pip install nox + nox -f pytests/noxfile.py -s bench -- --benchmark-json $(pwd)/output.json + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + name: pytest-bench + tool: "pytest" + output-file-path: output.json + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: ${{ github.event_name != 'pull_request' }}