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

🧑‍💻 Add validate-pins workflow for PRs #26996

Merged
51 changes: 51 additions & 0 deletions .github/workflows/ci-validate-pins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# ci-validate-pins.yml
# Validate that all of the pins files are unchanged by pinsformat.py
#

name: CI - Validate Pins Files

on:
pull_request:
branches:
- bugfix-2.1.x
# Cannot be enabled on 2.1.x until it contains the unit test framework
#- 2.1.x
paths:
- 'Marlin/src/pins/*/**'
push:
branches:
- bugfix-2.1.x
# Cannot be enabled on 2.1.x until it contains the unit test framework
#- 2.1.x
paths:
- 'Marlin/src/pins/*/**'

jobs:
validate_pins_files:
name: Validate Pins Files
if: github.repository == 'MarlinFirmware/Marlin'

runs-on: ubuntu-latest

steps:
- name: Check out the PR
uses: actions/checkout@v4

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Select Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'

- name: Validate all pins files
run: |
make validate-pins -j
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ UNIT_TEST_CONFIG ?= default
help:
@echo "Tasks for local development:"
@echo "make marlin : Build marlin for the configured board"
@echo "make format-pins : Reformat all pins files"
@echo "make format-pins -j : Reformat all pins files (-j for parallel execution)"
@echo "make validate-pins -j : Validate all pins files, fails if any require reformatting"
@echo "make tests-single-ci : Run a single test from inside the CI"
@echo "make tests-single-local : Run a single test locally"
@echo "make tests-single-local-docker : Run a single test locally, using docker"
Expand Down Expand Up @@ -81,7 +82,14 @@ setup-local-docker:

PINS := $(shell find Marlin/src/pins -mindepth 2 -name '*.h')

.PHONY: $(PINS) format-pins validate-pins

$(PINS): %:
@echo "Formatting $@" && node $(SCRIPTS_DIR)/pinsformat.js $@
@echo "Formatting $@"
@python $(SCRIPTS_DIR)/pinsformat.py $< $@

format-pins: $(PINS)

validate-pins: format-pins
@echo "Validating pins files"
@git diff --exit-code || (git status && echo "\nError: Pins files are not formatted correctly. Run \"make format-pins\" to fix.\n" && exit 1)
2 changes: 1 addition & 1 deletion buildroot/share/git/mfhelp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Modify Configuration.h / Configuration_adv.h:
Modify pins files:

pins_set ............. Set the value of a pin in a pins file
pinsformat.js ........ Node.js script to format pins files
pinsformat.py ........ Python script to format pins files

THIS
197 changes: 0 additions & 197 deletions buildroot/share/scripts/pinsformat.js

This file was deleted.

24 changes: 16 additions & 8 deletions buildroot/share/scripts/pinsformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def rpad(astr, fill, c=' '):
need = fill - len(astr)
return astr if need <= 0 else astr + (need * c)

# Concatenate a string, adding a space if necessary
# to avoid merging two words
def concat_with_space(s1, s2):
if not s1.endswith(' ') and not s2.startswith(' '):
s1 += ' '
return s1 + s2

# Pin patterns
mpatt = [ r'-?\d{1,3}', r'P[A-I]\d+', r'P\d_\d+', r'Pin[A-Z]\d\b' ]
mstr = '|'.join(mpatt)
Expand All @@ -45,6 +52,7 @@ def format_pins(argv):
scnt = 0
for arg in argv:
if arg == '-v':
global do_log
do_log = True
elif scnt == 0:
# Get a source file if specified. Default destination is the same file
Expand Down Expand Up @@ -135,7 +143,7 @@ def tryPindef(d):
logmsg("pin:", line)
pinnum = r[4] if r[4][0] == 'P' else lpad(r[4], patt['pad'])
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + pinnum
line = concat_with_space(rpad(line, col_value_lj), pinnum)
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
Expand All @@ -149,7 +157,7 @@ def tryNoPin(d):
if r == None: return False
logmsg("pin -1:", line)
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + '-1'
line = concat_with_space(rpad(line, col_value_lj), '-1')
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
Expand Down Expand Up @@ -179,8 +187,8 @@ def tryAlias(d):
if r == None: return False
logmsg("alias:", line)
line = f'{r[1]} {r[3]}'
line += lpad(r[4], col_value_rj + 1 - len(line))
if r[5]: line = rpad(line, col_comment) + r[5]
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = concat_with_space(rpad(line, col_comment), r[5])
d['line'] = line
return True

Expand All @@ -193,7 +201,7 @@ def trySwitch(d):
if r == None: return False
logmsg("switch:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
d['check_comment_next'] = True
return True
Expand All @@ -207,7 +215,7 @@ def tryDef(d):
if r == None: return False
logmsg("def:", line)
line = f'{r[1]} {r[3]} '
line += lpad(r[4], col_value_rj + 1 - len(line))
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = rpad(line, col_comment - 1) + ' ' + r[5]
d['line'] = line
return True
Expand All @@ -221,7 +229,7 @@ def tryUndef(d):
if r == None: return False
logmsg("undef:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
return True

Expand All @@ -233,7 +241,7 @@ def tryCond(d):
r = condPatt.match(line)
if r == None: return False
logmsg("cond:", line)
line = rpad(r[1], col_comment) + r[5]
line = concat_with_space(rpad(r[1], col_comment), r[5])
d['line'] = line
d['check_comment_next'] = True
return True
Expand Down
Loading