Skip to content

Commit eca4596

Browse files
authored
Merge branch 'main' into report-yaml-error-properly-as-comment
2 parents b3429b0 + dc21362 commit eca4596

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
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

.tekton/linter.yaml

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ spec:
3737
value: "$(params.repo_url)"
3838
- name: revision
3939
value: "$(params.revision)"
40+
- name: depth
41+
value: 1000
4042
- name: generate-release-yaml
4143
image: registry.access.redhat.com/ubi9/python-312
4244
workingDir: $(workspaces.source.path)
4345
script: |
44-
set -x
46+
set -euxo pipefail
4547
mkdir -p bin/ # ignored in .gitignore
4648
./hack/generate-releaseyaml.sh > bin/release.yaml
4749
- name: codespell
@@ -61,7 +63,7 @@ spec:
6163
image: registry.access.redhat.com/ubi9/python-312
6264
workingDir: $(workspaces.source.path)
6365
script: |
64-
set -x
66+
set -euxo pipefail
6567
if [[ "{{ headers['X-Github-Event'] }}" == "" ]]; then
6668
echo "Not a GitHub event, skipping gitlint"
6769
exit 0
@@ -75,14 +77,62 @@ spec:
7577
git config --global --add safe.directory $(workspaces.source.path)
7678
git log -1 --format=format:%s |grep -E -q '^Merge branch' && exit 0
7779
pip3 install gitlint
78-
gitlint --commit "$(git log --format=format:%H --no-merges -1)" --ignore "Merge branch"
80+
81+
# Check all commits between base_sha and HEAD
82+
base_sha="{{ body.pull_request.base.sha }}"
83+
failed=0
84+
while read -r commit_hash; do
85+
echo "Checking commit: $commit_hash"
86+
if ! gitlint --commit "$commit_hash" --ignore "Merge branch"; then
87+
failed=1
88+
fi
89+
done < <(git log "${base_sha}..HEAD" --format=format:%H --no-merges)
90+
91+
exit $failed
92+
93+
- name: conventional-commits
94+
displayName: "conventional commit check"
95+
image: registry.access.redhat.com/ubi9/python-312
96+
workingDir: $(workspaces.source.path)
97+
script: |
98+
set -euxo pipefail
99+
git config --global --add safe.directory /workspace/source
100+
101+
if [[ "{{ headers['X-Github-Event'] }}" == "" ]]; then
102+
echo "Not a GitHub event, skipping gitlint"
103+
exit 0
104+
fi
105+
106+
if [[ "{{ headers['X-Github-Event'] }}" != "pull_request" ]]; then
107+
echo "Not a pull request, skipping gitlint"
108+
exit 0
109+
fi
110+
base_sha="{{ body.pull_request.base.sha }}"
111+
112+
# make sure we have a conventional commit
113+
invalid_commits=0
114+
while read -r commit_msg; do
115+
if ! echo "$commit_msg" | grep -E -q '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?:'; then
116+
echo "ERROR: Found commit message that does not follow conventional commit format:"
117+
echo "$commit_msg"
118+
invalid_commits=$((invalid_commits + 1))
119+
fi
120+
done < <(git log "${base_sha}..HEAD" --format=format:%s --no-merges)
121+
122+
if [ $invalid_commits -gt 0 ]; then
123+
echo "ERROR: $invalid_commits commit(s) do not follow conventional commit format."
124+
echo "Expected format: type(scope): description"
125+
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
126+
echo "See: https://www.conventionalcommits.org/en/v1.0.0/#summary"
127+
exit 1
128+
fi
79129
80130
- name: yamllint
81131
displayName: "YAML Linter"
82132
image: cytopia/yamllint
83133
workingDir: $(workspaces.source.path)
84134
script: |
85-
set -x
135+
set -euxo pipefail
86136
yamllint -f parsable -c .yamllint $(find . -type f -regex ".*y[a]ml" -print)
87137
88138
- name: ruff-lint

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)