Skip to content

Commit

Permalink
Linting for shell and GitHub Actions (#206)
Browse files Browse the repository at this point in the history
* Setup shell lint action
* Fix CMake lint
* Apply shellcheck
* Setup Actions linter
* Apply lint fixes for workflows
* Run Windows workflow when .bat files are changed, not .sh files
* Pin zizmor version
* Update dev docs for linters
  • Loading branch information
jwallwork23 authored Dec 18, 2024
1 parent 13e12e2 commit 11dcd03
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
with:
persist-credentials: false
uses: actions/checkout@v4

- name: Install Python
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fypp_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: actions/setup-python@v4
with:
python-version: "3.11"
Expand Down
26 changes: 24 additions & 2 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ on:
# Triggers the workflow on pushes to open pull requests with code changes
pull_request:
paths:
- '.github/workflows/static_analysis.yml'
- '.github/workflows/*.yml'
- '**.c'
- '**.cpp'
- '**.fypp'
- '**.f90'
- '**.F90'
- '**.pf'
- '**.py'
- '**.sh'
- '**CMakeLists.txt'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -35,6 +37,8 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
with:
persist-credentials: false
uses: actions/checkout@v4

- name: Install Python
Expand Down Expand Up @@ -63,13 +67,31 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${BUILD_DIR} -DCMAKE_Fortran_FLAGS="-std=f2008" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Apply CMake linter, cmake-lint
- name: cmake
- name: cmake-lint
if: always()
run: |
cd ${{ github.workspace }}
. ftorch_venv/bin/activate
cmake-lint $(find . -name CMakeLists.txt)
# Apply Shell linter, shellcheck
- name: shellcheck
if: always()
run: |
cd ${{ github.workspace }}
sudo apt install shellcheck
for FILE in $(find . -name "*.sh"); do
shellcheck ${FILE}
done
# Apply GitHub Actions linter, zizmor
- name: zizmor
if: always()
run: |
cd ${{ github.workspace }}
. ftorch_venv/bin/activate
zizmor .github/workflows/*.yml
# Apply Fortran linter, fortitude
# Configurable using the fortitude.toml file if present
- name: fortitude source
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_suite_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
with:
persist-credentials: false
uses: actions/checkout@v4

- name: Install Python
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test_suite_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ on:
pull_request:
paths:
- '.github/workflows/test_suite_windows.yml'
- '**.bat'
- '**.c'
- '**.cpp'
- '**.fypp'
- '**.f90'
- '**.F90'
- '**.pf'
- '**.py'
- '**.sh'
- '**CMakeLists.txt'
- '**requirements.txt'
- '**data/*'
Expand Down Expand Up @@ -53,6 +53,8 @@ jobs:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout code
with:
persist-credentials: false
uses: actions/checkout@v4

- name: Install Python
Expand Down
8 changes: 8 additions & 0 deletions pages/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@ The tools we use are as follows on a language-by-language basis:
* C++: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
* C: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
* Python: [ruff](https://docs.astral.sh/ruff/)
* Shell: [ShellCheck](https://github.com/koalaman/shellcheck)
* CMake: [cmake-format](https://github.com/cheshirekow/cmake_format)
* GitHub Actions workflows: [zizmor](https://woodruffw.github.io/zizmor)

Instructions on installing these tools can be found in their respective documentations.
Note that all but ShellCheck may be installed with pip. A shortcut for doing
this is to run the following from the base FTorch directory:
```
pip install -r requirements.txt
```

Contributors should run them over their code and ensure that it conforms before submitting
a pull request. If there is a good reason to ignore a particular rule this should be
justified in the pull request and ideally documented in the code.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ fortitude-lint==0.6.0
clang-format==19.1.3
clang-tidy==19.1.0
cmakelang
zizmor==0.9.2
7 changes: 3 additions & 4 deletions run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

set -eu

CTEST_ARGS=$@
EXAMPLES="1_SimpleNet 2_ResNet18 4_MultiIO 6_Autograd"
BUILD_DIR=src/build

for EXAMPLE in ${EXAMPLES}; do
pip -q install -r examples/${EXAMPLE}/requirements.txt
cd ${BUILD_DIR}/test/examples/${EXAMPLE}
ctest ${CTEST_ARGS}
pip -q install -r examples/"${EXAMPLE}"/requirements.txt
cd "${BUILD_DIR}"/test/examples/"${EXAMPLE}"
ctest "$@"
cd -
done

0 comments on commit 11dcd03

Please sign in to comment.