Skip to content

Commit bc38434

Browse files
authored
Merge pull request #15 from generalui/fix/shellcheck-and-ci-workflow
fix: shellcheck errors in start.sh; add code-quality CI workflow
2 parents 9940c9a + 7e73644 commit bc38434

7 files changed

Lines changed: 161 additions & 4 deletions

File tree

.github/workflows/CODE_QUALITY.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Code Quality Workflow
2+
3+
## What it does
4+
5+
Lints Markdown files and shell scripts on every pull request to `main`. Also runnable manually via `workflow_dispatch`.
6+
7+
## When it runs
8+
9+
- Pull requests to `main` (opened, reopened, or synchronized) when any of the following paths change:
10+
- `**/*.md`
11+
- `**/.markdownlint*`
12+
- `*.sh`
13+
- `.github/workflows/code-quality.yml`
14+
- Manual trigger via the GitHub Actions UI
15+
16+
## Markdown linting
17+
18+
**Tool:** [`DavidAnson/markdownlint-cli2-action`](https://github.com/DavidAnson/markdownlint-cli2-action)
19+
20+
**Config file:** `.markdownlint-cli2.jsonc` (max line length 240, allowed inline HTML, excludes `CLAUDE.md` and `.github/copilot-instructions.md`)
21+
22+
**Run locally:**
23+
24+
```sh
25+
markdownlint-cli2 '**/*.md'
26+
```
27+
28+
## Shell script linting
29+
30+
**Tool:** [`reviewdog/action-shellcheck`](https://github.com/reviewdog/action-shellcheck) — posts inline PR review comments via `github-pr-review` reporter.
31+
32+
**Run locally:**
33+
34+
```sh
35+
shellcheck start.sh stop.sh reset_env_variables.sh
36+
```
37+
38+
**`.shellcheckrc` suppressions** (project-wide):
39+
40+
| Rule | Reason |
41+
| --- | --- |
42+
| `SC1091` | Not following sourced files (`reset_env_variables.sh`) |
43+
| `SC2153` | False positives on variable name misspelling |
44+
| `SC2317` | False positive on unreachable commands in trap/signal handlers |
45+
46+
## Adding new checks
47+
48+
1. Add a "Get changed files" step using `tj-actions/changed-files@v47` scoped to the relevant paths.
49+
2. Add a "Should lint X" step that writes the `any_changed` output to `$GITHUB_OUTPUT`.
50+
3. Add the lint step gated on `if: steps.should_lint_x.outputs.run == 'true'`.
51+
4. Update the paths filter under `on.pull_request.paths` to include the new file patterns.

.github/workflows/code-quality.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Code Quality
2+
on:
3+
pull_request:
4+
branches: [main]
5+
types: [opened, reopened, synchronize]
6+
paths:
7+
- '**/*.md'
8+
- '**/.markdownlint*'
9+
- '*.sh'
10+
- '.github/workflows/code-quality.yml'
11+
workflow_dispatch:
12+
jobs:
13+
quality:
14+
name: Lint and test
15+
timeout-minutes: 15
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v6
20+
with:
21+
fetch-depth: 0
22+
submodules: false
23+
24+
- name: Get changed markdown files
25+
id: changed_md
26+
uses: tj-actions/changed-files@v47
27+
with:
28+
files: |
29+
**/*.md
30+
31+
- name: Get changed shell scripts
32+
id: changed_sh
33+
uses: tj-actions/changed-files@v47
34+
with:
35+
files: |
36+
*.sh
37+
38+
- name: Should lint docs
39+
id: should_lint_docs
40+
shell: bash
41+
run: |
42+
run=${{ steps.changed_md.outputs.any_changed }}
43+
echo "run=${run}" >> $GITHUB_OUTPUT
44+
45+
- name: Should lint shell
46+
id: should_lint_shell
47+
shell: bash
48+
run: |
49+
run=${{ steps.changed_sh.outputs.any_changed }}
50+
echo "run=${run}" >> $GITHUB_OUTPUT
51+
52+
- name: Lint markdown
53+
if: steps.should_lint_docs.outputs.run == 'true'
54+
uses: DavidAnson/markdownlint-cli2-action@v22
55+
with:
56+
globs: '**/*.md'
57+
58+
- name: Lint shell scripts
59+
if: steps.should_lint_shell.outputs.run == 'true'
60+
uses: reviewdog/action-shellcheck@v1
61+
with:
62+
reporter: github-pr-review
63+
fail_on_error: true
64+
path: '.'
65+
pattern: '*.sh'
66+
exclude: './.git/*'
67+
68+
- name: Default Job Success
69+
if: steps.should_lint_docs.outputs.run != 'true' && steps.should_lint_shell.outputs.run != 'true'
70+
shell: bash
71+
run: exit 0

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
markdownlint-cli2 0.21.0
2+
shellcheck 0.11.0

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,7 @@ Example usage:
118118
### Linting
119119

120120
See [LINTING.md](./documentation/LINTING.md)
121+
122+
## Other Documentation
123+
124+
See [documentation](./documentation/)

documentation/CICD.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ci/Cd
2+
3+
See [CODE_QUALITY.md](../.github/workflows/CODE_QUALITY.md)

documentation/LINTING.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,45 @@
66

77
- Markdownlint must be installed as an extension (extension id: `DavidAnson.vscode-markdownlint`) for local markdown linting to work within VS Code or Cursor on save.
88
- Or run in directly using [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2).
9-
- `markdownlint-cli2` is included in the asdf tool versions file.
9+
- `markdownlint-cli2` is included in the asdf [`.tool-versions`](../.tool-versions) file.
1010
See <https://github.com/paulo-ferraz-oliveira/asdf-markdownlint-cli2>.
1111

1212
```sh
1313
markdownlint-cli2 '**/*.md'
1414
```
1515

16+
- [ShellCheck](https://github.com/koalaman/shellcheck) `timonwong.shellcheck`
17+
18+
- ShellCheck must be installed as an extension (extension id: `timonwong.shellcheck`) for local shell script linting to work within VS Code or Cursor on save.
19+
- Or run it directly using the [ShellCheck CLI](https://github.com/koalaman/shellcheck#installing).
20+
- `shellcheck` is included in the asdf [`.tool-versions`](../.tool-versions) file.
21+
22+
```sh
23+
shellcheck *.sh
24+
```
25+
1626
## Configuration
1727

28+
### Markdown
29+
1830
MarkdownLint uses [`.markdownlint-cli2.jsonc`](../..markdownlint-cli2.jsonc) to configure the markdown linting rules and to ignore linting for specific files and paths.
1931
See <https://github.com/DavidAnson/markdownlint-cli2/tree/main?tab=readme-ov-file#markdownlint-cli2jsonc>
2032

33+
### Shell
34+
35+
ShellCheck uses [`.shellcheckrc`](../.shellcheckrc) to configure linting rules.
36+
The following rules are disabled project-wide:
37+
38+
| Rule | Reason |
39+
| --- | --- |
40+
| `SC1091` | Suppresses "not following" warnings for sourced files (e.g. `reset_env_variables.sh`) |
41+
| `SC2153` | Suppresses false-positive variable name misspelling warnings |
42+
| `SC2317` | Suppresses unreachable-command false positives in trap/signal handlers |
43+
44+
`external-sources=true` is also set to allow ShellCheck to follow sourced files when they are available.
45+
46+
See <https://github.com/koalaman/shellcheck/wiki/Checks>
47+
2148
## Continuous Integration
2249

2350
Linting is automatically run in CI/CD via the [Code Quality workflow](../.github/workflows/code-quality.yml) on pull requests to `main`.

start.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function start() {
9191
# Cursor invisible
9292
tput civis
9393
while sleep 0.1; do
94-
i=$(((i + $charwidth) % ${#char}))
94+
i=$(((i + charwidth) % ${#char}))
9595
printf "%s" "${char:$i:$charwidth}"
9696
echo -en "\033[1D"
9797
done
@@ -120,7 +120,7 @@ function start() {
120120
function check_status() {
121121
local max_num_tries=35
122122
local status_code
123-
status_code=$(curl --write-out %{http_code} --silent --output /dev/null localhost:"${pga_port}")
123+
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:"${pga_port}")
124124
if [[ ${iterator} -lt ${max_num_tries} && ${status_code} -eq 200 || ${status_code} -eq 302 ]]
125125
then
126126
# Stop the progress indicator.
@@ -140,7 +140,7 @@ function start() {
140140
tput cnorm
141141
>&2 echo -e "${yellow}Did not work. Perhaps the server is taking a long time to start?${nc}"
142142
else
143-
echo -en "${chars:$iterator:1}" "\r"
143+
echo -en "${char:$iterator:1}" "\r"
144144
sleep 1
145145
((iterator++))
146146
check_status

0 commit comments

Comments
 (0)