-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (106 loc) · 4.19 KB
/
Copy pathon-module-release.yml
File metadata and controls
118 lines (106 loc) · 4.19 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
name: e2e on module release
on:
repository_dispatch:
types: [module-released]
workflow_dispatch:
inputs:
module:
description: 'Module name (e.g. common-module)'
required: true
version:
description: 'Module version tag (e.g. v0.5.0)'
required: true
permissions:
contents: write
concurrency:
group: e2e-${{ github.event.client_payload.module || github.event.inputs.module }}-${{ github.event.client_payload.version || github.event.inputs.version }}
cancel-in-progress: false
jobs:
e2e:
runs-on: ubuntu-latest
env:
MODULE: ${{ github.event.client_payload.module || github.event.inputs.module }}
VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- uses: helm/kind-action@v1
with:
cluster_name: tinysystems-e2e
wait: 60s
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: v3.16.4
- name: Validate inputs
run: |
set -euo pipefail
if ! [[ "$MODULE" =~ ^[a-z0-9-]+$ ]]; then
echo "invalid module name: $MODULE" >&2
exit 1
fi
if ! [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then
echo "invalid version: $VERSION" >&2
exit 1
fi
- name: Install charts
run: ./scripts/install-charts.sh "$MODULE" "$VERSION"
- name: Run scenarios and record
env:
E2E_MODULE: ${{ env.MODULE }}
run: make test-record MODULE="$MODULE" VERSION="$VERSION"
- name: Commit result
if: always()
env:
BRANCH: ${{ github.ref_name }}
run: |
set -euo pipefail
if [ -z "$(git status --porcelain results/)" ]; then
echo "no result file changes"
exit 0
fi
git config user.name "tinysystems-e2e-bot"
git config user.email "e2e-bot@users.noreply.github.com"
git add results/
git commit -m "e2e: ${MODULE}@${VERSION}"
max_attempts=15
for attempt in $(seq 1 "$max_attempts"); do
if git push origin "HEAD:${BRANCH}"; then
exit 0
fi
echo "push rejected (attempt ${attempt}/${max_attempts}); rebasing on origin/${BRANCH}"
git fetch origin "${BRANCH}"
# -X theirs auto-resolves add/add and modify/modify conflicts
# on result files by taking upstream's version. Two CI runs
# for the same MODULE@VERSION (e.g. tag deleted + re-pushed
# or adjacent tags firing simultaneously) produce equivalent
# JSON, so either copy is fine — what we must avoid is the
# rebase aborting mid-loop and failing the whole workflow.
if ! git rebase -X theirs "origin/${BRANCH}"; then
git rebase --abort 2>/dev/null || true
# If our result file already exists upstream, treat as
# success — the data is recorded, our commit is redundant.
if git fetch origin "${BRANCH}" && git ls-tree "origin/${BRANCH}" -- "results/${MODULE}/${VERSION}.json" | grep -q .; then
echo "result for ${MODULE}@${VERSION} already on origin; nothing to push"
exit 0
fi
echo "rebase aborted with no upstream result file — bailing"
exit 1
fi
# Randomised backoff: a batch of module releases fires many e2e
# runs that all push results at once. A deterministic sleep makes
# them retry in lock-step and collide again; jitter de-syncs them
# so each wins a push within a few attempts.
sleep $(( (RANDOM % 6) + 1 ))
done
echo "result commit failed after ${max_attempts} attempts" >&2
exit 1
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-logs-${{ env.MODULE }}-${{ env.VERSION }}
path: results/${{ env.MODULE }}/${{ env.VERSION }}.json