-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (136 loc) · 5.53 KB
/
Copy pathci.yml
File metadata and controls
169 lines (136 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Clone rookery (for local replace directives)
run: git clone --depth 1 https://github.com/aflock-ai/rookery.git ../rookery
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.26'
- name: Build
run: go build -v ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Clone rookery (for local replace directives)
run: git clone --depth 1 https://github.com/aflock-ai/rookery.git ../rookery
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.26'
- name: golangci-lint
uses: golangci/golangci-lint-action@9fae48acfc02a90574d7c304a1758ef9895495fa # v7.0.1
with:
version: latest
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Clone rookery (for local replace directives)
run: git clone --depth 1 https://github.com/aflock-ai/rookery.git ../rookery
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.26'
- name: Run unit tests
run: go test -coverprofile=coverage.out -covermode=atomic ./internal/... ./pkg/...
- name: Upload coverage report
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: coverage-report
path: coverage.out
retention-days: 7
coverage-check:
runs-on: ubuntu-latest
needs: unit-tests
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Clone rookery (for local replace directives)
run: git clone --depth 1 https://github.com/aflock-ai/rookery.git ../rookery
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.26'
- name: Download coverage report
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: coverage-report
- name: Check coverage
run: |
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Package | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|---------|----------|" >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.out | while read line; do
if [[ "$line" == *"total:"* ]]; then
total=$(echo "$line" | awk '{print $NF}')
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Total Coverage: $total**" >> $GITHUB_STEP_SUMMARY
elif [[ "$line" != "" ]]; then
pkg=$(echo "$line" | awk '{print $1}')
cov=$(echo "$line" | awk '{print $NF}')
if [[ "$pkg" != "" && "$cov" != "" ]]; then
echo "| $pkg | $cov |" >> $GITHUB_STEP_SUMMARY
fi
fi
done
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Clone rookery (for local replace directives)
run: git clone --depth 1 https://github.com/aflock-ai/rookery.git ../rookery
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.26'
- name: Build binary
run: go build -o bin/aflock ./cmd/aflock
- name: Initialize test project
run: |
mkdir -p /tmp/aflock-test/src
cd /tmp/aflock-test
git init
git config user.email "ci@aflock.ai"
git config user.name "CI"
$GITHUB_WORKSPACE/bin/aflock init
echo "test" > src/app.go
git add .
git commit -m "initial"
- name: Test hooks
run: |
cd /tmp/aflock-test
echo "Testing SessionStart..."
echo '{"session_id":"ci-test","cwd":"/tmp/aflock-test"}' | $GITHUB_WORKSPACE/bin/aflock hook SessionStart
echo "Testing PreToolUse (allowed)..."
echo '{"session_id":"ci-test","cwd":"/tmp/aflock-test","tool_name":"Read","tool_use_id":"t1","tool_input":{"file_path":"src/app.go"}}' | $GITHUB_WORKSPACE/bin/aflock hook PreToolUse
echo "Testing PreToolUse (denied - Task)..."
DENY_RESULT=$(echo '{"session_id":"ci-test","cwd":"/tmp/aflock-test","tool_name":"Task","tool_use_id":"t2","tool_input":{}}' | $GITHUB_WORKSPACE/bin/aflock hook PreToolUse 2>&1) || true
if echo "$DENY_RESULT" | grep -q "BLOCKED"; then
echo "Task correctly denied"
else
echo "ERROR: Task should have been denied"
echo "Got: $DENY_RESULT"
exit 1
fi
echo "Testing verify..."
$GITHUB_WORKSPACE/bin/aflock verify --policy .aflock
- name: Test status command
run: $GITHUB_WORKSPACE/bin/aflock status
all-tests:
runs-on: ubuntu-latest
needs: [build, lint, unit-tests, integration-tests]
steps:
- name: All checks passed
run: echo "All CI checks passed!"