Skip to content

Commit 6a7cd4d

Browse files
Add CI workflow for tests and support both podman and docker
Co-authored-by: HectorCastelli <3715874+HectorCastelli@users.noreply.github.com>
1 parent bc0024d commit 6a7cd4d

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker
20+
run: |
21+
docker --version
22+
23+
- name: Run tests
24+
run: |
25+
sh scripts/tests.sh
26+
27+
- name: Upload test report
28+
if: always()
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: test-report
32+
path: test_report.txt
33+
retention-days: 30

scripts/tests.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/usr/bin/env sh
22
set -eu
33

4+
# Detect container runtime (prefer podman, fallback to docker)
5+
if command -v podman >/dev/null 2>&1; then
6+
CONTAINER_RUNTIME="podman"
7+
elif command -v docker >/dev/null 2>&1; then
8+
CONTAINER_RUNTIME="docker"
9+
else
10+
printf "Error: Neither podman nor docker is installed\n" >&2
11+
exit 1
12+
fi
13+
414
# Global variables
515
IMAGE_NAME="dotfiles-test"
616
REPORT_FILE="${REPORT_FILE:-test_report.txt}"
@@ -9,13 +19,13 @@ REPO_DIR="$(git rev-parse --show-toplevel)"
919

1020
# Build the test image
1121
build_image() {
12-
printf "Building test image...\n"
13-
podman build -t "$IMAGE_NAME" -f "$REPO_DIR/Containerfile" "$REPO_DIR"
22+
printf "Building test image with %s...\n" "$CONTAINER_RUNTIME"
23+
"$CONTAINER_RUNTIME" build -t "$IMAGE_NAME" -f "$REPO_DIR/Containerfile" "$REPO_DIR"
1424
}
1525

1626
# Start a new test container
1727
start_container() {
18-
CURRENT_CONTAINER=$(podman run -d \
28+
CURRENT_CONTAINER=$("$CONTAINER_RUNTIME" run -d \
1929
-v "$REPO_DIR:/dotfiles:ro" \
2030
"$IMAGE_NAME" \
2131
sleep infinity)
@@ -26,7 +36,7 @@ start_container() {
2636
cleanup_container() {
2737
if [ -n "$CURRENT_CONTAINER" ]; then
2838
printf "Cleaning up container: %s\n" "$CURRENT_CONTAINER"
29-
podman rm -f "$CURRENT_CONTAINER" >/dev/null 2>&1 || true
39+
"$CONTAINER_RUNTIME" rm -f "$CURRENT_CONTAINER" >/dev/null 2>&1 || true
3040
CURRENT_CONTAINER=""
3141
fi
3242
}
@@ -42,7 +52,7 @@ assert() {
4252
printf "Command: %s\n" "$command" | tee -a "$REPORT_FILE"
4353

4454
# Run the command in the container and capture output and exit code
45-
if output=$(podman exec "$CURRENT_CONTAINER" sh -c "$command" 2>&1); then
55+
if output=$("$CONTAINER_RUNTIME" exec "$CURRENT_CONTAINER" sh -c "$command" 2>&1); then
4656
exit_code=0
4757
else
4858
exit_code=$?

0 commit comments

Comments
 (0)