Skip to content

Commit 25f53d8

Browse files
authored
Merge pull request #113 from per1234/check-files
Add infrastructure for checking project filesystem
2 parents a749529 + 5906a12 commit 25f53d8

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-files-task.md
2+
name: Check Files
3+
4+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
5+
on:
6+
create:
7+
push:
8+
pull_request:
9+
schedule:
10+
# Run periodically to catch breakage caused by external changes.
11+
- cron: "0 8 * * THU"
12+
workflow_dispatch:
13+
repository_dispatch:
14+
15+
jobs:
16+
run-determination:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
result: ${{ steps.determination.outputs.result }}
20+
steps:
21+
- name: Determine if the rest of the workflow should run
22+
id: determination
23+
run: |
24+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
25+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
26+
if [[
27+
"${{ github.event_name }}" != "create" ||
28+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
29+
]]; then
30+
# Run the other jobs.
31+
RESULT="true"
32+
else
33+
# There is no need to run the other jobs.
34+
RESULT="false"
35+
fi
36+
37+
echo "result=$RESULT" >> $GITHUB_OUTPUT
38+
39+
check-filenames:
40+
needs: run-determination
41+
if: needs.run-determination.outputs.result == 'true'
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v3
47+
48+
- name: Install Task
49+
uses: arduino/setup-task@v1
50+
with:
51+
repo-token: ${{ secrets.GITHUB_TOKEN }}
52+
version: 3.x
53+
54+
- name: Check filenames
55+
run: task --silent general:check-filenames
56+
57+
check-symlinks:
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v3
65+
66+
- name: Install Task
67+
uses: arduino/setup-task@v1
68+
with:
69+
repo-token: ${{ secrets.GITHUB_TOKEN }}
70+
version: 3.x
71+
72+
- name: Check symlinks
73+
run: task --silent general:check-symlinks

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# `arduino/compile-sketches` action
22

33
[![Check Action Metadata status](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml)
4+
[![Check Files status](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml)
45
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
56
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
67
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)

Taskfile.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,76 @@ tasks:
4141
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
4242
-d "action.yml"
4343
44+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml
45+
general:check-filenames:
46+
desc: Check for non-portable filenames
47+
cmds:
48+
- |
49+
find . \
50+
-type d -name '.git' -prune -o \
51+
-type d -name '.licenses' -prune -o \
52+
-type d -name '__pycache__' -prune -o \
53+
-type d -name 'node_modules' -prune -o \
54+
-exec \
55+
sh \
56+
-c \
57+
' \
58+
basename "$0" | \
59+
grep \
60+
--perl-regexp \
61+
--regexp='"'"'([<>:"/\\|?*\x{0000}-\x{001F}])|(.+\.$)'"'"' \
62+
--silent \
63+
&& \
64+
echo "$0"
65+
' \
66+
'{}' \
67+
\; \
68+
-execdir \
69+
false \
70+
'{}' \
71+
+ \
72+
|| \
73+
{
74+
echo
75+
echo "Prohibited characters found in filenames"
76+
echo "See:"
77+
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=except%20for%20the%20following"
78+
false
79+
}
80+
- |
81+
find . \
82+
-type d -name '.git' -prune -o \
83+
-type d -name '.licenses' -prune -o \
84+
-type d -name '__pycache__' -prune -o \
85+
-type d -name 'node_modules' -prune -o \
86+
-exec \
87+
sh \
88+
-c \
89+
' \
90+
basename "$0" | \
91+
grep \
92+
--ignore-case \
93+
--extended-regexp \
94+
--regexp='"'"'^(con|prn|aux|nul|com[0-9]+|lpt[0-9]+)$'"'"' \
95+
--silent \
96+
&& \
97+
echo "$0"
98+
' \
99+
'{}' \
100+
\; \
101+
-execdir \
102+
false \
103+
'{}' \
104+
+ \
105+
|| \
106+
{
107+
echo
108+
echo "Reserved filenames found"
109+
echo "See:"
110+
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=use%20the%20following-,reserved%20names,-for%20the%20name"
111+
false
112+
}
113+
44114
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
45115
general:check-spelling:
46116
desc: Check for commonly misspelled words
@@ -51,6 +121,33 @@ tasks:
51121
cmds:
52122
- poetry run codespell
53123

124+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml
125+
general:check-symlinks:
126+
desc: Check for bad symlinks
127+
cmds:
128+
- |
129+
find . \
130+
-type d -name '.git' -prune -o \
131+
-type d -name '.licenses' -prune -o \
132+
-type d -name '__pycache__' -prune -o \
133+
-type d -name 'node_modules' -prune -o \
134+
-type l \
135+
-execdir \
136+
test ! -e '{}' \
137+
\; \
138+
-exec \
139+
echo '{}' \
140+
\; \
141+
-execdir \
142+
false \
143+
'{}' \
144+
+ \
145+
|| \
146+
{
147+
echo 'Broken or circular symlink found'
148+
false
149+
}
150+
54151
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
55152
general:correct-spelling:
56153
desc: Correct commonly misspelled words where possible

0 commit comments

Comments
 (0)