-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (173 loc) · 5.75 KB
/
build.yml
File metadata and controls
195 lines (173 loc) · 5.75 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
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
name: Build and release
on:
workflow_run:
workflows:
- Check
types:
- completed
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
check-version:
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
release_exists: ${{ steps.release_check.outputs.release_exists }}
should_run: ${{ steps.decide.outputs.should_run }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Read version
id: version
run: |
version=$(awk -F' *= *' '$1 == "version" { gsub(/"/, "", $2); print $2; exit }' Cargo.toml)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Check release existence
id: release_check
uses: actions/github-script@v7
with:
script: |
const tag = `${{ steps.version.outputs.version }}`;
try {
await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag,
});
core.setOutput('release_exists', 'true');
} catch (error) {
if (error.status === 404) {
core.setOutput('release_exists', 'false');
} else {
throw error;
}
}
- name: Decide run
id: decide
run: |
if [[ "${{ steps.release_check.outputs.release_exists }}" == "false" ]]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
fi
build:
needs: check-version
if: needs.check-version.outputs.should_run == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-musl
artifact: typst-webservice-linux-x64
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
artifact: typst-webservice-linux-arm64
- os: macos-15-intel
target: x86_64-apple-darwin
artifact: typst-webservice-macos-x64
- os: macos-15
target: aarch64-apple-darwin
artifact: typst-webservice-macos-arm64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Optionally install musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'
run: sudo apt-get install -y musl-tools
- uses: Swatinem/rust-cache@v2
- name: Build
env:
CC_aarch64_unknown_linux_musl: ${{ matrix.target == 'aarch64-unknown-linux-musl' && 'musl-gcc' || '' }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/typst-webservice dist/${{ matrix.artifact }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}
docker:
needs:
- check-version
- build
if: needs.check-version.outputs.should_run == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Download linux x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-x64
path: dist
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
file: Dockerfile
push: true
build-args: "version=${{ needs.check-version.outputs.version }}"
context: dist
tags: "ghcr.io/tweedegolf/typst-webservice:${{ needs.check-version.outputs.version }},ghcr.io/tweedegolf/typst-webservice:latest"
release:
needs:
- check-version
- build
if: needs.check-version.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Download linux x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-x64
path: dist
- name: Download linux arm64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-arm64
path: dist
- name: Download macos x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-macos-x64
path: dist
- name: Download macos arm64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-macos-arm64
path: dist
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version.outputs.version }}
name: Version ${{ needs.check-version.outputs.version }}
generate_release_notes: true
files: |
dist/typst-webservice-linux-x64
dist/typst-webservice-linux-arm64
dist/typst-webservice-macos-x64
dist/typst-webservice-macos-arm64