Skip to content

Commit

Permalink
Add infrastructure for checking project filesystem
Browse files Browse the repository at this point in the history
There are differences in the filename restrictions between operating systems. The use of filenames that are not valid
on one operating system in the project will cause problems for contributors or users (e.g., not possible to check out
the repository).

Tasks are added to check for non-portable filenames:

- Presence of characters prohibited by an operating system in filenames
- Use of filenames reserved by an operating system

Tasks are also added to check for problems with symbolic links ("symlinks") contained in the project:

- Broken symlinks
- Circular symlinks

A GitHub Actions workflow is included to run the tasks on any change to the project files in order to avoid the
introduction of problems with the project filesystem, and periodically in order to catch breakage caused by external
changes.
  • Loading branch information
per1234 committed Oct 16, 2023
1 parent 1f76e82 commit c783b9a
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/check-files-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-files-task.md
name: Check Files

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
pull_request:
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 8 * * THU"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
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
check-filenames:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check filenames
run: task --silent general:check-filenames

check-symlinks:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check symlinks
run: task --silent general:check-symlinks
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ino-hardware-package-list

[![Check Files status](https://github.com/per1234/inoplatforms/actions/workflows/check-files-task.yml/badge.svg)](https://github.com/per1234/inoplatforms/actions/workflows/check-files-task.yml)
[![Check General Formatting status](https://github.com/per1234/inoplatforms/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/per1234/inoplatforms/actions/workflows/check-general-formatting-task.yml)
[![Check Go status](https://github.com/per1234/inoplatforms/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/per1234/inoplatforms/actions/workflows/check-go-task.yml)
[![Check License status](https://github.com/per1234/inoplatforms/actions/workflows/check-license.yml/badge.svg)](https://github.com/per1234/inoplatforms/actions/workflows/check-license.yml)
Expand Down
99 changes: 99 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ tasks:
desc: Check for problems with the project
deps:
- task: ci:validate
- task: general:check-filenames
- task: general:check-formatting
- task: general:check-spelling
- task: general:check-symlinks
- task: markdown:check-links
- task: markdown:lint
- task: npm:validate
Expand Down Expand Up @@ -66,6 +68,76 @@ tasks:
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
-d "{{.WORKFLOWS_DATA_PATH}}"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml

Check warning on line 71 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

71:121 [line-length] line too long (127 > 120 characters)
general:check-filenames:
desc: Check for non-portable filenames
cmds:
- |
find . \
-type d -name '.git' -prune -o \
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-exec \
sh \
-c \
' \
basename "$0" | \
grep \
--perl-regexp \
--regexp='"'"'([<>:"/\\|?*\x{0000}-\x{001F}])|(.+\.$)'"'"' \
--silent \
&& \
echo "$0"
' \
'{}' \
\; \
-execdir \
false \
'{}' \
+ \
|| \
{
echo
echo "Prohibited characters found in filenames"
echo "See:"
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=except%20for%20the%20following"

Check warning on line 104 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

104:121 [line-length] line too long (142 > 120 characters)
false
}
- |
find . \
-type d -name '.git' -prune -o \
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-exec \
sh \
-c \
' \
basename "$0" | \
grep \
--ignore-case \
--extended-regexp \
--regexp='"'"'^(con|prn|aux|nul|com[0-9]+|lpt[0-9]+)$'"'"' \
--silent \
&& \
echo "$0"
' \
'{}' \
\; \
-execdir \
false \
'{}' \
+ \
|| \
{
echo
echo "Reserved filenames found"
echo "See:"
echo "https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions:~:text=use%20the%20following-,reserved%20names,-for%20the%20name"

Check warning on line 137 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

137:121 [line-length] line too long (169 > 120 characters)
false
}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml

Check warning on line 141 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

141:121 [line-length] line too long (140 > 120 characters)
general:check-formatting:
desc: Check basic formatting style of all files
Expand All @@ -84,6 +156,33 @@ tasks:
cmds:
- poetry run codespell

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml

Check warning on line 159 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

159:121 [line-length] line too long (127 > 120 characters)
general:check-symlinks:
desc: Check for bad symlinks
cmds:
- |
find . \
-type d -name '.git' -prune -o \
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-type l \
-execdir \
test ! -e '{}' \
\; \
-exec \
echo '{}' \
\; \
-execdir \
false \
'{}' \
+ \
|| \
{
echo 'Broken or circular symlink found'
false
}
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml

Check warning on line 186 in Taskfile.yml

View workflow job for this annotation

GitHub Actions / Generate problem matcher output

186:121 [line-length] line too long (127 > 120 characters)
general:correct-spelling:
desc: Correct commonly misspelled words where possible
Expand Down

0 comments on commit c783b9a

Please sign in to comment.