From 340217fa24c3346bbe6e7cc61ff5e566aa95bc51 Mon Sep 17 00:00:00 2001 From: Drew Oldag Date: Wed, 2 Oct 2024 13:56:00 -0700 Subject: [PATCH] Updating to the latest PPT version. Adding workflow support for failure alerts sent to slack. --- .copier-answers.yml | 5 +- .github/workflows/asv-main.yml | 123 +++++++++++----------------- .github/workflows/asv-nightly.yml | 125 ++++++++++++----------------- .github/workflows/asv-pr.yml | 56 +++++-------- .github/workflows/smoke-test.yml | 40 ++++++++- .pre-commit-config.yaml | 2 + LICENSE | 2 +- benchmarks/asv.conf.json | 1 + pyproject.toml | 2 +- src/resspect/example_benchmarks.py | 4 +- 10 files changed, 166 insertions(+), 194 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 8130fcdb..97e90a94 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,12 +1,13 @@ # Changes here will be overwritten by Copier -_commit: v2.0.2 +_commit: v2.0.3 _src_path: gh:lincc-frameworks/python-project-template author_email: contact@cosmostatistics-initiative.org author_name: The RESSPECT team create_example_module: false custom_install: true enforce_style: [] -failure_notification: [] +failure_notification: +- slack include_benchmarks: true include_docs: false mypy_type_checking: none diff --git a/.github/workflows/asv-main.yml b/.github/workflows/asv-main.yml index f6a6f297..32c25cf5 100644 --- a/.github/workflows/asv-main.yml +++ b/.github/workflows/asv-main.yml @@ -1,7 +1,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: @@ -10,92 +9,60 @@ 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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/.github/workflows/asv-nightly.yml b/.github/workflows/asv-nightly.yml index 80a2d785..28b270ae 100644 --- a/.github/workflows/asv-nightly.yml +++ b/.github/workflows/asv-nightly.yml @@ -1,7 +1,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: @@ -11,83 +10,63 @@ 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 }} \ No newline at end of file + - 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}} \ No newline at end of file diff --git a/.github/workflows/asv-pr.yml b/.github/workflows/asv-pr.yml index bf5aed6d..4499eb9f 100644 --- a/.github/workflows/asv-pr.yml +++ b/.github/workflows/asv-pr.yml @@ -11,76 +11,60 @@ 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 }} \ No newline at end of file + path: ${{env.ARTIFACTS_DIR}} \ No newline at end of file diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 31075605..35e5a478 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -39,4 +39,42 @@ jobs: pip list - name: Run unit tests with pytest run: | - python -m pytest \ No newline at end of file + python -m pytest + - name: Send status to Slack app + if: ${{ failure() && github.event_name != 'workflow_dispatch' }} + id: slack + uses: slackapi/slack-github-action@v1 + with: + # For posting a rich message using Block Kit + payload: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "${{ github.repository }}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "GitHub Action build result: *${{ job.status }}* :${{ job.status }}:" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7811ea40..d128208a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ + repos: # Compare the local template version to the latest remote template version # This hook should always pass. It will print a message if the local version @@ -16,6 +17,7 @@ repos: name: Clear output from Jupyter notebooks description: Clear output from Jupyter notebooks. files: \.ipynb$ + exclude: ^docs/pre_executed stages: [commit] language: system entry: jupyter nbconvert --clear-output diff --git a/LICENSE b/LICENSE index 435c3ed1..155187db 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 The RESSPECT team +Copyright (c) 2024 The RESSPECT team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/benchmarks/asv.conf.json b/benchmarks/asv.conf.json index 08dea6a3..f1c37642 100644 --- a/benchmarks/asv.conf.json +++ b/benchmarks/asv.conf.json @@ -1,3 +1,4 @@ + { // The version of the config file format. Do not change, unless // you know what you are doing. diff --git a/pyproject.toml b/pyproject.toml index 03d707e4..dca62021 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ run_time_domain = "resspect.scripts.run_time_domain:main" [project.optional-dependencies] dev = [ - "asv==0.6.1", # Used to compute performance benchmarks + "asv==0.6.4", # Used to compute performance benchmarks "jupyter", # Clears output from Jupyter notebooks "pre-commit", # Used to run checks before finalizing a git commit "pytest", diff --git a/src/resspect/example_benchmarks.py b/src/resspect/example_benchmarks.py index 5a77b06c..78da46a0 100644 --- a/src/resspect/example_benchmarks.py +++ b/src/resspect/example_benchmarks.py @@ -4,11 +4,11 @@ import time -def runtime_computation(): +def runtime_computation() -> None: """Runtime computation consuming between 0 and 5 seconds.""" time.sleep(random.uniform(0, 5)) -def memory_computation(): +def memory_computation() -> list[int]: """Memory computation for a random list up to 512 samples.""" return [0] * random.randint(0, 512)