forked from arduino/compile-sketches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update infrastructure for checking for problems with Python code
Arduino tooling projects use a standardized infrastructure. A centralized collection of reusable infrastructure assets is maintained in a dedicated repository: https://github.com/arduino/tooling-project-assets Since the time this project's infrastructure was installed, some advancements have been made in the upstream "template" assets. The project's infrastructure is hereby brought up to date with the state of the art upstream assets. The significant changes: - Migration to the use of the Task task runner to allow contributors to easily run the same operations locally as is done by the CI system on GitHub. - The project will now be formatted using the Black code formatter tool, the standard for Arduino Tooling projects.
- Loading branch information
Showing
8 changed files
with
278 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python/.flake8 | ||
# See: https://flake8.pycqa.org/en/latest/user/configuration.html | ||
# The code style defined in this file is the official standardized style to be used in all Arduino tooling projects and | ||
# should not be modified. | ||
|
||
[flake8] | ||
doctests = True | ||
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before. | ||
ignore = W503 | ||
max-complexity = 10 | ||
max-line-length = 120 | ||
select = E,W,F,C,N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-python-task.md | ||
name: Check Python | ||
|
||
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows | ||
on: | ||
create: | ||
push: | ||
paths: | ||
- ".github/workflows/check-python-task.ya?ml" | ||
- "**/.flake8" | ||
- "**/poetry.lock" | ||
- "**/pyproject.toml" | ||
- "**/setup.cfg" | ||
- ".python-version" | ||
- "Taskfile.ya?ml" | ||
- "**/tox.ini" | ||
- "**.py" | ||
pull_request: | ||
paths: | ||
- ".github/workflows/check-python-task.ya?ml" | ||
- "**/.flake8" | ||
- "**/poetry.lock" | ||
- "**/pyproject.toml" | ||
- "**/setup.cfg" | ||
- ".python-version" | ||
- "Taskfile.ya?ml" | ||
- "**/tox.ini" | ||
- "**.py" | ||
schedule: | ||
# Run periodically to catch breakage caused by external changes. | ||
- cron: "0 8 * * WED" | ||
workflow_dispatch: | ||
repository_dispatch: | ||
|
||
jobs: | ||
run-determination: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
result: ${{ steps.determination.outputs.result }} | ||
steps: | ||
- name: Determine if the rest of the workflow should run | ||
id: determination | ||
run: | | ||
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" | ||
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. | ||
if [[ | ||
"${{ github.event_name }}" != "create" || | ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX | ||
]]; then | ||
# Run the other jobs. | ||
RESULT="true" | ||
else | ||
# There is no need to run the other jobs. | ||
RESULT="false" | ||
fi | ||
echo "result=$RESULT" >> $GITHUB_OUTPUT | ||
lint: | ||
needs: run-determination | ||
if: needs.run-determination.outputs.result == 'true' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: .python-version | ||
|
||
- name: Install Poetry | ||
run: | | ||
pipx install \ | ||
--python "$(which python)" \ | ||
poetry | ||
- name: Install Task | ||
uses: arduino/setup-task@v1 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
version: 3.x | ||
|
||
- name: Run flake8 | ||
uses: liskin/gh-problem-matcher-wrap@v2 | ||
with: | ||
linters: flake8 | ||
run: task python:lint | ||
|
||
formatting: | ||
needs: run-determination | ||
if: needs.run-determination.outputs.result == 'true' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: .python-version | ||
|
||
- name: Install Poetry | ||
run: | | ||
pipx install \ | ||
--python "$(which python)" \ | ||
poetry | ||
- name: Install Task | ||
uses: arduino/setup-task@v1 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
version: 3.x | ||
|
||
- name: Format Python code | ||
run: task python:format | ||
|
||
- name: Check formatting | ||
run: git diff --color --exit-code |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.