Skip to content

ci: run shellcheck on shell scripts [WPB-8645] - #5630

Merged
yamilmedina merged 2 commits into
developfrom
chore/shellcheck
Dec 4, 2026
Merged

yamilmedina merged 2 commits into
developfrom
chore/shellcheck

Conversation

@yamilmedina

@yamilmedina yamilmedina commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

https://wearezeta.atlassian.net/browse/WPB-8645

Pitch me the changes

CI now runs shellcheck on our shell scripts, the same check Kalium added in wireapp/kalium#4836. The scripts that had findings are fixed, so the new check passes from day one, and the scripts behave the same as before.

Ticket: WPB-30201

Problems

.pre-commit-config.yaml already has a shellcheck hook, but CI never runs it. On develop the tracked scripts have 51 findings with shellcheck 0.11.0 and 60 with 0.9.0, the version on ubuntu-latest.

Changes

  • A new ShellCheck workflow runs on pull requests and in the merge queue. It checks every tracked .sh file and the hooks in .githooks/. git ls-files does not go into the kalium submodule, which has its own check. gradlew is generated, so it is left out.
  • The findings in 8 scripts are fixed. Most fixes add quotes, read -r, find -print0 | xargs -0, or split local x=$(...) into a declaration and an assignment.

Solution

  • grep -c and set -e: in wire-apk-wrapper.sh, grep | wc -l became grep -c ... || true. grep -c exits 1 when nothing matches, and after the declaration split that would stop the script under set -e.
  • Removed $? checks: in wire-apk-wrapper.sh these checks could never run, because set -e already stops the script on the failed command. Exit behavior is the same.
  • Array for an optional flag: docker-agent/builder.sh keeps --stacktrace as an array, so it is still passed as its own argument and dropped when unset.
  • Disabled checks, each with a reason:
    • a trap handler in run_ui_tests.sh that shellcheck thinks is unused;
    • TEST_APP_ID and TEST_APK_PATH, which come from GITHUB_ENV;
    • an ls -t that sorts by modification time;
    • local temp_dir=$(mktemp -d), where splitting would make a mktemp failure fatal.

Verification

  • Lint: shellcheck exits 0 on this branch with 0.9.0 and 0.11.0. The same command fails on develop with both versions. actionlint is clean on the new workflow.
  • Same results: the old and new versions ran side by side with stubs for gradlew, apksigner, apktool and adb. Output and exit codes matched for validate_apk_integrity (matching, missing-dex and missing-file APKs), resolve-test-apk-path (0, 1 and 2 APKs), the builder.sh arguments with and without --stacktrace, and new-feature-module.sh in a scratch repo.
  • Independent review: a second agent re-ran these comparisons and checked each disable directive against the findings on develop. It found nothing blocking.
  • Python tests: scripts/qa/android-ui has 127 tests and 1 failure (http://[invalid]). develop has the same failure.
  • Not run: the real apktool, apksigner, adb and Docker agent flows, and the scripts on bash 5. Locally only bash 3.2 was available.

Notes

  • Edge cases that now work: a value with spaces or a backslash, such as a keystore password, is now passed whole. Before, it was split or lost the backslash. Normal values give the same result.
  • One lost stderr line: when no test APK exists, resolve-test-apk-path no longer prints the ls: No such file line. The error message and exit code are the same.
  • Ticket: this uses the Kalium ticket, WPB-30201. Tell me if Android needs its own.

For the reviewer

We already had shellcheck in pre-commit, but nobody was forced to run it, so the scripts piled up warnings. This PR makes CI run it on every PR and cleans up the existing warnings so it starts green. The fixes are mostly "put quotes around variables." Look closest at scripts/dev/wire-apk-wrapper.sh: it has the most changes, and the || true and removed $? checks there are the only spots where the logic moved.

Fix every finding from shellcheck 0.9.0 and 0.11.0 on tracked shell
scripts, keeping behavior the same:

- Quote expansions, and use an array for the optional gradle
  --stacktrace flag in docker-agent/builder.sh.
- Split local declarations from assignments. Add `|| true` where
  `grep -c` ends the pipeline, because it exits 1 on zero matches.
- Delete `$?` checks that set -e already made unreachable.
- Use read -r, find -print0 | xargs -0, and a glob instead of ls.
- Disable a check with a reason where it reports a false positive
  (trap handler, GITHUB_ENV variables, ls -t mtime sort) or where
  the fix would change behavior (mktemp failure under set -e).
Run shellcheck on pull requests and in the merge queue. It checks
every tracked .sh file and the Git hooks in .githooks/. git ls-files
does not descend into the kalium submodule, which runs its own check.
@yamilmedina
yamilmedina requested a review from a team as a code owner December 3, 2026 11:44
@yamilmedina
yamilmedina requested review from Garzas and ohassine and removed request for a team December 3, 2026 11:44
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.98%. Comparing base (58ba90e) to head (7595f50).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5630      +/-   ##
===========================================
- Coverage    56.99%   56.98%   -0.01%     
===========================================
  Files          818      818              
  Lines        28491    28491              
  Branches      4401     4401              
===========================================
- Hits         16238    16237       -1     
  Misses       10837    10837              
- Partials      1416     1417       +1     

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58ba90e...7595f50. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yamilmedina yamilmedina changed the title ci: run shellcheck on shell scripts [WPB-30201] ci: run shellcheck on shell scripts [WPB-8645] Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Test Results

  372 files  ±0    372 suites  ±0   2m 1s ⏱️ -2s
3 318 tests ±0  3 318 ✅ ±0  0 💤 ±0  0 ❌ ±0 
3 330 runs  ±0  3 330 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 7595f50. ± Comparison against base commit 58ba90e.

@yamilmedina yamilmedina self-assigned this Dec 3, 2026
@yamilmedina
yamilmedina merged commit 4abf2fa into develop Dec 4, 2026
33 checks passed
@yamilmedina
yamilmedina deleted the chore/shellcheck branch December 4, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant