From 8ac99bd6068ebf3a508fbe1fd109f0d49e7f9378 Mon Sep 17 00:00:00 2001 From: Tom Schraitle Date: Thu, 27 Jul 2023 21:55:51 +0200 Subject: [PATCH] Only run GHA if project files are modified There is no need to run the test suite when docs files are modified. --- .github/workflows/python-testing.yml | 69 +++++++++++++++++++--------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml index f6decc03..5c52af69 100644 --- a/.github/workflows/python-testing.yml +++ b/.github/workflows/python-testing.yml @@ -1,20 +1,23 @@ --- name: Python +# HINT: Sync this paths with the egrep in step check_files on: push: branches: [ "master", "main" ] paths: - 'pyproject.toml' + - 'setup.cfg' - '**.py' - - '.github/workflows/python-testing.yml' + - '.github/workflows/*.yml' pull_request: branches: [ "master", "main" ] paths: - 'pyproject.toml' + - 'setup.cfg' - '**.py' - - '.github/workflows/python-testing.yml' + - '.github/workflows/*.yml' permissions: contents: read @@ -22,37 +25,59 @@ permissions: concurrency: # only cancel in-progress runs of the same workflow group: ${{ github.workflow }}-${{ github.ref }} - # ${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: + check-files: + runs-on: ubuntu-latest + outputs: + can_run: ${{ steps.check_files.outputs.can_run }} + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: GitHub variables + id: gh-vars + run: | + for var in GITHUB_WORKFLOW GITHUB_ACTION GITHUB_ACTIONS GITHUB_REPOSITORY GITHUB_EVEN_NAME GITHUB_EVENT_PATH GITHUB_WORKSPACE GITHUB_SHA GITHUB_REF GITHUB_HEAD_REF GITHUB_BASE_REF; do + echo "$var = ${!var}" + done + + - name: Check for file changes + id: check_files + run: | + # ${{ github.event.after }} ${{ github.event.before }} + can_run=$(git diff --name-only HEAD~1 HEAD | \ + egrep -q '.github/workflows/|pyproject.toml|setup.cfg|\.py$' && echo 1 || echo 0) + echo "can_run=$can_run" + echo "can_run=$can_run" >> $GITHUB_OUTPUT + + skip_test: + runs-on: ubuntu-latest + needs: check-files + timeout-minutes: 2 + if: ${{ needs.check-files.outputs.can_run == '0' }} + + steps: + - name: Skip test + run: | + echo "Nothing to do as no TOML, Python, or YAML file has been changed. + " + echo "Skipping." + check: runs-on: ubuntu-latest + needs: check-files # Timout of 15min timeout-minutes: 15 + # needs.check-files.outputs.can_run + if: ${{ needs.check-files.outputs.can_run == '1' }} steps: - uses: actions/checkout@v3 - - name: Output env variables - run: | - echo "Default branch=${default-branch}" - echo "GITHUB_WORKFLOW=${GITHUB_WORKFLOW}" - echo "GITHUB_ACTION=$GITHUB_ACTION" - echo "GITHUB_ACTIONS=$GITHUB_ACTIONS" - echo "GITHUB_ACTOR=$GITHUB_ACTOR" - echo "GITHUB_REPOSITORY=$GITHUB_REPOSITORY" - echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME" - echo "GITHUB_EVENT_PATH=$GITHUB_EVENT_PATH" - echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE" - echo "GITHUB_SHA=$GITHUB_SHA" - echo "GITHUB_REF=$GITHUB_REF" - echo "GITHUB_HEAD_REF=$GITHUB_HEAD_REF" - echo "GITHUB_BASE_REF=$GITHUB_BASE_REF" - echo "::debug::---Start content of file $GITHUB_EVENT_PATH" - cat $GITHUB_EVENT_PATH - echo "\n" - echo "::debug::---end" - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy