From 12b42b970415f047e139cdb2af30425f7572645c Mon Sep 17 00:00:00 2001 From: Sandro Campos Date: Mon, 30 Sep 2024 16:22:25 -0400 Subject: [PATCH] Remove Python env caching and upgrade asv --- ...benchmarks %}asv-main.yml{% endif %}.jinja | 123 +++++++---------- ...chmarks %}asv-nightly.yml{% endif %}.jinja | 125 ++++++++---------- ...e_benchmarks %}asv-pr.yml{% endif %}.jinja | 56 +++----- python-project-template/pyproject.toml.jinja | 2 +- 4 files changed, 118 insertions(+), 188 deletions(-) diff --git a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-main.yml{% endif %}.jinja b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-main.yml{% endif %}.jinja index f70e04c..ff836b9 100644 --- a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-main.yml{% endif %}.jinja +++ b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-main.yml{% endif %}.jinja @@ -2,7 +2,6 @@ # This workflow will run benchmarks with airspeed velocity (asv), # store the new results in the "benchmarks" branch and publish them # to a dashboard on GH Pages. - name: Run ASV benchmarks for main on: @@ -11,93 +10,61 @@ on: env: PYTHON_VERSION: "3.10" - WORKING_DIR: ${{ github.workspace }}/benchmarks + ASV_VERSION: "0.6.4" + WORKING_DIR: ${{github.workspace}}/benchmarks concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{github.workflow}}-${{github.ref}} cancel-in-progress: true jobs: - - setup-python: - runs-on: ubuntu-latest - - steps: - - name: Cache Python ${{ env.PYTHON_VERSION }} - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: python-${{ env.PYTHON_VERSION }} - - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: "${{ env.PYTHON_VERSION }}" - asv-main: runs-on: ubuntu-latest - needs: setup-python - permissions: contents: write - defaults: run: - working-directory: ${{ env.WORKING_DIR }} - + working-directory: ${{env.WORKING_DIR}} steps: - - name: Checkout main branch of the repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Cache Python ${{ env.PYTHON_VERSION }} - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: python-${{ env.PYTHON_VERSION }} - - - name: Install dependencies - run: | - sudo apt-get update - python -m pip install --upgrade pip - pip install asv==0.6.1 virtualenv tabulate - - - name: Configure git - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Create ASV machine config file - run: asv machine --machine gh-runner --yes - - - name: Fetch previous results from the "benchmarks" branch - run: | - if git ls-remote --exit-code origin benchmarks > /dev/null 2>&1; then - git merge origin/benchmarks \ - --allow-unrelated-histories \ - --no-commit - mv ../_results . - fi - - - name: Run ASV for the main branch - run: asv run ALL --skip-existing --verbose || true - - - name: Submit new results to the "benchmarks" branch - uses: JamesIves/github-pages-deploy-action@v4 - with: - branch: benchmarks - folder: ${{ env.WORKING_DIR }}/_results - target-folder: _results - - - name: Generate dashboard HTML - run: | - asv show - asv publish - - - name: Deploy to Github pages - uses: JamesIves/github-pages-deploy-action@v4 - with: - branch: gh-pages - folder: ${{ env.WORKING_DIR }}/_html + - name: Set up Python ${{env.PYTHON_VERSION}} + uses: actions/setup-python@v5 + with: + python-version: ${{env.PYTHON_VERSION}} + - name: Checkout main branch of the repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install dependencies + run: pip install "asv[virtualenv]==${{env.ASV_VERSION}}" + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Create ASV machine config file + run: asv machine --machine gh-runner --yes + - name: Fetch previous results from the "benchmarks" branch + run: | + if git ls-remote --exit-code origin benchmarks > /dev/null 2>&1; then + git merge origin/benchmarks \ + --allow-unrelated-histories \ + --no-commit + mv ../_results . + fi + - name: Run ASV for the main branch + run: asv run ALL --skip-existing --verbose || true + - name: Submit new results to the "benchmarks" branch + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: benchmarks + folder: ${{env.WORKING_DIR}}/_results + target-folder: _results + - name: Generate dashboard HTML + run: | + asv show + asv publish + - name: Deploy to Github pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: ${{env.WORKING_DIR}}/_html {%- endraw -%} \ No newline at end of file diff --git a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-nightly.yml{% endif %}.jinja b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-nightly.yml{% endif %}.jinja index 09f831f..583d988 100644 --- a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-nightly.yml{% endif %}.jinja +++ b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-nightly.yml{% endif %}.jinja @@ -2,7 +2,6 @@ # This workflow will run daily at 06:45. # It will run benchmarks with airspeed velocity (asv) # and compare performance with the previous nightly build. - name: Run benchmarks nightly job on: @@ -12,84 +11,64 @@ on: env: PYTHON_VERSION: "3.10" - WORKING_DIR: ${{ github.workspace }}/benchmarks + ASV_VERSION: "0.6.4" + WORKING_DIR: ${{github.workspace}}/benchmarks NIGHTLY_HASH_FILE: nightly-hash jobs: - asv-nightly: runs-on: ubuntu-latest - defaults: run: - working-directory: ${{ env.WORKING_DIR }} - + working-directory: ${{env.WORKING_DIR}} steps: - - name: Checkout main branch of the repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Cache Python ${{ env.PYTHON_VERSION }} - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: python-${{ env.PYTHON_VERSION }} - - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: "${{ env.PYTHON_VERSION }}" - - - name: Install dependencies - run: | - sudo apt-get update - python -m pip install --upgrade pip - pip install asv==0.6.1 virtualenv - - - name: Configure git - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Create ASV machine config file - run: asv machine --machine gh-runner --yes - - - name: Fetch previous results from the "benchmarks" branch - run: | - if git ls-remote --exit-code origin benchmarks > /dev/null 2>&1; then - git merge origin/benchmarks \ - --allow-unrelated-histories \ - --no-commit - mv ../_results . - fi - - - name: Get nightly dates under comparison - id: nightly-dates - run: | - echo "yesterday=$(date -d yesterday +'%Y-%m-%d')" >> $GITHUB_OUTPUT - echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - - name: Use last nightly commit hash from cache - uses: actions/cache@v4 - with: - path: ${{ env.WORKING_DIR }} - key: nightly-results-${{ steps.nightly-dates.outputs.yesterday }} - - - name: Run comparison of main against last nightly build - run: | - HASH_FILE=${{ env.NIGHTLY_HASH_FILE }} - CURRENT_HASH=${{ github.sha }} - if [ -f $HASH_FILE ]; then - PREV_HASH=$(cat $HASH_FILE) - asv continuous $PREV_HASH $CURRENT_HASH --verbose || true - asv compare $PREV_HASH $CURRENT_HASH --sort ratio --verbose - fi - echo $CURRENT_HASH > $HASH_FILE - - - name: Update last nightly hash in cache - uses: actions/cache@v4 - with: - path: ${{ env.WORKING_DIR }} - key: nightly-results-${{ steps.nightly-dates.outputs.today }} + - name: Set up Python ${{env.PYTHON_VERSION}} + uses: actions/setup-python@v5 + with: + python-version: ${{env.PYTHON_VERSION}} + - name: Checkout main branch of the repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install dependencies + run: pip install "asv[virtualenv]==${{env.ASV_VERSION}}" + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Create ASV machine config file + run: asv machine --machine gh-runner --yes + - name: Fetch previous results from the "benchmarks" branch + run: | + if git ls-remote --exit-code origin benchmarks > /dev/null 2>&1; then + git merge origin/benchmarks \ + --allow-unrelated-histories \ + --no-commit + mv ../_results . + fi + - name: Get nightly dates under comparison + id: nightly-dates + run: | + echo "yesterday=$(date -d yesterday +'%Y-%m-%d')" >> $GITHUB_OUTPUT + echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - name: Use last nightly commit hash from cache + uses: actions/cache@v4 + with: + path: ${{env.WORKING_DIR}} + key: nightly-results-${{steps.nightly-dates.outputs.yesterday}} + - name: Run comparison of main against last nightly build + run: | + HASH_FILE=${{env.NIGHTLY_HASH_FILE}} + CURRENT_HASH=${{github.sha}} + if [ -f $HASH_FILE ]; then + PREV_HASH=$(cat $HASH_FILE) + asv continuous $PREV_HASH $CURRENT_HASH --verbose || true + asv compare $PREV_HASH $CURRENT_HASH --sort ratio --verbose + fi + echo $CURRENT_HASH > $HASH_FILE + - name: Update last nightly hash in cache + uses: actions/cache@v4 + with: + path: ${{env.WORKING_DIR}} + key: nightly-results-${{steps.nightly-dates.outputs.today}} {%- endraw -%} \ No newline at end of file diff --git a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-pr.yml{% endif %}.jinja b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-pr.yml{% endif %}.jinja index 4b5565c..be577f2 100644 --- a/python-project-template/.github/workflows/{% if include_benchmarks %}asv-pr.yml{% endif %}.jinja +++ b/python-project-template/.github/workflows/{% if include_benchmarks %}asv-pr.yml{% endif %}.jinja @@ -12,77 +12,61 @@ on: workflow_dispatch: concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{github.workflow}}-${{github.ref}} cancel-in-progress: true env: PYTHON_VERSION: "3.10" - WORKING_DIR: ${{ github.workspace }}/benchmarks - ARTIFACTS_DIR: ${{ github.workspace }}/artifacts + ASV_VERSION: "0.6.4" + WORKING_DIR: ${{github.workspace}}/benchmarks + ARTIFACTS_DIR: ${{github.workspace}}/artifacts jobs: - setup-python: - runs-on: ubuntu-latest - steps: - - name: Cache Python ${{ env.PYTHON_VERSION }} - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: python-${{ env.PYTHON_VERSION }} - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: ${{ env.PYTHON_VERSION }} asv-pr: runs-on: ubuntu-latest - needs: setup-python defaults: run: - working-directory: ${{ env.WORKING_DIR }} + working-directory: ${{env.WORKING_DIR}} steps: + - name: Set up Python ${{env.PYTHON_VERSION}} + uses: actions/setup-python@v5 + with: + python-version: ${{env.PYTHON_VERSION}} - name: Checkout PR branch of the repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Display Workflow Run Information run: | - echo "Workflow Run ID: ${{ github.run_id }}" - - name: Cache Python ${{ env.PYTHON_VERSION }} - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: python-${{ env.PYTHON_VERSION }} + echo "Workflow Run ID: ${{github.run_id}}" - name: Install dependencies - run: | - sudo apt-get update - python -m pip install --upgrade pip - pip install asv==0.6.1 virtualenv tabulate lf-asv-formatter + run: pip install "asv[virtualenv]==${{env.ASV_VERSION}}" lf-asv-formatter - name: Make artifacts directory - run: mkdir -p ${{ env.ARTIFACTS_DIR }} + run: mkdir -p ${{env.ARTIFACTS_DIR}} - name: Save pull request number - run: echo ${{ github.event.pull_request.number }} > ${{ env.ARTIFACTS_DIR }}/pr + run: echo ${{github.event.pull_request.number}} > ${{env.ARTIFACTS_DIR}}/pr - name: Get current job logs URL uses: Tiryoh/gha-jobid-action@v1 id: jobs with: - github_token: ${{ secrets.GITHUB_TOKEN }} - job_name: ${{ github.job }} + github_token: ${{secrets.GITHUB_TOKEN}} + job_name: ${{github.job}} - name: Create ASV machine config file run: asv machine --machine gh-runner --yes - name: Save comparison of PR against main branch run: | - git remote add upstream https://github.com/${{ github.repository }}.git + git remote add upstream https://github.com/${{github.repository}}.git git fetch upstream asv continuous upstream/main HEAD --verbose || true asv compare upstream/main HEAD --sort ratio --verbose | tee output - python -m lf_asv_formatter --asv_version "$(echo asv --version)" + python -m lf_asv_formatter --asv_version "$(asv --version | awk '{print $2}')" printf "\n\nClick [here]($STEP_URL) to view all benchmarks." >> output - mv output ${{ env.ARTIFACTS_DIR }} + mv output ${{env.ARTIFACTS_DIR}} env: - STEP_URL: "${{ steps.jobs.outputs.html_url }}#step:11:1" + STEP_URL: ${{steps.jobs.outputs.html_url}}#step:10:1 - name: Upload artifacts (PR number and benchmarks output) uses: actions/upload-artifact@v4 with: name: benchmark-artifacts - path: ${{ env.ARTIFACTS_DIR }} + path: ${{env.ARTIFACTS_DIR}} {%- endraw -%} \ No newline at end of file diff --git a/python-project-template/pyproject.toml.jinja b/python-project-template/pyproject.toml.jinja index 3763035..5d6a9b3 100644 --- a/python-project-template/pyproject.toml.jinja +++ b/python-project-template/pyproject.toml.jinja @@ -29,7 +29,7 @@ dependencies = [ [project.optional-dependencies] dev = [ {%- if include_benchmarks %} - "asv==0.6.1", # Used to compute performance benchmarks + "asv==0.6.4", # Used to compute performance benchmarks {%- endif %} {%- if 'black' in enforce_style %} "black", # Used for static linting of files