-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (140 loc) · 4.8 KB
/
screenshot.yml
File metadata and controls
162 lines (140 loc) · 4.8 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Screenshot Tests
on:
push:
paths:
- "examples/gallery/**"
- "download.cr"
workflow_dispatch:
jobs:
screenshot:
name: ${{ matrix.os }} Screenshot
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- os: ubuntu
runner: ubuntu-latest
setup-display: true
- os: windows
runner: windows-latest
setup-display: false
- os: macos
runner: macos-latest
setup-display: false
env:
DISPLAY: ${{ matrix.setup-display && ':99' || '' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: true
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
with:
crystal: latest
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu'
run: |
sudo apt-get update -y
sudo apt-get install -y libgtk-3-dev xvfb imagemagick xdotool openbox wmctrl
- name: Setup Windows Developer Command Prompt
if: matrix.os == 'windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Install Crystal dependencies
run: shards install
- name: Download libui library
run: |
crystal run download.cr
${{ matrix.os == 'windows' && 'Get-ChildItem libui' || 'ls -la libui/' }}
- name: Build all gallery (Linux/macOS)
if: matrix.os != 'windows'
shell: bash
run: |
for f in examples/gallery/*.cr; do
name=$(basename "$f" .cr)
crystal build "$f" -o "$name"
done
- name: Build all gallery (Windows)
if: matrix.os == 'windows'
shell: pwsh
run: |
Get-ChildItem examples/gallery/*.cr | ForEach-Object {
$name = $_.BaseName
crystal build $_.FullName -o $name
}
- name: Generate app-names and output-files
if: matrix.os != 'windows'
id: gen_names
shell: bash
run: |
APPS=$(for f in examples/gallery/*.cr; do basename "$f" .cr; done | xargs)
OUTPUTS=$(for f in examples/gallery/*.cr; do basename "$f" .cr; done | xargs -I{} echo -n "{}-${{ matrix.os }}.png ")
echo "APP_NAMES=$APPS" >> $GITHUB_ENV
echo "OUTPUT_FILES=$OUTPUTS" >> $GITHUB_ENV
- name: Generate app-names and output-files (Windows)
if: matrix.os == 'windows'
id: gen_names_win
shell: pwsh
run: |
$apps = (Get-ChildItem examples/gallery/*.cr | ForEach-Object { $_.BaseName }) -join ' '
$outputs = (Get-ChildItem examples/gallery/*.cr | ForEach-Object { "$($_.BaseName)-${{ matrix.os }}.png" }) -join ' '
echo "APP_NAMES=$apps" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "OUTPUT_FILES=$outputs" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Take screenshots for all gallery
uses: ./.github/actions/screenshot
with:
os: ${{ matrix.os }}
app-names: ${{ env.APP_NAMES }}
output-files: ${{ env.OUTPUT_FILES }}
- name: Upload screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ matrix.os }}
path: "*.png"
retention-days: 30
push_screenshots:
name: Push all screenshots to orphan branch
needs: screenshot
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: true
- name: Prepare orphan branch
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Prepare orphan branch first
git fetch origin screenshots || true
git checkout --orphan screenshots || git checkout screenshots
- name: Download all screenshots artifacts
uses: actions/download-artifact@v5
with:
pattern: screenshots-*
merge-multiple: true
- name: Commit screenshots
run: |
# Debug: Check downloaded files
echo "=== Downloaded files ==="
ls -la
# Add gallery.md if it exists
if [ -f gallery.md ]; then
git add gallery.md
fi
# Commit only if PNG files exist
if ls *.png 1> /dev/null 2>&1; then
git add *.png
git status
if ! git diff --cached --quiet; then
git commit -m "Update screenshots [skip ci]"
git push -f origin screenshots
else
echo "No changes to commit."
fi
else
echo "No PNG files found to commit."
fi