-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (100 loc) · 3.97 KB
/
Copy pathdemo.yml
File metadata and controls
112 lines (100 loc) · 3.97 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
name: Demo GIF
on:
push:
branches: [main]
permissions:
contents: write
jobs:
record:
# Skip if the push was made by the CI bot to avoid loops.
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
# Credentials intentionally persisted — needed for git push.
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: true
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version-file: go.mod
- name: Build mdsmith
run: go build -o mdsmith ./cmd/mdsmith
- name: Cache VHS + ttyd binaries
id: vhs-cache
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
~/vhs-bin
key: vhs-0.10.0-ttyd-1.7.7-${{ runner.os }}-${{ runner.arch }}
- name: Install VHS runtime dependencies
run: |
# Google Chrome is pre-installed on GitHub runners and
# go-rod (used by VHS) finds it via launcher.LookPath().
# Installing chromium via apt on Ubuntu 24.04 triggers a
# slow snap install (~500 MB of dependencies), so we skip
# it and only install ffmpeg.
sudo apt-get update -qq
sudo apt-get install -y -qq ffmpeg
if [ -f ~/vhs-bin/ttyd ]; then
sudo install ~/vhs-bin/ttyd /usr/local/bin/ttyd
else
curl -fsSL -o /tmp/ttyd \
"https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64"
sudo install /tmp/ttyd /usr/local/bin/ttyd
fi
- name: Install VHS
run: |
if [ -f ~/vhs-bin/vhs ]; then
sudo install ~/vhs-bin/vhs /usr/local/bin/vhs
else
go install github.com/charmbracelet/vhs@v0.10.0
fi
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Populate VHS cache
if: steps.vhs-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/vhs-bin
cp /usr/local/bin/ttyd ~/vhs-bin/
cp "$(go env GOPATH)/bin/vhs" ~/vhs-bin/ 2>/dev/null || cp /usr/local/bin/vhs ~/vhs-bin/ 2>/dev/null || true
- name: Record demo in isolated directory
run: |
# Run VHS in a temp directory so demo.tape commands
# cannot modify the repo working tree.
iso="$(mktemp -d)"
tar --exclude='.git' -cf - . | (cd "$iso" && tar -xf -)
# No Output-path rewrite needed — VHS runs inside $iso,
# so relative Output assets/demo.gif writes to $iso/assets/.
(cd "$iso" && vhs demo.tape)
cp "$iso/assets/demo.gif" /tmp/demo.gif
rm -rf "$iso"
- name: Push GIF to assets branch
run: |
# Create or update the orphan assets branch with only
# the demo GIF. This avoids pushing to main entirely —
# no branch protection bypass needed.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Remove untracked build artifacts so branch switch succeeds.
rm -f mdsmith
# Check if assets branch exists on remote
if git ls-remote --exit-code origin refs/heads/assets >/dev/null 2>&1; then
git fetch origin assets
git checkout assets
git rm -rf --ignore-unmatch .
git clean -fdx
else
git checkout --orphan assets
git rm -rf --ignore-unmatch .
git clean -fdx
fi
mkdir -p assets
cp /tmp/demo.gif assets/demo.gif
# Only push if the GIF actually changed
git add assets/demo.gif
if git diff --staged --quiet; then
echo "assets/demo.gif unchanged — nothing to push"
else
git commit -m "chore: update demo GIF"
git push -u origin assets
fi