-
Notifications
You must be signed in to change notification settings - Fork 42
220 lines (196 loc) · 7.15 KB
/
Copy pathbuild-binaries.yml
File metadata and controls
220 lines (196 loc) · 7.15 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
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
name: Build Binaries
on:
push:
tags: ['*/v*']
workflow_dispatch:
inputs:
tag:
description: 'Tag to build (e.g., opendata-log/v0.1.1)'
required: true
type: string
env:
CARGO_TERM_COLOR: always
jobs:
check-binary:
name: Check if crate has binary
runs-on: ubuntu-latest
outputs:
has_binary: ${{ steps.check.outputs.has_binary }}
crate_name: ${{ steps.check.outputs.crate_name }}
version: ${{ steps.check.outputs.version }}
features: ${{ steps.check.outputs.features }}
tag: ${{ steps.check.outputs.tag }}
docker_image: ${{ steps.check.outputs.docker_image }}
steps:
- name: Parse tag and check for binary
id: check
run: |
TAG="${{ inputs.tag || github.ref_name }}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
CRATE_NAME="${TAG%/v*}"
VERSION="${TAG#*/v}"
echo "crate_name=$CRATE_NAME" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
case "$CRATE_NAME" in
opendata-log)
echo "has_binary=true" >> "$GITHUB_OUTPUT"
echo "features=http-server" >> "$GITHUB_OUTPUT"
echo "docker_image=log" >> "$GITHUB_OUTPUT"
;;
opendata-timeseries)
echo "has_binary=true" >> "$GITHUB_OUTPUT"
echo "features=remote-write" >> "$GITHUB_OUTPUT"
echo "docker_image=timeseries" >> "$GITHUB_OUTPUT"
;;
opendata-vector)
echo "has_binary=true" >> "$GITHUB_OUTPUT"
echo "features=http-server" >> "$GITHUB_OUTPUT"
echo "docker_image=vector" >> "$GITHUB_OUTPUT"
;;
*)
echo "has_binary=false" >> "$GITHUB_OUTPUT"
echo "features=" >> "$GITHUB_OUTPUT"
echo "docker_image=" >> "$GITHUB_OUTPUT"
;;
esac
create-release:
name: Create GitHub Release
needs: [check-binary]
if: needs.check-binary.outputs.has_binary == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.check-binary.outputs.tag }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-binary.outputs.tag }}
name: ${{ needs.check-binary.outputs.crate_name }} v${{ needs.check-binary.outputs.version }}
generate_release_notes: true
draft: false
build-binaries:
name: Build ${{ matrix.target }}
needs: [check-binary, create-release]
if: needs.check-binary.outputs.has_binary == 'true'
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- name: Free Disk Space (Ubuntu)
if: runner.os == 'Linux'
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: true
- uses: actions/checkout@v4
with:
ref: ${{ needs.check-binary.outputs.tag }}
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: release-${{ matrix.target }}
- name: Build
run: cargo build --release -p ${{ needs.check-binary.outputs.crate_name }} --features ${{ needs.check-binary.outputs.features }}
- name: Package binary (unix)
if: runner.os != 'Windows'
run: |
cd target/release
tar -czvf ../../${{ needs.check-binary.outputs.crate_name }}-${{ needs.check-binary.outputs.version }}-${{ matrix.target }}.tar.gz ${{ needs.check-binary.outputs.crate_name }}
- name: Package binary (windows)
if: runner.os == 'Windows'
run: |
cd target/release
7z a ../../${{ needs.check-binary.outputs.crate_name }}-${{ needs.check-binary.outputs.version }}-${{ matrix.target }}.zip ${{ needs.check-binary.outputs.crate_name }}.exe
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-binary.outputs.tag }}
files: |
${{ needs.check-binary.outputs.crate_name }}-*.tar.gz
${{ needs.check-binary.outputs.crate_name }}-*.zip
build-docker:
name: Build Docker image
needs: [check-binary, create-release]
if: needs.check-binary.outputs.docker_image != ''
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ needs.check-binary.outputs.docker_image }}
steps:
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: true
- uses: actions/checkout@v4
with:
ref: ${{ needs.check-binary.outputs.tag }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=v${{ needs.check-binary.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.check-binary.outputs.version }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ needs.check-binary.outputs.docker_image }}/Dockerfile
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
- name: Output image URI
run: |
echo "## Docker Image Published" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Image:** \`${{ env.IMAGE_NAME }}\`" >> "$GITHUB_STEP_SUMMARY"
echo "**Tags:**" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.meta.outputs.tags }}' | while read -r tag; do
echo "- \`${tag}\`" >> "$GITHUB_STEP_SUMMARY"
done