Skip to content

Commit c30d1b7

Browse files
committed
chore: Separate CI log formatting
* Extracted log formatting logic into a reusable `output_logs` function in `gh-workflow-ci.sh`. * Added a distinct step in the e2e GitHub Actions workflow to display fmatted logs using `snazy` or a Python fallback. * This change aimed to improve CI log visibility directly within the GitHub UI after log collection completed. * Updated script command-line handling and help text to reflect the new function. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 33a66a0 commit c30d1b7

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.github/workflows/e2e.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ jobs:
165165
run: |
166166
./hack/gh-workflow-ci.sh collect_logs
167167
168+
- name: Show controllers/watcher logs with Snazy
169+
run: |
170+
./hack/gh-workflow-ci output-logs
171+
168172
- name: Upload artifacts
169173
if: ${{ always() }}
170174
uses: actions/upload-artifact@v4

hack/gh-workflow-ci.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ run_e2e_tests() {
9191
make test-e2e GO_TEST_FLAGS="-run \"$(echo "${tests[*]}" | sed 's/ /|/g')\""
9292
}
9393

94+
output_logs() {
95+
if command -v "snazy" >/dev/null 2>&1; then
96+
snazy --skip-line-regexp="^(Reconcile (succeeded|error)|Updating webhook)" /tmp/logs/pac-pods.log
97+
else
98+
# snazy for the poors
99+
python -c "import sys,json,datetime; [print(f'• { (lambda t: datetime.datetime.fromisoformat(t.rstrip(\"Z\")).strftime(\"%H:%M:%S\") if isinstance(t,str) else datetime.datetime.fromtimestamp(t).strftime(\"%H:%M:%S\"))(json.loads(l.strip())[\"ts\"] )} {json.loads(l.strip()).get(\"msg\",\"\")}') if l.strip().startswith('{') else print(l.strip()) for l in sys.stdin]" \
100+
</tmp/logs/pac-pods.log
101+
fi
102+
}
103+
94104
collect_logs() {
95105
# Read from environment variables
96106
local test_gitea_smee_url="${TEST_GITEA_SMEEURL}"
@@ -100,14 +110,6 @@ collect_logs() {
100110
# Output logs to stdout so we can see via the web interface directly
101111
kubectl logs -n pipelines-as-code -l app.kubernetes.io/part-of=pipelines-as-code \
102112
--all-containers=true --tail=1000 >/tmp/logs/pac-pods.log
103-
if command -v "snazy" >/dev/null 2>&1; then
104-
snazy --skip-line-regexp="^(Reconcile (succeeded|error)|Updating webhook)" /tmp/logs/pac-pods.log
105-
else
106-
# snazy for the poors
107-
python -c "import sys,json,datetime; [print(f'• { (lambda t: datetime.datetime.fromisoformat(t.rstrip(\"Z\")).strftime(\"%H:%M:%S\") if isinstance(t,str) else datetime.datetime.fromtimestamp(t).strftime(\"%H:%M:%S\"))(json.loads(l.strip())[\"ts\"] )} {json.loads(l.strip()).get(\"msg\",\"\")}') if l.strip().startswith('{') else print(l.strip()) for l in sys.stdin]" \
108-
</tmp/logs/pac-pods.log
109-
fi
110-
111113
kind export logs /tmp/logs
112114
[[ -d /tmp/gosmee-replay ]] && cp -a /tmp/gosmee-replay /tmp/logs/
113115

@@ -168,6 +170,10 @@ help() {
168170
collect_logs
169171
Collect logs from the cluster
170172
Required env vars: TEST_GITEA_SMEEURL, TEST_GITHUB_SECOND_SMEE_URL
173+
174+
output_logs
175+
Will output logs using snazzy formatting when available or otherwise through a simple
176+
python formatter. This makes debugging easier from the GitHub Actions interface.
171177
EOF
172178
}
173179

@@ -184,6 +190,9 @@ run_e2e_tests)
184190
collect_logs)
185191
collect_logs
186192
;;
193+
output_logs)
194+
output_logs
195+
;;
187196
help)
188197
help
189198
exit 0

0 commit comments

Comments
 (0)