Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure PR workflows can run on all PRs (but still skip when they're not needed) #2237

Merged
merged 19 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions .github/workflows/ansible-lint.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
name: ansible-lint
on:
push:
paths:
- 'ansible/**'
pull_request:
paths:
- 'ansible/**'

on: [push, pull_request]

# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# In order to be able to have required checks, a workflow can't be entirely
# skipped: see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
paths-filter:
name: "Filter Paths"
runs-on: ubuntu-latest
outputs:
matches: ${{ steps.filter.outputs.matches }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # important, to fetch previous commit

# workaround for https://github.com/dorny/paths-filter/issues/240
- id: previous-sha
run: 'echo "sha=$(git rev-parse HEAD^1)" >> $GITHUB_OUTPUT'

- uses: dorny/paths-filter@v3
id: filter
with:
base: "${{ steps.previous-sha.outputs.sha }}"
filters: |
matches:
- 'ansible/**'
- '.github/workflows/ansible-lint.yaml'

build:
needs: paths-filter
if: needs.paths-filter.outputs.matches == 'true'
name: Ansible Lint
runs-on: ubuntu-latest

Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/backend-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Backend Lint + Type Check

on: [push, pull_request]

# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# In order to be able to have required checks, a workflow can't be entirely
# skipped: see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
paths-filter:
name: "Filter Paths"
runs-on: ubuntu-latest
outputs:
matches: ${{ steps.filter.outputs.matches }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # important, to fetch previous commit

# workaround for https://github.com/dorny/paths-filter/issues/240
- id: previous-sha
run: 'echo "sha=$(git rev-parse HEAD^1)" >> $GITHUB_OUTPUT'

- uses: dorny/paths-filter@v3
id: filter
with:
base: "${{ steps.previous-sha.outputs.sha }}"
filters: |
matches:
- 'backend/**'
- '.github/workflows/backend-lint.yaml'

unit-tests:
needs: paths-filter
if: needs.paths-filter.outputs.matches == 'true'
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
cd backend/
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev-requirements.txt

- name: Style Check
run: |
black --check backend/btrixcloud/

- name: Lint Check
run: |
cd backend/
pylint btrixcloud/

- name: Type Check
run: |
cd backend/
mypy --install-types --non-interactive --check-untyped-defs btrixcloud/
101 changes: 0 additions & 101 deletions .github/workflows/frontend-build-prepare.yaml

This file was deleted.

Loading
Loading