Skip to content

Commit

Permalink
Merge pull request #114 from nathan-weinberg/mergify
Browse files Browse the repository at this point in the history
mergify: add mergify configuration
  • Loading branch information
nathan-weinberg authored Aug 28, 2024
2 parents 29fb9ad + 715d9ef commit eaa977d
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 25 deletions.
204 changes: 204 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
pull_request_rules:
- name: auto-merge
description: automatic merge for main with >= 2 approved reviews, all requested reviews have given feedback, not held, and CI is successful
conditions:
- "#approved-reviews-by>=2"
- "#review-requested=0"
- "#changes-requested-reviews-by=0"
- or:
- base=main
- base~=^release-
- label!=hold
- label!=do-not-merge
- label!=needs-rebase
- check-success=DCO

# The files conditions regex should match the globs in workflow files
# If workflow configuration files in .github/ are changed, the actionlint check must pass
- or:
- and:
- check-success=actionlint
- or:
- files~=^\.github/(actions|workflows)/.*\.ya?ml$
- files~=^\.github/workflows/actionlint\.
- and:
- -files~=^\.github/(actions|workflows)/.*\.ya?ml$
- -files~=^\.github/workflows/actionlint\.

# e2e workflow
- or:
- and:
- check-success=e2e
- or:
- files~=\.py$
- files=pyproject.toml
- files~=^requirements.*\.txt$
- files=.github/workflows/e2e.yml
- and:
- -files~=\.py$
- -files=pyproject.toml
- -files~=^requirements.*\.txt$
- -files=.github/workflows/e2e.yml

# lint must pass if files change that would trigger this job
- or:
- and:
- check-success=lint-workflow-complete
- or:
# see .github/workflows/lint.yml and test.yml
- files~=\.py$
- files=pyproject.toml
- files~=^requirements.*\.txt$
- files=tox.ini
- files~=^scripts/[^/]+\.sh$
- files=.github/workflows/lint.yml
- and:
- -files~=\.py$
- -files=pyproject.toml
- -files~=^requirements.*\.txt$
- -files=tox.ini
- -files~=^scripts/[^/]+\.sh$
- -files=.github/workflows/lint.yml

- or:
- and:
- check-success=markdown-lint
- or:
- files~=\.md$
- files=.markdownlint-cli2.yaml
- files=.github/workflows/docs.yml
- and:
- -files~=\.md$
- -files=.markdownlint-cli2.yaml
- -files=.github/workflows/docs.yml

- or:
- and:
- check-success=spellcheck
- or:
- files~=\.md$
- files=tox.ini
- files~=^\.spellcheck[^/]+$
- files=.github/workflows/spellcheck.yml
- and:
- -files~=\.md$
- -files=tox.ini
- -files~=^\.spellcheck[^/]+$
- -files=.github/workflows/spellcheck.yml

actions:
merge:
method: merge
delete_head_branch:

- name: label-cicd
description: Automatically apply CI/CD label
conditions:
- or:
- files=.github/mergify.yml
- files~=^\.github/(actions|workflows)/
- files=scripts/ruff.sh
- files=.pre-commit-config.yaml
- files=.pylintrc
- files~=^\.spellcheck[^/]+$
- files=tox.ini
- files=.markdownlint-cli2.yaml
actions:
label:
add:
- CI/CD

- name: label-documentation
description: Automatically apply documentation label
conditions:
- or:
- files~=^[^/]+\.md$
actions:
label:
add:
- documentation

- name: label-testing
description: Automatically apply testing label
conditions:
- or:
- files~=^tests/
- files=tox.ini
actions:
label:
add:
- testing

- name: ping author on conflicts and add 'needs-rebase' label
conditions:
- conflict
- -closed
actions:
label:
add:
- needs-rebase
comment:
message: |
This pull request has merge conflicts that must be resolved before it can be
merged. @{{author}} please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork
- name: remove 'needs-rebase' label when conflict is resolved
conditions:
- -conflict
- -closed
actions:
label:
remove:
- needs-rebase

- name: release-branch-label
description: Automatically apply the release-branch label to release branch PRs
conditions:
- base~=^release-
actions:
label:
add:
- release-branch

- name: Apply ci-failure label if any CI checks have failed
conditions:
- "#check-failure>0"
actions:
label:
add:
- ci-failure

- name: Remove ci-failure label if no failures are present
conditions:
- "#check-failure=0"
actions:
label:
remove:
- ci-failure

- name: Apply 'one-approval' label if one of the maintainer approved the PR
conditions:
- "#approved-reviews-by=1"
actions:
label:
add:
- one-approval

- name: Remove 'one-approval' label if the approval was reset
conditions:
- "#approved-reviews-by!=1"
actions:
label:
remove:
- one-approval

- name: label-dependencies
description: Automatically apply dependencies label
conditions:
- or:
- files~=^requirements.*\.txt$
- files~=^requirements/
actions:
label:
add:
- dependencies
71 changes: 47 additions & 24 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
- 'pyproject.toml'
- 'requirements*.txt'
- 'tox.ini'
- 'scripts/*.sh'
- '.github/**'
- 'scripts/*.sh' # Used by this workflow
- '.github/workflows/lint.yml' # This workflow
pull_request:
branches:
- "main"
Expand All @@ -23,52 +23,75 @@ on:
- 'pyproject.toml'
- 'requirements*.txt'
- 'tox.ini'
- 'scripts/*.sh'
- '.github/**'
- 'scripts/*.sh' # Used by this workflow
- '.github/workflows/lint.yml' # This workflow

env:
PYTHON_VERSION: 3.11
LC_ALL: en_US.UTF-8

defaults:
run:
shell: bash

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
name: "${{ matrix.lint.name }}"
strategy:
fail-fast: false
matrix:
lint:
- name: "ruff"
commands: |
tox -e ruff -- check
- name: "pylint"
commands: |
echo "::add-matcher::.github/workflows/matchers/pylint.json"
tox -e lint
- name: "mypy"
commands: |
tox -e mypy
steps:
- name: Checkout
uses: actions/checkout@v4
- name: "Harden Runner"
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: "Checkout"
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# https://github.com/actions/checkout/issues/249
fetch-depth: 0
submodules: true

- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Setup Python 3.11
uses: actions/setup-python@v5
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: 3.11
cache: pip
cache-dependency-path: |
**/pyproject.toml
**/requirements*.txt
- name: Install dependencies
id: deps
- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox
python -m pip install tox tox-gh
- name: Run Ruff check
- name: "${{ matrix.lint.name }}"
run: |
tox -e ruff -- check
${{ matrix.lint.commands }}
env:
RUFF_OUTPUT_FORMAT: github

- name: Run linting
if: ${{ !cancelled() && (steps.deps.outcome == 'success') }}
run: |
echo "::add-matcher::.github/workflows/matchers/pylint.json"
tox -e lint
- name: Run mypy type checks
if: ${{ !cancelled() && (steps.deps.outcome == 'success') }}
run: |
tox -e mypy
lint-workflow-complete:
needs: ["lint"]
runs-on: ubuntu-latest
steps:
- name: Lint Workflow Complete
run: echo "Lint Workflow Complete"
1 change: 0 additions & 1 deletion .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ permissions:

jobs:
spellcheck:
name: Spellcheck (en_US)
runs-on: ubuntu-latest
steps:
- name: "Harden Runner"
Expand Down

0 comments on commit eaa977d

Please sign in to comment.