-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
122 lines (107 loc) · 3.7 KB
/
fonts.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
name: Fonts
on:
pull_request_target:
branches: [ main ]
types: [ labeled ] # 'build fonts' label
jobs:
docker:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'build fonts')
outputs:
image: ${{ steps.check-image.outputs.result }}
permissions:
contents: read
pull-requests: write # to remove label
steps:
- uses: actions/checkout@v3
with:
ref: ${{ format('refs/pull/{0}/merge', github.event.pull_request.number) }}
persist-credentials: false # minimize exposure and prevent accidental pushes
- name: Remove label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: "build fonts",
});
- name: Check image
id: check-image
uses: actions/github-script@v6
with:
# https://github.community/t/github-token-has-no-access-to-new-container-rest-apis/170395
github-token: ${{ secrets.GH_PACKAGES_TOKEN }}
result-encoding: string
script: |
/* eslint-disable camelcase, max-len, no-console */
const org = context.repo.owner;
const package_name = "fonts";
const version = "${{ hashFiles('dockers/fonts/Dockerfile') }}";
let packages;
try {
packages = (await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
org,
package_type: "container",
package_name,
})).data;
} catch (e) {
packages = [];
console.error(e);
}
core.setOutput("exists", packages.some(p => p.metadata.container.tags.includes(version)));
return `ghcr.io/${org}/${package_name}:${version}`.toLowerCase();
- name: Login to GitHub Container Registry
if: ${{ !fromJSON(steps.check-image.outputs.exists) }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: KaTeX-bot
# https://github.community/t/cant-authenticate-with-actions-token-for-pr-event/170752
password: ${{ secrets.GH_PACKAGES_TOKEN }}
- name: Build and push
if: ${{ !fromJSON(steps.check-image.outputs.exists) }}
uses: docker/build-push-action@v3
with:
context: dockers/fonts
tags: ${{ steps.check-image.outputs.result }}
push: true
fonts:
runs-on: ubuntu-latest
needs: docker
container:
image: ${{ needs.docker.outputs.image }}
credentials:
username: KaTeX-bot
# https://github.community/t/cant-authenticate-with-actions-token-for-pr-event/170752
password: ${{ secrets.GH_PACKAGES_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ format('refs/pull/{0}/merge', github.event.pull_request.number) }}
persist-credentials: false
- name: Build fonts
run: |
make -C src/fonts all
rm -f fonts/*.*
cp src/fonts/ttf/*.ttf fonts
cp src/fonts/woff/*.woff fonts
cp src/fonts/woff2/*.woff2 fonts
- name: Build metrics
run: ./dockers/fonts/buildMetrics.sh
- name: Run git diff
run: |
printf '[diff "font"]\n\tbinary = true\n\ttextconv = ttx -q -i -o -' >> ~/.gitconfig
git diff --exit-code
- uses: actions/upload-artifact@v3
if: failure()
with:
name: fonts
path: fonts
- uses: actions/upload-artifact@v3
if: failure()
with:
name: metrics
path: src/fontMetricsData.js