Skip to content

Commit dc103f4

Browse files
authored
Add bats-core and helper libraries to ci-tools image (#60)
* Add bats-core and helper libraries to ci-tools image Install bats and git from apt, then shallow-clone bats-support, bats-assert, and bats-file into /usr/lib/bats/ at pinned tags. Set BATS_LIB_PATH so bats_load_library finds helpers automatically. * Link tools in README table to their project pages
1 parent 122c8b4 commit dc103f4

File tree

6 files changed

+65
-12
lines changed

6 files changed

+65
-12
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ CI pipelines. Published to GHCR at `ghcr.io/knight-owl-dev/ci-tools`.
2525

2626
| Tool | Purpose |
2727
| --- | --- |
28-
| shellcheck | Shell script linting |
29-
| shfmt | Shell script formatting |
30-
| actionlint | GitHub Actions workflow linting |
31-
| hadolint | Dockerfile linting |
32-
| markdownlint-cli2 | Markdown linting |
33-
| biome | JavaScript/TypeScript linting |
34-
| stylelint | CSS linting |
35-
| luacheck | Lua script linting |
36-
| chktex | LaTeX document linting |
28+
| [shellcheck](https://github.com/koalaman/shellcheck) | Shell script linting |
29+
| [shfmt](https://github.com/mvdan/sh) | Shell script formatting |
30+
| [actionlint](https://github.com/rhysd/actionlint) | GitHub Actions workflow linting |
31+
| [hadolint](https://github.com/hadolint/hadolint) | Dockerfile linting |
32+
| [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) | Markdown linting |
33+
| [biome](https://github.com/biomejs/biome) | JavaScript/TypeScript linting |
34+
| [stylelint](https://github.com/stylelint/stylelint) | CSS linting |
35+
| [luacheck](https://github.com/lunarmodules/luacheck) | Lua script linting |
36+
| [chktex](https://www.nongnu.org/chktex/) | LaTeX document linting |
37+
| [bats](https://github.com/bats-core/bats-core) | Shell script test framework with bats-support, bats-assert, bats-file helper libraries |
38+
| [git](https://git-scm.com) | Version control (build-time cloning and runtime use) |
3739
| validate-action-pins | GitHub Actions SHA pin verification |
38-
| make | Build automation |
40+
| [make](https://www.gnu.org/software/make/) | Build automation |
3941

4042
Pinned versions and checksums are tracked in
4143
[`images/ci-tools/versions.lock`](images/ci-tools/versions.lock).
@@ -112,6 +114,7 @@ respective communities:
112114
- [luacheck](https://github.com/lunarmodules/luacheck) by Lunar Modules (MIT)
113115
- [stylelint](https://github.com/stylelint/stylelint) by stylelint contributors (MIT)
114116
- [ChkTeX](https://www.nongnu.org/chktex/) by ChkTeX contributors (GPLv2+)
117+
- [bats-core](https://github.com/bats-core/bats-core) by bats-core contributors (MIT)
115118

116119
## License
117120

images/ci-tools/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN apt-get update \
1717
ca-certificates \
1818
luarocks \
1919
gcc \
20+
bats \
21+
git \
2022
&& apt-get clean \
2123
&& rm -rf /var/lib/apt/lists/*
2224

@@ -81,6 +83,19 @@ RUN luarocks install luacheck "${LUACHECK_VERSION}" \
8183
&& apt-get purge -y --auto-remove gcc \
8284
&& rm -rf /var/lib/apt/lists/*
8385

86+
# ---------- bats helpers ----------
87+
ARG BATS_SUPPORT_VERSION
88+
ARG BATS_ASSERT_VERSION
89+
ARG BATS_FILE_VERSION
90+
RUN git clone --depth 1 --branch "${BATS_SUPPORT_VERSION}" \
91+
https://github.com/bats-core/bats-support /usr/lib/bats/bats-support \
92+
&& git clone --depth 1 --branch "${BATS_ASSERT_VERSION}" \
93+
https://github.com/bats-core/bats-assert /usr/lib/bats/bats-assert \
94+
&& git clone --depth 1 --branch "${BATS_FILE_VERSION}" \
95+
https://github.com/bats-core/bats-file /usr/lib/bats/bats-file \
96+
&& rm -rf /usr/lib/bats/*/.git
97+
ENV BATS_LIB_PATH=/usr/lib/bats
98+
8499
# ---------- validate-action-pins ----------
85100
ARG VALIDATE_ACTION_PINS_VERSION
86101
ENV VALIDATE_ACTION_PINS_VERSION=${VALIDATE_ACTION_PINS_VERSION}

images/ci-tools/compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ services:
2020
BIOME_VERSION: ${BIOME_VERSION}
2121
STYLELINT_VERSION: ${STYLELINT_VERSION}
2222
LUACHECK_VERSION: ${LUACHECK_VERSION}
23+
BATS_SUPPORT_VERSION: ${BATS_SUPPORT_VERSION}
24+
BATS_ASSERT_VERSION: ${BATS_ASSERT_VERSION}
25+
BATS_FILE_VERSION: ${BATS_FILE_VERSION}
2326
VALIDATE_ACTION_PINS_VERSION: ${VALIDATE_ACTION_PINS_VERSION}

images/ci-tools/versions.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ MARKDOWNLINT_CLI2_VERSION=0.21.0
1111
BIOME_VERSION=2.4.1
1212
STYLELINT_VERSION=17.3.0
1313
LUACHECK_VERSION=1.2.0-1
14+
BATS_SUPPORT_VERSION=v0.3.0
15+
BATS_ASSERT_VERSION=v2.2.4
16+
BATS_FILE_VERSION=v0.4.0
1417
VALIDATE_ACTION_PINS_VERSION=local

scripts/ci-tools/resolve.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ resolve_luacheck() {
115115
LUACHECK_VERSION="${version}"
116116
}
117117

118+
resolve_bats_support() {
119+
local tag="${1:-}"
120+
[[ -z "${tag}" ]] && tag="$(latest_gh_tag bats-core/bats-support)"
121+
BATS_SUPPORT_VERSION="${tag}"
122+
}
123+
124+
resolve_bats_assert() {
125+
local tag="${1:-}"
126+
[[ -z "${tag}" ]] && tag="$(latest_gh_tag bats-core/bats-assert)"
127+
BATS_ASSERT_VERSION="${tag}"
128+
}
129+
130+
resolve_bats_file() {
131+
local tag="${1:-}"
132+
[[ -z "${tag}" ]] && tag="$(latest_gh_tag bats-core/bats-file)"
133+
BATS_FILE_VERSION="${tag}"
134+
}
135+
118136
resolve_validate_action_pins() {
119137
VALIDATE_ACTION_PINS_VERSION="$(resolve_local \
120138
"${VALIDATE_ACTION_PINS_VERSION}" "${1:-}")"
@@ -123,7 +141,7 @@ resolve_validate_action_pins() {
123141
# ── argument parsing ─────────────────────────────────────────────────
124142

125143
# Determine which tools to resolve and whether a version is pinned.
126-
ALL_TOOLS=(shfmt actionlint hadolint markdownlint-cli2 biome stylelint luacheck validate-action-pins)
144+
ALL_TOOLS=(shfmt actionlint hadolint markdownlint-cli2 biome stylelint luacheck bats-support bats-assert bats-file validate-action-pins)
127145
TOOLS_TO_RESOLVE=()
128146
declare -A PINNED_VERSIONS=()
129147

@@ -133,7 +151,7 @@ else
133151
for arg in "${@}"; do
134152
tool="${arg%%:*}"
135153
case "${tool}" in
136-
shfmt | actionlint | hadolint | markdownlint-cli2 | biome | stylelint | luacheck | validate-action-pins) ;;
154+
shfmt | actionlint | hadolint | markdownlint-cli2 | biome | stylelint | luacheck | bats-support | bats-assert | bats-file | validate-action-pins) ;;
137155
*) die "unknown tool: ${tool}. Valid tools: ${ALL_TOOLS[*]}" ;;
138156
esac
139157
TOOLS_TO_RESOLVE+=("${tool}")
@@ -152,6 +170,7 @@ MARKDOWNLINT_CLI2_VERSION=""
152170
BIOME_VERSION=""
153171
STYLELINT_VERSION=""
154172
LUACHECK_VERSION=""
173+
BATS_SUPPORT_VERSION="" BATS_ASSERT_VERSION="" BATS_FILE_VERSION=""
155174
VALIDATE_ACTION_PINS_VERSION=""
156175

157176
if [[ -f "${LOCKFILE}" ]]; then
@@ -185,6 +204,9 @@ MARKDOWNLINT_CLI2_VERSION=${MARKDOWNLINT_CLI2_VERSION}
185204
BIOME_VERSION=${BIOME_VERSION}
186205
STYLELINT_VERSION=${STYLELINT_VERSION}
187206
LUACHECK_VERSION=${LUACHECK_VERSION}
207+
BATS_SUPPORT_VERSION=${BATS_SUPPORT_VERSION}
208+
BATS_ASSERT_VERSION=${BATS_ASSERT_VERSION}
209+
BATS_FILE_VERSION=${BATS_FILE_VERSION}
188210
VALIDATE_ACTION_PINS_VERSION=${VALIDATE_ACTION_PINS_VERSION}
189211
EOF
190212
mv "${LOCKFILE_TMP}" "${LOCKFILE}"

scripts/ci-tools/verify.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ check "mandoc" "" command -v mandoc
3737
check "stylelint" "${STYLELINT_VERSION}" stylelint --version
3838
check "validate-action-pins" "${VALIDATE_ACTION_PINS_VERSION}" \
3939
validate-action-pins --version
40+
check "bats" "" bats --version
41+
# Bats helpers are shallow-cloned by tag at build time with .git removed after.
42+
# No version command exists at runtime, so we can only confirm presence.
43+
check "bats-support" "" ls /usr/lib/bats/bats-support/load.bash
44+
check "bats-assert" "" ls /usr/lib/bats/bats-assert/load.bash
45+
check "bats-file" "" ls /usr/lib/bats/bats-file/load.bash
46+
check "git" "" git --version
4047
check "make" "" make --version
4148
verify_exit

0 commit comments

Comments
 (0)