-
Notifications
You must be signed in to change notification settings - Fork 1
197 lines (181 loc) · 6.84 KB
/
build.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Nightly builds
name: Build
on:
schedule:
- cron: "15 0 * * *"
permissions:
contents: read
packages: read
concurrency: build
env:
GIT_AUTHOR_NAME: OpenSlide Automation
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: OpenSlide Automation
GIT_COMMITTER_EMAIL: [email protected]
jobs:
setup:
name: Set up
runs-on: ubuntu-latest
outputs:
linux_builder_repo_and_digest: ${{ steps.find-linux.outputs.builder_repo_and_digest }}
windows_builder_repo_and_digest: ${{ steps.find-windows.outputs.builder_repo_and_digest }}
suffix: ${{ steps.params.outputs.suffix }}
openslide_commit: ${{ steps.params.outputs.openslide_commit }}
bin_commit: ${{ steps.params.outputs.bin_commit }}
changed: ${{ steps.params.outputs.changed }}
stale: ${{ steps.params.outputs.stale }}
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Find Linux builder container digest
id: find-linux
uses: openslide/openslide-bin/.github/find-container-digest@main
with:
builder_image: linux
- name: Find Windows builder container digest
id: find-windows
uses: openslide/openslide-bin/.github/find-container-digest@main
with:
builder_image: windows
- name: Calculate parameters
id: params
run: |
set -euo pipefail
suffix="$(date +%Y%m%d).nightly"
echo "suffix=$suffix" >> $GITHUB_OUTPUT
duplicate=$(jq ".builds[] | select(.version | endswith(\"+$suffix\"))" \
site/index.json)
if [ -n "$duplicate" ]; then
echo "Found existing nightly build with suffix $suffix"
exit 1
fi
# Modify the repository at least every 30 days so GitHub doesn't
# disable the workflow
if [ $(( $(jq .last_update site/index.json) + 86400 * 30 )) -lt $(date +%s) ]; then
echo "Repository is stale"
echo "stale=true" >> $GITHUB_OUTPUT
fi
for repo in openslide openslide-bin; do
old=$(jq -r ".builds[-1][\"${repo}\"]" site/index.json)
new=$(curl --no-progress-meter \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/openslide/${repo}/commits/main" |
jq -r .sha)
echo "$repo commit: https://github.com/openslide/${repo}/commit/${new:0:10}"
echo "${repo##*-}_commit=$new" >> $GITHUB_OUTPUT
if [ "$old" != "$new" ]; then
echo " -> changed from https://github.com/openslide/${repo}/commit/${old:0:10}"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo " -> unchanged"
fi
done
for repo in "linux|${{ steps.find-linux.outputs.builder_repo_and_digest }}" "windows|${{ steps.find-windows.outputs.builder_repo_and_digest }}"; do
name="${repo%%|*}"
old=$(jq -r ".builds[-1][\"${name}-builder\"]" site/index.json)
new="${repo##*|}"
echo "$name builder container: $new"
if [ "$old" != "$new" ]; then
echo " -> changed from $old"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo " -> unchanged"
fi
done
build:
name: Build
needs: setup
if: needs.setup.outputs.changed
uses: openslide/openslide-bin/.github/workflows/build.yml@main
with:
linux_builder_repo_and_digest: ${{ needs.setup.outputs.linux_builder_repo_and_digest }}
macos_enable: true
windows_builder_repo_and_digest: ${{ needs.setup.outputs.windows_builder_repo_and_digest }}
openslide_repo: openslide/openslide
openslide_ref: ${{ needs.setup.outputs.openslide_commit }}
openslide_bin_repo: openslide/openslide-bin
openslide_bin_ref: ${{ needs.setup.outputs.bin_commit }}
suffix: ${{ needs.setup.outputs.suffix }}
upload:
name: Upload
needs: [setup, build]
if: needs.setup.outputs.changed
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Update Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Check out repo
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get install python3-dateutil python3-jinja2
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: "openslide[_-]bin-*"
path: upload
merge-multiple: true
- name: Update index
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
scripts/make-index.py \
--version "${{ needs.build.outputs.version }}" \
--files upload \
--linux-builder "${{ needs.setup.outputs.linux_builder_repo_and_digest }}" \
--windows-builder "${{ needs.setup.outputs.windows_builder_repo_and_digest }}" \
--openslide "${{ needs.setup.outputs.openslide_commit }}" \
--bin "${{ needs.setup.outputs.bin_commit }}"
- name: Commit, tag, push, create release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
version="${{ needs.build.outputs.version }}"
tar xf "upload/openslide-bin-${version}.tar.gz"
title="Build $version"
# trim width for commit message limit
body="$(openslide-bin-${version}/bintool versions \
upload/*.{tar.xz,zip} | \
sed 's/ |$/|/')"
git add site
git commit -m "$title" -m "$body"
git tag -a "v$version" -m "$title" -m "$body"
git push origin HEAD "v$version"
gh release create --notes-file - --prerelease --verify-tag \
--title "$title" "v$version" upload/* <<EOF
See the [build index](https://openslide.org/builds/) for more info.
$body
EOF
deploy:
name: Deploy website
needs: [upload]
permissions:
contents: read
pages: write
id-token: write
uses: ./.github/workflows/pages.yml
keepalive:
name: Keepalive
needs: setup
if: needs.setup.outputs.stale && ! needs.setup.outputs.changed
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get install python3-dateutil python3-jinja2
- name: Commit and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
scripts/make-index.py
git add site
git commit -m "Update timestamp"
git push