Skip to content

Commit 4a1241d

Browse files
committed
Install lint tools in CI
1 parent 52073b6 commit 4a1241d

4 files changed

Lines changed: 151 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
8+
jobs:
9+
lint-and-test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Install lint tools
16+
run: ./test/install-tools.sh
17+
18+
- name: Validate script syntax
19+
run: ./test/validate-scripts.sh
20+
21+
- name: ShellCheck
22+
run: shellcheck run.sh start_squid.sh test/detect-proxy.sh test/test-proxy.sh test/validate-scripts.sh
23+
24+
- name: Hadolint
25+
run: hadolint Dockerfile test/Dockerfile
26+
27+
- name: Build proxy image
28+
run: docker build -t docker-proxy .
29+
30+
- name: Build test image
31+
run: docker build -t docker-proxy-test ./test

AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Agent Notes
2+
3+
This file tracks agent updates for the repository.
4+
5+
- Last updated: 2025-09-20
6+
- Updates:
7+
- Added CI workflow, script validation, and lint automation.
8+
- Added lint tool installer and updated CI to use it.
9+
- Added latest-version installer with apt fallback for lint tools.
10+
- Expanded script validation to cover the lint tool installer.

test/install-tools.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
install_dir=${INSTALL_DIR:-/usr/local/bin}
6+
7+
mkdir -p "$install_dir"
8+
9+
fetch_latest_tag() {
10+
local repo="$1"
11+
curl -fsSL "https://api.github.com/repos/${repo}/releases/latest" \
12+
| awk -F '"' '/"tag_name"/ { print $4; exit }'
13+
}
14+
15+
install_shellcheck() {
16+
local tag
17+
local arch
18+
local tarball
19+
local tmp_dir
20+
21+
tag=$(fetch_latest_tag "koalaman/shellcheck")
22+
if [[ -z "$tag" ]]; then
23+
return 1
24+
fi
25+
arch=$(uname -m)
26+
case "$arch" in
27+
x86_64) arch="x86_64" ;;
28+
aarch64|arm64) arch="aarch64" ;;
29+
*)
30+
echo "Unsupported architecture for shellcheck: $arch" >&2
31+
exit 1
32+
;;
33+
esac
34+
35+
tarball="shellcheck-${tag}.linux.${arch}.tar.xz"
36+
tmp_dir=$(mktemp -d)
37+
if ! curl -fsSL -o "${tmp_dir}/${tarball}" \
38+
"https://github.com/koalaman/shellcheck/releases/download/${tag}/${tarball}"; then
39+
rm -rf "$tmp_dir"
40+
return 1
41+
fi
42+
tar -xJf "${tmp_dir}/${tarball}" -C "$tmp_dir"
43+
mv "${tmp_dir}/shellcheck-${tag}/shellcheck" "${install_dir}/shellcheck"
44+
chmod +x "${install_dir}/shellcheck"
45+
rm -rf "$tmp_dir"
46+
}
47+
48+
install_hadolint() {
49+
local tag
50+
local arch
51+
local os
52+
local binary
53+
54+
tag=$(fetch_latest_tag "hadolint/hadolint")
55+
if [[ -z "$tag" ]]; then
56+
return 1
57+
fi
58+
os="Linux"
59+
arch=$(uname -m)
60+
case "$arch" in
61+
x86_64) arch="x86_64" ;;
62+
aarch64|arm64) arch="arm64" ;;
63+
*)
64+
echo "Unsupported architecture for hadolint: $arch" >&2
65+
exit 1
66+
;;
67+
esac
68+
69+
binary="hadolint-${os}-${arch}"
70+
if ! curl -fsSL -o "${install_dir}/hadolint" \
71+
"https://github.com/hadolint/hadolint/releases/download/${tag}/${binary}"; then
72+
return 1
73+
fi
74+
chmod +x "${install_dir}/hadolint"
75+
}
76+
77+
if ! install_shellcheck; then
78+
echo "Falling back to apt for shellcheck" >&2
79+
apt-get update
80+
apt-get install -y shellcheck
81+
fi
82+
83+
if ! install_hadolint; then
84+
echo "Falling back to apt for hadolint" >&2
85+
apt-get update
86+
apt-get install -y hadolint
87+
fi
88+
89+
shellcheck --version
90+
hadolint --version

test/validate-scripts.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
scripts=(
6+
"run.sh"
7+
"start_squid.sh"
8+
"test/install-tools.sh"
9+
"test/detect-proxy.sh"
10+
"test/test-proxy.sh"
11+
)
12+
13+
for script in "${scripts[@]}"; do
14+
if [[ ! -f "$script" ]]; then
15+
echo "Missing script: $script" >&2
16+
exit 1
17+
fi
18+
bash -n "$script"
19+
echo "Validated bash syntax: $script"
20+
done

0 commit comments

Comments
 (0)