-
Notifications
You must be signed in to change notification settings - Fork 2
278 lines (235 loc) · 8.96 KB
/
ci.yml
File metadata and controls
278 lines (235 loc) · 8.96 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
name: CI Pipeline
run-name: CI by ${{ github.actor }}
on:
push:
branches: ['main']
pull_request:
branches: ['main']
env:
CI: true
CONTAINER_TARGET: ci
CONTAINER_CMD: docker
CONTAINER_NON_INTERACTIVE: true
# Required for pushing to ghcr.io and creating releases
permissions:
contents: write
packages: write
jobs:
# ============================================
# Detect what changed (fast, no container)
# ============================================
changes:
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
tests: ${{ steps.filter.outputs.tests }}
docs: ${{ steps.filter.outputs.docs }}
ci: ${{ steps.filter.outputs.ci }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect changed paths
id: filter
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
else
# Push event: compare with parent commit
BASE="${{ github.event.before }}"
HEAD="${{ github.sha }}"
# Handle first push or force push (before is all zeros)
if [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
# Compare against parent of HEAD
BASE="${HEAD}^"
fi
fi
CHANGED=$(git diff --name-only "$BASE" "$HEAD" 2>/dev/null || echo "")
# Default all to false
CODE=false
TESTS=false
DOCS=false
CI_FILES=false
# Check each pattern (only if CHANGED is non-empty)
if [ -n "$CHANGED" ]; then
if echo "$CHANGED" | grep -qE '^(tracing_library/|decoder_tool/|command_line_tool/|snapshot_library/|kernel_tracing_library/|cmake/|CMakeLists\.txt|CMakePresets\.json)'; then
CODE=true
fi
if echo "$CHANGED" | grep -qE '^(tests/|examples/)'; then
TESTS=true
fi
if echo "$CHANGED" | grep -qE '^docs/|\.md$'; then
DOCS=true
fi
if echo "$CHANGED" | grep -qE '^(\.github/|scripts/)'; then
CI_FILES=true
fi
fi
echo "code=$CODE" >> $GITHUB_OUTPUT
echo "tests=$TESTS" >> $GITHUB_OUTPUT
echo "docs=$DOCS" >> $GITHUB_OUTPUT
echo "ci=$CI_FILES" >> $GITHUB_OUTPUT
echo "Changed files:"
echo "$CHANGED"
echo ""
echo "Detected: code=$CODE tests=$TESTS docs=$DOCS ci=$CI_FILES"
# ============================================
# Quick checks (format, version) - fail fast
# Skip only for docs-only changes
# ============================================
checks:
runs-on: ubuntu-latest
needs: changes
if: |
github.event_name == 'push' ||
needs.changes.outputs.code == 'true' ||
needs.changes.outputs.tests == 'true' ||
needs.changes.outputs.ci == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Load CI-Container
uses: ./.github/actions/load-container
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Format Check
run: ./scripts/container.sh ./scripts/ci-cd/step_format.sh
- name: Fetch main branch for version check
if: github.event_name == 'pull_request'
run: git fetch origin main:main
- name: Version Check
if: github.event_name == 'pull_request'
run: ./scripts/container.sh ./scripts/ci-cd/step_version.sh
# ============================================
# Build and Test
# Skip only for docs-only changes
# ============================================
build-and-test:
runs-on: ubuntu-latest
needs: [changes, checks]
if: |
!failure() && !cancelled() &&
(github.event_name == 'push' ||
needs.changes.outputs.code == 'true' ||
needs.changes.outputs.tests == 'true' ||
needs.changes.outputs.ci == 'true')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ccache
run: mkdir -p ~/.ccache
- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-${{ github.sha }}
restore-keys: |
ccache-${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-
ccache-${{ runner.os }}-build-
- name: Load CI-Container
uses: ./.github/actions/load-container
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: ./scripts/container.sh ./scripts/ci-cd/step_build.sh
- name: Show ccache stats
run: ./scripts/container.sh ccache --show-stats || true
- name: Test
run: ./scripts/container.sh ./scripts/ci-cd/step_test.sh
- name: Memory Check
run: ./scripts/container.sh ./scripts/ci-cd/step_memcheck.sh
# ============================================
# Packaging (only for code/ci changes, or push to main)
# ============================================
package:
runs-on: ubuntu-latest
needs: [changes, build-and-test]
if: |
!failure() && !cancelled() &&
(github.event_name == 'push' ||
needs.changes.outputs.code == 'true' ||
needs.changes.outputs.ci == 'true')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ccache
run: mkdir -p ~/.ccache
- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-${{ runner.os }}-package-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-${{ github.sha }}
restore-keys: |
ccache-${{ runner.os }}-package-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}-
ccache-${{ runner.os }}-package-
ccache-${{ runner.os }}-build-
- name: Load CI-Container
uses: ./.github/actions/load-container
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Package
run: ./scripts/container.sh ./scripts/ci-cd/step_package.sh
- name: Show ccache stats
run: ./scripts/container.sh ccache --show-stats || true
- name: Package Validate
run: ./scripts/container.sh ./scripts/ci-cd/step_package_validate.sh --skip-srpm-rebuild
# ==========================================
# Create GitHub Release (only on push to main)
# ==========================================
- name: Get version and generate release info
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: release_info
env:
COMMIT_SHA: ${{ github.sha }}
run: |
set -e
VERSION=$(head -n1 VERSION.md)
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Create a unique tag using version + short commit hash
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
echo "tag=v${VERSION}-${SHORT_SHA}" >> $GITHUB_OUTPUT
# Find packages directory (container.sh puts it under build/in_container/*/build/packages)
PACKAGES_DIR=$(find build -type d -name packages | head -1)
if [ -z "$PACKAGES_DIR" ]; then
echo "ERROR: No packages directory found"
exit 1
fi
# Check that SRPM exists
if ! ls "$PACKAGES_DIR"/*.src.rpm 1>/dev/null 2>&1; then
echo "ERROR: No SRPM found in $PACKAGES_DIR"
exit 1
fi
# Copy SRPM to current directory and generate checksums there
# (packages dir may be owned by root from container)
cp "$PACKAGES_DIR"/*.src.rpm .
sha256sum *.src.rpm > SHA256SUMS
# Build release body with checksums embedded
{
echo "Release of Common Low Level Tracing Kit"
echo ""
echo "**Commit:** ${COMMIT_SHA}"
echo ""
echo "## Install from SRPM"
echo "\`\`\`bash"
echo "rpmbuild --rebuild clltk-${VERSION}-*.src.rpm"
echo "sudo dnf install ~/rpmbuild/RPMS/x86_64/clltk-*.rpm"
echo "\`\`\`"
echo ""
echo "## Checksums (SHA256)"
echo "\`\`\`"
cat SHA256SUMS
echo "\`\`\`"
} > release_body.md
- name: Create Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_info.outputs.tag }}
name: ${{ steps.release_info.outputs.version }}
body_path: release_body.md
files: |
*.src.rpm
SHA256SUMS