-
-
Notifications
You must be signed in to change notification settings - Fork 182
137 lines (115 loc) · 4.52 KB
/
e2e-recording.yml
File metadata and controls
137 lines (115 loc) · 4.52 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
name: E2E Recordings
on:
pull_request:
types: [labeled]
env:
CARGO_TERM_COLOR: always
jobs:
record:
name: Record E2E Tests
if: github.event.label.name == 'needs-recording'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@stable
- name: Install tmux
run: sudo apt-get update && sudo apt-get install -y tmux
- name: Install asciinema
run: pipx install asciinema
- name: Install agg
run: |
AGG_VERSION="1.7.0"
curl -fsSL "https://github.com/asciinema/agg/releases/download/v${AGG_VERSION}/agg-x86_64-unknown-linux-gnu" -o /usr/local/bin/agg
chmod +x /usr/local/bin/agg
- name: Verify recording tools
run: |
tmux -V
asciinema --version
agg --version
- name: Build tests
run: cargo test --test e2e --no-run
- name: Run e2e tests with recording
env:
RECORD_E2E: "1"
run: cargo test --test e2e -- --nocapture
- name: Upload recordings as artifact
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: e2e-recordings
path: |
target/e2e-recordings/*.gif
target/e2e-recordings/*.cast
if-no-files-found: warn
retention-days: 30
- name: Publish GIFs and comment on PR
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
shopt -s nullglob
gifs=(target/e2e-recordings/*.gif)
if [ ${#gifs[@]} -eq 0 ]; then
echo "No GIF recordings found, skipping PR comment."
exit 0
fi
# Push GIFs to the e2e-recordings orphan branch so they are
# accessible via raw.githubusercontent.com and render inline.
RUN_DIR="run-${{ github.run_id }}"
REPO="${{ github.repository }}"
BRANCH="e2e-recordings"
# Set up a temporary worktree for the orphan branch.
tmp=$(mktemp -d)
git clone --depth 1 --branch "$BRANCH" \
"https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" "$tmp" 2>/dev/null \
|| {
# Branch doesn't exist yet -- create an orphan.
git clone --depth 1 \
"https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" "$tmp"
cd "$tmp"
git checkout --orphan "$BRANCH"
git rm -rf . > /dev/null 2>&1 || true
echo "# E2E Test Recordings" > README.md
echo "" >> README.md
echo "GIFs published by the E2E Recordings workflow. Each run-* directory" >> README.md
echo "corresponds to a GitHub Actions run." >> README.md
git add README.md
git commit -m "init: e2e-recordings branch"
cd -
}
# Copy GIFs into the run directory.
mkdir -p "$tmp/$RUN_DIR"
cp "${gifs[@]}" "$tmp/$RUN_DIR/"
cd "$tmp"
git add "$RUN_DIR"
git commit -m "recordings: PR #${{ github.event.pull_request.number }} (run ${{ github.run_id }})"
git push origin "$BRANCH"
cd -
# Build PR comment with inline GIF images.
RAW_BASE="https://raw.githubusercontent.com/${REPO}/${BRANCH}/${RUN_DIR}"
body="## E2E Test Recordings"$'\n\n'
for gif in "${gifs[@]}"; do
name=$(basename "$gif" .gif)
body+="### ${name}"$'\n\n'
body+=""$'\n\n'
done
body+="---"$'\n'
body+="*Raw recordings (.cast) available in the [e2e-recordings artifact](${{ github.server_url }}/${REPO}/actions/runs/${{ github.run_id }}).*"
# Post or update the comment to avoid duplicates on re-runs.
existing=$(gh api \
"repos/${REPO}/issues/${{ github.event.pull_request.number }}/comments" \
--jq '.[] | select(.body | startswith("## E2E Test Recordings")) | .id' \
| head -1)
if [ -n "$existing" ]; then
gh api \
"repos/${REPO}/issues/comments/${existing}" \
-X PATCH \
-f body="$body"
echo "Updated existing PR comment ${existing}"
else
gh pr comment "${{ github.event.pull_request.number }}" --body "$body"
echo "Posted new PR comment"
fi