diff --git a/.github/workflows/run_asvs.yaml b/.github/workflows/run_asvs.yaml index 53eadc38e9..cac717123b 100644 --- a/.github/workflows/run_asvs.yaml +++ b/.github/workflows/run_asvs.yaml @@ -13,7 +13,7 @@ env: # Results and other data are stored away from the main branch. # This keeps the main branch clean and allows us to clear out # objects / history after being built up for long periods of time. - BRANCH_NAME: pandas_20250109 + BRANCH_NAME: pandas_20250203 permissions: contents: read @@ -29,7 +29,7 @@ jobs: contents: write issues: write outputs: - new_commit: ${{ steps.new-commit.outputs.new_commit }} + new_commit: ${{ steps.get-commit.outputs.new_commit }} steps: # In order to run pandas' actions, we have to checkout into the root directory. - name: Checkout pandas @@ -44,38 +44,40 @@ jobs: ref: ${{ env.BRANCH_NAME }} path: asv-runner/ - - name: Compare Commit SHAs - id: new-commit + - name: Set up Conda + uses: ./.github/actions/setup-conda + + - name: Get Commit + id: get-commit run: | - if [ "$(git rev-parse HEAD)" = "$(cat asv-runner/data/latest_sha.txt)" ]; then + sha="$(python asv-runner/ci/find_commit_to_run.py --input-path=asv-runner/data/ --repo-path=.)" + echo "sha: $sha" + if [ "$sha" = "NONE" ]; then echo "new_commit=no" echo "new_commit=no" >> "$GITHUB_OUTPUT" else echo "new_commit=yes" echo "new_commit=yes" >> "$GITHUB_OUTPUT" fi - echo "$(git rev-parse HEAD)" > asv-runner/data/latest_sha.txt + echo "$sha" >> asv-runner/data/shas.txt + git checkout $sha # Prevent another job from kicking off and running on this commit - - name: Update latest_sha.txt - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + - name: Commit shas.txt + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: Update latest SHA + commit_message: Update shas.txt branch: ${{ env.BRANCH_NAME }} repository: asv-runner - file_pattern: 'data/latest_sha.txt' - - - name: Set up Conda - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} - uses: ./.github/actions/setup-conda + file_pattern: 'data/shas.txt' - name: Build pandas - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} uses: ./.github/actions/build_pandas - name: Run ASV Benchmarks - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} run: | cd asv_bench asv machine --machine=asvrunner --yes @@ -83,21 +85,21 @@ jobs: - name: Update asv-runner branch # In case there was a push by another job. - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} run: | cd asv-runner git fetch && git pull - name: Move results into asv-runner - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} run: | mkdir -p asv-runner/data/results/asvrunner/ cp asv_bench/results/benchmarks.json asv-runner/data/results/ cp asv_bench/results/asvrunner/machine.json asv-runner/data/results/asvrunner/ - cp asv_bench/results/asvrunner/$(git rev-parse --short=8 HEAD)-existing*.json asv-runner/data/results/asvrunner/ + cp asv_bench/results/asvrunner/$(git rev-parse --short=8 HEAD)-existing*.json asv-runner/data/results/asvrunner/$(git rev-parse HEAD).json - name: Commit results to branch - if: ${{ steps.new-commit.outputs.new_commit == 'yes' }} + if: ${{ steps.get-commit.outputs.new_commit == 'yes' }} uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Results diff --git a/ci/find_commit_to_run.py b/ci/find_commit_to_run.py new file mode 100644 index 0000000000..0e47b574fa --- /dev/null +++ b/ci/find_commit_to_run.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +import argparse +import subprocess +from pathlib import Path + + +def run(*, input_path: str | Path, repo_path: str | Path): + if isinstance(input_path, str): + input_path = Path(input_path) + if isinstance(repo_path, str): + repo_path = Path(repo_path) + + shas_path = input_path / "shas.txt" + existing_shas: set[str] + if not shas_path.exists(): + existing_shas = set() + else: + with open(input_path / "shas.txt") as fh: + existing_shas = {line.strip() for line in fh.readlines()} + + response = subprocess.run( + f"cd {repo_path} && git log -40 --oneline --no-abbrev-commit", + capture_output=True, + shell=True, + check=False, + ) + recent_shas = [ + line[: line.find(" ")] for line in response.stdout.decode().strip().split("\n") + ] + for sha in recent_shas: + if sha not in existing_shas: + print(sha) + return + print("NONE") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--input-path") + parser.add_argument("--repo-path") + args = parser.parse_args() + run(input_path=args.input_path, repo_path=args.repo_path)