Skip to content

Commit c4810af

Browse files
samuelho-devclaude
andcommitted
test: add e2e tests for docker-build-push workflow
- test-docker-workflow-outputs.sh: validates workflow defines required outputs (digest, tags, sbom-path), uses correct metadata and build actions, supports cosign signing and SBOM generation - test.yaml: GitHub Actions workflow to run tests on changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 78a50e3 commit c4810af

2 files changed

Lines changed: 153 additions & 0 deletions

File tree

.github/workflows/test.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test Reusable Workflows
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '.github/workflows/**'
8+
- 'tests/**'
9+
pull_request:
10+
branches: [main]
11+
paths:
12+
- '.github/workflows/**'
13+
- 'tests/**'
14+
15+
jobs:
16+
test-workflow-outputs:
17+
name: Test Docker Workflow Outputs
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Run workflow output tests
23+
run: |
24+
chmod +x tests/test-docker-workflow-outputs.sh
25+
./tests/test-docker-workflow-outputs.sh
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env bash
2+
# Unit test for docker-build-push workflow output format
3+
# Tests that the workflow outputs meet expected format for downstream consumers
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
WORKFLOW_FILE="${SCRIPT_DIR}/../.github/workflows/docker-build-push.yml"
8+
9+
echo "=== git-flow: Docker Build Workflow Output Tests ==="
10+
echo ""
11+
12+
TESTS_PASSED=0
13+
TESTS_FAILED=0
14+
15+
# Helper functions
16+
pass() {
17+
echo "PASS: $1"
18+
TESTS_PASSED=$((TESTS_PASSED + 1))
19+
}
20+
21+
fail() {
22+
echo "FAIL: $1"
23+
TESTS_FAILED=$((TESTS_FAILED + 1))
24+
}
25+
26+
# Test 1: Workflow file exists
27+
echo "Test 1: Workflow file exists"
28+
if [[ -f "$WORKFLOW_FILE" ]]; then
29+
pass "Workflow file found at $WORKFLOW_FILE"
30+
else
31+
fail "Workflow file not found at $WORKFLOW_FILE"
32+
exit 1
33+
fi
34+
35+
# Test 2: Workflow defines 'digest' output
36+
echo ""
37+
echo "Test 2: Workflow defines 'digest' output"
38+
if grep -q "^[[:space:]]*digest:" "$WORKFLOW_FILE"; then
39+
pass "Workflow defines 'digest' output"
40+
else
41+
fail "Workflow missing 'digest' output definition"
42+
fi
43+
44+
# Test 3: Workflow defines 'tags' output
45+
echo ""
46+
echo "Test 3: Workflow defines 'tags' output"
47+
if grep -q "^[[:space:]]*tags:" "$WORKFLOW_FILE"; then
48+
pass "Workflow defines 'tags' output"
49+
else
50+
fail "Workflow missing 'tags' output definition"
51+
fi
52+
53+
# Test 4: Workflow defines 'sbom-path' output
54+
echo ""
55+
echo "Test 4: Workflow defines 'sbom-path' output"
56+
if grep -q "^[[:space:]]*sbom-path:" "$WORKFLOW_FILE"; then
57+
pass "Workflow defines 'sbom-path' output"
58+
else
59+
fail "Workflow missing 'sbom-path' output definition"
60+
fi
61+
62+
# Test 5: Digest output comes from build step
63+
echo ""
64+
echo "Test 5: Digest output sources from build step"
65+
if grep -q 'digest:.*\${{ steps.build.outputs.digest }}' "$WORKFLOW_FILE"; then
66+
pass "Digest output correctly sourced from build step"
67+
else
68+
fail "Digest output not correctly sourced from build step"
69+
fi
70+
71+
# Test 6: Tags output comes from meta step
72+
echo ""
73+
echo "Test 6: Tags output sources from meta step"
74+
if grep -q 'tags:.*\${{ steps.meta.outputs.tags }}' "$WORKFLOW_FILE"; then
75+
pass "Tags output correctly sourced from meta step"
76+
else
77+
fail "Tags output not correctly sourced from meta step"
78+
fi
79+
80+
# Test 7: Workflow uses docker/metadata-action for consistent tagging
81+
echo ""
82+
echo "Test 7: Uses docker/metadata-action for tag generation"
83+
if grep -q "docker/metadata-action" "$WORKFLOW_FILE"; then
84+
pass "Uses docker/metadata-action for consistent tagging"
85+
else
86+
fail "Missing docker/metadata-action for tag generation"
87+
fi
88+
89+
# Test 8: Workflow uses docker/build-push-action
90+
echo ""
91+
echo "Test 8: Uses docker/build-push-action"
92+
if grep -q "docker/build-push-action" "$WORKFLOW_FILE"; then
93+
pass "Uses docker/build-push-action"
94+
else
95+
fail "Missing docker/build-push-action"
96+
fi
97+
98+
# Test 9: Workflow supports cosign signing
99+
echo ""
100+
echo "Test 9: Supports cosign image signing"
101+
if grep -q "sigstore/cosign-installer" "$WORKFLOW_FILE"; then
102+
pass "Supports cosign image signing"
103+
else
104+
fail "Missing cosign signing support"
105+
fi
106+
107+
# Test 10: Workflow generates SBOM
108+
echo ""
109+
echo "Test 10: Generates SBOM with anchore/sbom-action"
110+
if grep -q "anchore/sbom-action" "$WORKFLOW_FILE"; then
111+
pass "Generates SBOM with anchore/sbom-action"
112+
else
113+
fail "Missing SBOM generation"
114+
fi
115+
116+
echo ""
117+
echo "=== Test Results ==="
118+
echo "Passed: $TESTS_PASSED"
119+
echo "Failed: $TESTS_FAILED"
120+
echo ""
121+
122+
if [[ $TESTS_FAILED -gt 0 ]]; then
123+
echo "FAILED: Some tests did not pass"
124+
exit 1
125+
else
126+
echo "SUCCESS: All tests passed"
127+
exit 0
128+
fi

0 commit comments

Comments
 (0)