Skip to content

Commit 6575639

Browse files
committed
fix: improve lint workflow portability and messaging
Address PR feedback: - Replace xargs -r (GNU-specific) with tr/xargs -0 for cross-platform compatibility - Add empty-file handling to prevent stdin processing - Add consistent messaging for all file-type scenarios The xargs -r flag is a GNU extension not available on BSD/macOS. Using null-delimited input (tr '\n' '\0' | xargs -0) is POSIX-compliant and works across all platforms.
1 parent 0d6c6bf commit 6575639

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

.github/workflows/lint.yml

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ jobs:
107107
# Run solhint in each workspace package that has contracts (check mode)
108108
pnpm -r exec bash -c 'if [ -d "contracts" ]; then npx solhint --max-warnings=0 --noPrompt --noPoster "contracts/**/*.sol" 2>/dev/null || exit 1; fi'
109109
# Check formatting with prettier
110-
git ls-files '*.sol' | xargs -r npx prettier --check --cache --log-level warn
110+
SOL_FILES=$(git ls-files '*.sol')
111+
if [ -n "$SOL_FILES" ]; then
112+
echo "$SOL_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn
113+
else
114+
echo "No Solidity files found"
115+
fi
111116
elif [ "${{ steps.changed_files.outputs.sol_count }}" -gt "0" ]; then
112117
echo "Linting changed Solidity files..."
113118
# Lint each changed file from its package directory
@@ -132,7 +137,9 @@ jobs:
132137
done
133138
134139
# Check formatting with prettier
135-
cat changed_sol.txt | xargs -r npx prettier --check --cache --log-level warn
140+
cat changed_sol.txt | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn
141+
else
142+
echo "No Solidity files to lint"
136143
fi
137144
138145
- name: Lint TypeScript/JavaScript files
@@ -141,12 +148,19 @@ jobs:
141148
run: |
142149
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
143150
echo "Linting all TypeScript/JavaScript files..."
144-
git ls-files '*.js' '*.ts' '*.cjs' '*.mjs' '*.jsx' '*.tsx' | xargs -r npx eslint --max-warnings=0 --no-warn-ignored
145-
git ls-files '*.js' '*.ts' '*.cjs' '*.mjs' '*.jsx' '*.tsx' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
151+
TS_FILES=$(git ls-files '*.js' '*.ts' '*.cjs' '*.mjs' '*.jsx' '*.tsx')
152+
if [ -n "$TS_FILES" ]; then
153+
echo "$TS_FILES" | tr '\n' '\0' | xargs -0 npx eslint --max-warnings=0 --no-warn-ignored
154+
echo "$TS_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
155+
else
156+
echo "No TypeScript/JavaScript files found"
157+
fi
146158
elif [ "${{ steps.changed_files.outputs.ts_js_count }}" -gt "0" ]; then
147159
echo "Linting changed TypeScript/JavaScript files..."
148-
cat changed_ts_js.txt | xargs -r npx eslint --max-warnings=0 --no-warn-ignored
149-
cat changed_ts_js.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
160+
cat changed_ts_js.txt | tr '\n' '\0' | xargs -0 npx eslint --max-warnings=0 --no-warn-ignored
161+
cat changed_ts_js.txt | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
162+
else
163+
echo "No TypeScript/JavaScript files to lint"
150164
fi
151165
152166
- name: Lint Markdown files
@@ -155,12 +169,19 @@ jobs:
155169
run: |
156170
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
157171
echo "Linting all Markdown files..."
158-
git ls-files '*.md' | xargs -r npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
159-
git ls-files '*.md' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
172+
MD_FILES=$(git ls-files '*.md')
173+
if [ -n "$MD_FILES" ]; then
174+
echo "$MD_FILES" | tr '\n' '\0' | xargs -0 npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
175+
echo "$MD_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
176+
else
177+
echo "No Markdown files found"
178+
fi
160179
elif [ "${{ steps.changed_files.outputs.md_count }}" -gt "0" ]; then
161180
echo "Linting changed Markdown files..."
162-
cat changed_md.txt | xargs -r npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
163-
cat changed_md.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
181+
cat changed_md.txt | tr '\n' '\0' | xargs -0 npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
182+
cat changed_md.txt | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
183+
else
184+
echo "No Markdown files to lint"
164185
fi
165186
166187
- name: Lint JSON files
@@ -170,10 +191,22 @@ jobs:
170191
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
171192
echo "Linting all JSON files..."
172193
# Exclude Ignition deployment artifacts and other build artifacts
173-
git ls-files '*.json' | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; } | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
194+
JSON_FILES=$(git ls-files '*.json' | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; })
195+
if [ -n "$JSON_FILES" ]; then
196+
echo "$JSON_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
197+
else
198+
echo "No JSON files found"
199+
fi
174200
elif [ "${{ steps.changed_files.outputs.json_count }}" -gt "0" ]; then
175201
echo "Linting changed JSON files..."
176-
cat changed_json.txt | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; } | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
202+
JSON_FILES=$(cat changed_json.txt | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; })
203+
if [ -n "$JSON_FILES" ]; then
204+
echo "$JSON_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
205+
else
206+
echo "No JSON files to lint (after filtering build artifacts)"
207+
fi
208+
else
209+
echo "No JSON files to lint"
177210
fi
178211
179212
- name: Lint YAML files
@@ -182,12 +215,19 @@ jobs:
182215
run: |
183216
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
184217
echo "Linting all YAML files..."
185-
git ls-files '*.yml' '*.yaml' | xargs -r npx yaml-lint
186-
git ls-files '*.yml' '*.yaml' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
218+
YAML_FILES=$(git ls-files '*.yml' '*.yaml')
219+
if [ -n "$YAML_FILES" ]; then
220+
echo "$YAML_FILES" | tr '\n' '\0' | xargs -0 npx yaml-lint
221+
echo "$YAML_FILES" | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
222+
else
223+
echo "No YAML files found"
224+
fi
187225
elif [ "${{ steps.changed_files.outputs.yaml_count }}" -gt "0" ]; then
188226
echo "Linting changed YAML files..."
189-
cat changed_yaml.txt | xargs -r npx yaml-lint
190-
cat changed_yaml.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
227+
cat changed_yaml.txt | tr '\n' '\0' | xargs -0 npx yaml-lint
228+
cat changed_yaml.txt | tr '\n' '\0' | xargs -0 npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
229+
else
230+
echo "No YAML files to lint"
191231
fi
192232
193233
- name: Check lint results

0 commit comments

Comments
 (0)