-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (93 loc) · 3.26 KB
/
ci.yml
File metadata and controls
113 lines (93 loc) · 3.26 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
name: CI
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
permissions:
contents: write
jobs:
test:
name: Test & Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Run tests
id: tests
run: |
TEST_OUTPUT=$(go test -v -race -count=1 ./... 2>&1)
echo "$TEST_OUTPUT"
TEST_COUNT=$(echo "$TEST_OUTPUT" | grep -c '^--- PASS:' || true)
echo "test_count=$TEST_COUNT" >> "$GITHUB_OUTPUT"
- name: Build binary
id: build
run: |
go build -o rawdoc .
BINARY_SIZE=$(du -sh rawdoc | cut -f1)
echo "binary_size=$BINARY_SIZE" >> "$GITHUB_OUTPUT"
- name: Smoke test
run: |
./rawdoc https://example.com -q
echo "Smoke test passed"
- name: Auto patch tag
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=$((PATCH + 1))
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
# Skip if this commit is already tagged (e.g. from release workflow)
if git describe --exact-match HEAD 2>/dev/null; then
echo "Commit already tagged, skipping"
exit 0
fi
git tag -a "$NEW_TAG" -m "Auto patch $NEW_TAG
Install: go install github.com/RandomCodeSpace/rawdoc@$NEW_TAG"
git push origin "$NEW_TAG"
echo "Tagged $NEW_TAG"
echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
- name: Generate job summary
if: always()
env:
TEST_COUNT: ${{ steps.tests.outputs.test_count }}
BINARY_SIZE: ${{ steps.build.outputs.binary_size }}
COMMIT_SHA: ${{ github.sha }}
BUILD_NUMBER: ${{ github.run_number }}
TESTS_OUTCOME: ${{ steps.tests.outcome }}
BUILD_OUTCOME: ${{ steps.build.outcome }}
run: |
SHORT_SHA="${COMMIT_SHA:0:7}"
BUILD_DATE=$(date -u +"%Y-%m-%d %H:%M UTC")
if [ "$TESTS_OUTCOME" = "success" ]; then
TEST_STATUS="✅ Passed (${TEST_COUNT} tests)"
else
TEST_STATUS="❌ Failed"
fi
if [ "$BUILD_OUTCOME" = "success" ]; then
BUILD_STATUS="✅ Success"
else
BUILD_STATUS="❌ Failed"
fi
SMOKE_STATUS="✅ example.com fetched"
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## rawdoc CI Results
| Check | Status |
|-------|--------|
| Unit Tests | ${TEST_STATUS} |
| Build | ${BUILD_STATUS} |
| Smoke Test | ${SMOKE_STATUS} |
| Binary Size | ${BINARY_SIZE} |
**Build:** #${BUILD_NUMBER} | **Commit:** ${SHORT_SHA} | **Date:** ${BUILD_DATE}
EOF