-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (196 loc) Β· 7.33 KB
/
publish.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Docker
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
pull_request:
paths-ignore:
- 'README.md'
- '.github/*.y[a]?ml'
push:
branches: [ 'master' ]
tags: [ 'v*' ]
env:
BUILDKIT_PROGRESS: plain
GHCR: ghcr.io
REGISTRY: ${{ vars.REGISTRY }}
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
REPO: ${{ vars.REPO }}
PUSH_IMAGE: ${{ github.event_name != 'pull_request' }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
actions: write # See https://docs.github.com/en/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
contents: read
packages: write
steps:
# Checkout the repository
- name: Checkout π―
uses: actions/checkout@v4
with:
fetch-depth: 1
# Get current year
- name: Get current year π
id: get-year
shell: bash
run: echo "year=$(date +%Y)" >> ${GITHUB_OUTPUT}
- name: Restore cached repository π¦
id: restore
uses: actions/cache/restore@v3
with:
path: texlive/
key: rsync-TL${{ steps.get-year.outputs.year }}-${{ github.sha }}
restore-keys: |
rsync-TL${{ steps.get-year.outputs.year }}-
rsync-
enableCrossOsArchive: true
fail-on-cache-miss: false
- name: Run rsync π
shell: bash
run: |
echo "::group::rsync"
script/rsync.sh ${{ env.REPO }} texlive/ --exclude-from=rsyncignore.txt
echo "::endgroup::"
echo "::group::Repository tree"
tree -nh texlive/
echo "::endgroup::"
- name: Get TeX Live release version π
id: tl-release
shell: bash
run: echo "number=$(find ${{ github.workspace }}/texlive/ -name 'TEXLIVE_*' -print0 | sed -e s/[^0-9]//g)" >> ${GITHUB_OUTPUT}
- name: Save repository to cache πΎ
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
uses: actions/cache/save@v3
with:
path: texlive/
key: rsync-TL${{ steps.tl-release.outputs.number }}-${{ github.sha }}
enableCrossOsArchive: true
# Workaround: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
- name: Delete old repo cache ποΈ
if: ${{ steps.restore.outputs.cache-hit }}
shell: bash
run: |
gh extension install actions/gh-actions-cache
[ $(gh actions-cache list -R ${{ github.repository }} -B ${{ github.ref }} --key rsync- | wc -l) -lt 2 ] && exit 0
gh actions-cache delete ${{ steps.restore.outputs.cache-matched-key }} -R ${{ github.repository }} --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU π»
uses: docker/setup-qemu-action@v3
- name: Setup buildx π§
uses: docker/setup-buildx-action@v3
- name: Extract metadata π
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR }}/${{ github.repository }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
bake-target: metadata-action-bullseye-full
flavor: |
latest=auto
prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,onlatest=false
tags: |
type=schedule,pattern=nightly
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha,prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,format=short
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
# Read platforms as CSV from bake file
- name: Read platforms from bake file π
id: get-platforms
shell: bash
run: |
echo "platform=$(docker buildx bake -f docker-bake.hcl --print _platforms | jq -cr '.target._platforms.platforms | @csv' | tr -d '"')" >> ${GITHUB_OUTPUT}
- name: Log into GitHub registry π
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Login to another registry
- name: Log into ${{ env.REGISTRY }} π
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# Free up disk space
# Workaround: actions/runner-images#2840
- name: Free up disk space ποΈ
# Since this step is not critical as long as the space is freed up, we can ignore errors
continue-on-error: true
shell: bash
run: |
echo "::group::Current disk space usage"
echo "Listing 100 largest packages"
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
df -h
echo "::endgroup::"
echo "::group::Purging apt packages"
echo "Removing large packages"
sudo apt purge -qy \
'^dotnet-.*' '^mono.*' \
'^llvm-.*' '^libllvm.*' '^clang-.*' '^libclang.*' \
'^gfortran-.*' \
'^mysql.*' '^postgresql.*' '^mongodb.*'
sudo apt purge -qy \
azure-cli \
microsoft-edge-stable \
google-chrome-stable \
firefox \
powershell \
nginx \
libgl1-mesa-dri
sudo apt autoremove -qy
sudo apt clean -qy
df -h
echo "::endgroup::"
echo "Removing large directories..."
sudo rm -rf \
${AGENT_TOOLSDIRECTORY} \
/usr/share/dotnet \
/usr/local/graalvm/ \
/usr/local/.ghcup/ \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/chromium \
/usr/local/share/edge_driver \
/usr/local/share/powershell \
/usr/local/share/vcpkg
df -h
docker system df
- name: Build / Push image π³
uses: docker/bake-action@v4
with:
files: |
docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
set: |
*.cache-to=type=registry,mode=max,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache,oci-mediatypes=true
*.cache-from=type=registry,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache
*.platform=${{ steps.get-platforms.outputs.platform }}
env:
PUSH: ${{ fromJson(env.PUSH_IMAGE) }}
# NOTE: More space is required to run the upload-artifact action
- name: Cleanup CWD π§Ή
if: ${{ ! fromJson(env.PUSH_IMAGE) }}
shell: bash
run: |
echo "::group::Current disk"
df -h
tree -nhL 2
echo "::endgroup::"
rm -rf texlive
df -h
- name: Upload artifacts π
if: ${{ ! fromJson(env.PUSH_IMAGE) }}
uses: actions/upload-artifact@v3
with:
name: TL${{ steps.tl-release.outputs.number }}
path: texlive.oci
if-no-files-found: error