-
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (95 loc) · 3.69 KB
/
main.yml
File metadata and controls
115 lines (95 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Bash Project CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
name: Lint Bash Scripts with ShellCheck
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout Code
uses: actions/checkout@v3
# Install ShellCheck
- name: Install ShellCheck
run: |
sudo apt update
sudo apt install -y shellcheck
# Run ShellCheck on all scripts
- name: Run ShellCheck
run: |
set -eo pipefail
find . -name "*.sh" ! -path "./.git/*" -print0 | xargs -0 shellcheck --shell=bash --external-sources -x \
--severity=style \
--exclude=SC1090,SC1091,SC2034,SC2181
format:
name: Check Formatting with shfmt
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout Code
uses: actions/checkout@v3
# Install shfmt
- name: Install shfmt
run: |
sudo apt update
sudo apt install -y shfmt
# Run shfmt to check formatting
- name: Run shfmt
run: |
find . -type f -name "*.sh" -print0 | xargs -0 shfmt -i 4 -ci -bn -sr -kp -ln bash -d
# Explanation of flags:
# ---------------------
# -i 4 # Indent with 4 spaces (default is 2). Ensures consistent indentation style.
# -ci # Indent `case` blocks (useful for readability within `case` statements).
# -bn # Keep `do`, `then`, and similar keywords on the same line as the preceding command.
# # Example: `if true; then` instead of splitting to `if true; \n then`.
# -kp # Preserve padding in alignment for tables or comments (helps keep things visually aligned).
# # Example:
# # VAR1="value1" # aligned comment
# # VAR2="value2"
# -ln bash # Specify the shell dialect as `bash` (default is `posix` for maximum portability).
# # Ensures proper parsing for Bash-specific features.
# -d # Diff mode: Show differences between the current script formatting and the `shfmt` output.
# # This is useful in CI pipelines or for dry runs to check formatting issues without modifying files.
# Notes:
# - Remove the `-d` flag if you want shfmt to automatically apply formatting instead of displaying diffs.
validate_permissions:
name: Validate File Permissions and Shebangs
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout Code
uses: actions/checkout@v3
# Ensure all shell scripts are executable
- name: Ensure Executable Permissions
run: |
find . -name "*.sh" -exec chmod +x {} \;
# Validate all scripts have a shebang
- name: Validate Shebangs
run: |
missing_shebangs=$(find . -name "*.sh" ! -path "./lib/common_core/*" ! -path "./dotfiles/bash-preexec.sh" ! -path "./another/ignored-file.sh" -exec sh -c 'head -n 1 "$1" | grep -q "^#!" || echo "Missing shebang: $1"' _ {} \;)
if [[ -n "$missing_shebangs" ]]; then
echo "The following files are missing a shebang:"
echo "$missing_shebangs"
exit 1
fi
# run_bats_unit_tests:
# name: Run BATS Unit Tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v3
# # Install BATS if not included as a submodule
# - name: Install BATS
# run: |
# sudo apt-get update
# sudo apt-get install -y bats
# # Run the BATS Tests
# - name: Run BATS Tests
# run: |
# bats tests/unit