-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (172 loc) · 5.9 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
name: Build
on:
push:
branches: [ "main" ]
tags: [ '*' ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo build --locked --all-features
- name: Test
run: cargo test --locked --all-features
- name: Format
uses: actions-rust-lang/rustfmt@v1
- name: Clippy
run: cargo clippy -- -Dwarnings
build:
name: Build Artifact (${{ matrix.target }})
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
suffix: x86_64-linux-gnu
cargo: cargo
- target: x86_64-unknown-linux-musl
suffix: x86_64-linux-musl
cargo: cross
- target: aarch64-unknown-linux-musl
suffix: aarch64-linux-musl
cargo: cross
- target: armv7-unknown-linux-musleabihf
suffix: armv7-linux-musleabihf
cargo: cross
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
- name: Cross Installation
run: cargo install cross
if: ${{ matrix.cargo == 'cross' }}
- name: Build
run: |
${{ matrix.cargo }} build --release --locked --target ${{ matrix.target }}
mv target/${{ matrix.target }}/release/${{ github.event.repository.name }} ${{ github.event.repository.name }}_${{ matrix.suffix }}
- name: Store Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}_${{ matrix.suffix }}
path: ${{ github.event.repository.name }}_${{ matrix.suffix }}
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ github.event.repository.name }}_${{ matrix.suffix }}
container:
name: Container Images (${{ matrix.arch }})
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: linux/amd64
suffix: x86_64-linux-musl
short_suffix: x86_64-linux
- arch: linux/aarch64
suffix: aarch64-linux-musl
short_suffix: aarch64-linux
- arch: linux/arm/v7
suffix: armv7-linux-musleabihf
short_suffix: armv7-linux
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup qemu
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: GitHub Container Registry Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Retrieve Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}_${{ matrix.suffix }}
path: build/
- name: Prepare Dockerfile
run: |
mv build/${{ github.event.repository.name }}_${{ matrix.suffix }} build/${{ github.event.repository.name }}
chmod 0755 build/${{ github.event.repository.name }}
echo 'FROM scratch' > build/Dockerfile
echo 'ADD ${{ github.event.repository.name }} /${{ github.event.repository.name }}' >> build/Dockerfile
echo 'ENTRYPOINT ["/${{ github.event.repository.name }}"]' >> build/Dockerfile
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
suffix=-${{ matrix.short_suffix }},onlatest=true
- name: Build and push
uses: docker/build-push-action@v5
with:
context: build
platforms: ${{ matrix.arch }}
push: true
tags: ${{ steps.docker-meta.outputs.tags }}
provenance: false
container_manifest:
name: Container Manifest
needs: container
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: GitHub Container Registry Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
- name: Create and push tag manifest
if: startsWith(github.ref, 'refs/tags/')
run: |
docker buildx imagetools create \
-t ${{ steps.docker-meta.outputs.tags }} \
${{ steps.docker-meta.outputs.tags }}-x86_64-linux \
${{ steps.docker-meta.outputs.tags }}-aarch64-linux \
${{ steps.docker-meta.outputs.tags }}-armv7-linux
- name: Create and push tag manifest (latest)
run: |
docker buildx imagetools create \
-t ghcr.io/${{ github.repository }}:latest \
${{ steps.docker-meta.outputs.tags }}-x86_64-linux \
${{ steps.docker-meta.outputs.tags }}-aarch64-linux \
${{ steps.docker-meta.outputs.tags }}-armv7-linux
ghcr_cleanup:
name: GHCR Cleanup
needs: container_manifest
runs-on: ubuntu-latest
steps:
- name: Delete all containers from repository without tags
uses: camargo/delete-untagged-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}