From 4f5c040cfd9f6423658bde1693af96562d698f06 Mon Sep 17 00:00:00 2001 From: Jonathan Daniel Date: Sat, 28 Oct 2023 19:59:01 +0300 Subject: [PATCH 1/3] Move the pre-commit job to a new workflow Don't run the new workflow on a scheduled basis. --- .github/workflows/pre-commit.yml | 46 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 33 ----------------------- 2 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..84ddcb6 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,46 @@ +name: Pre-commit + +on: + push: + branches: + - main + - "releases/**" + pull_request: + branches: + - main + - "releases/**" + workflow_dispatch: + +jobs: + pre-commit: + runs-on: ubuntu-latest + env: + CACHE_DIR: /opt/.cache + PRE_COMMIT_HOME: /opt/.cache/pre-commit + BLACK_CACHE_DIR: /opt/.cache/black + RUFF_CACHE_DIR: /opt/.cache/ruff + MYPY_CACHE_DIR: /opt/.cache/mypy + steps: + - uses: actions/checkout@v4 + - name: Install Poetry + run: pipx install --pip-args="-c .github/workflows/poetry-constraint.txt" poetry + - uses: actions/setup-python@v4 + with: + python-version-file: .python-version + cache: poetry + cache-dependency-path: | + poetry.lock + .github/workflows/env-markers/poetry-install.txt + - name: Install dependencies + run: poetry install + - name: Set PY + id: set-py + run: echo "PY=$(python -VV | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + with: + path: ${{ env.CACHE_DIR }} + key: pre-commit-${{ runner.os }}-python-${{ steps.set-py.outputs.PY }}-config-and-deps-${{ hashFiles('.pre-commit-config.yaml', 'poetry.lock') }} + - name: Run pre-commit + env: + PRE_COMMIT_COLOR: always + run: poetry run pre-commit run --all-files diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7182bd8..164413b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,39 +14,6 @@ on: - cron: "0 15 * * *" # Daily at 6pm Israel standard time jobs: - pre-commit: - runs-on: ubuntu-latest - env: - CACHE_DIR: /opt/.cache - PRE_COMMIT_HOME: /opt/.cache/pre-commit - BLACK_CACHE_DIR: /opt/.cache/black - RUFF_CACHE_DIR: /opt/.cache/ruff - MYPY_CACHE_DIR: /opt/.cache/mypy - steps: - - uses: actions/checkout@v4 - - name: Install Poetry - run: pipx install --pip-args="-c .github/workflows/poetry-constraint.txt" poetry - - uses: actions/setup-python@v4 - with: - python-version-file: .python-version - cache: poetry - cache-dependency-path: | - poetry.lock - .github/workflows/env-markers/poetry-install.txt - - name: Install dependencies - run: poetry install - - name: Set PY - id: set-py - run: echo "PY=$(python -VV | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 - with: - path: ${{ env.CACHE_DIR }} - key: pre-commit-${{ runner.os }}-python-${{ steps.set-py.outputs.PY }}-config-and-deps-${{ hashFiles('.pre-commit-config.yaml', 'poetry.lock') }} - - name: Run pre-commit - env: - PRE_COMMIT_COLOR: always - run: poetry run pre-commit run --all-files - tests: strategy: fail-fast: false From da8afaeef583a3a8a1cbfb4319641e7ef470593f Mon Sep 17 00:00:00 2001 From: Jonathan Daniel Date: Sat, 28 Oct 2023 20:01:40 +0300 Subject: [PATCH 2/3] Run the tests workflow on push/PR only when py files change See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 164413b..e333a66 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,10 +2,14 @@ name: Tests on: push: + paths: + - "**.py" branches: - main - "releases/**" pull_request: + paths: + - "**.py" branches: - main - "releases/**" From 8bbfacab092f16ac596ff5972312488a074cb778 Mon Sep 17 00:00:00 2001 From: Jonathan Daniel Date: Sat, 28 Oct 2023 20:06:50 +0300 Subject: [PATCH 3/3] Run the tests WF also when some other files change --- .github/workflows/tests.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e333a66..7cb6297 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,12 +4,22 @@ on: push: paths: - "**.py" + - pyproject.toml + - poetry.lock + - .github/workflows/poetry-constraint.txt + - .github/workflows/env-markers/poetry-install-only-main-test.txt + - .github/workflows/tests.yml branches: - main - "releases/**" pull_request: paths: - "**.py" + - pyproject.toml + - poetry.lock + - .github/workflows/poetry-constraint.txt + - .github/workflows/env-markers/poetry-install-only-main-test.txt + - .github/workflows/tests.yml branches: - main - "releases/**"