-
Notifications
You must be signed in to change notification settings - Fork 9
198 lines (170 loc) · 5.92 KB
/
Copy pathpost-release.yml
File metadata and controls
198 lines (170 loc) · 5.92 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
name: Post Release
on:
release:
types: [published]
workflow_dispatch: # Allow manual trigger
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Build release binaries for multiple platforms
build-binaries:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: klag-exporter
asset_name: klag-exporter-linux-x86_64
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
artifact_name: klag-exporter
asset_name: klag-exporter-linux-aarch64
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
- name: Install dependencies
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/azure-cli.list
sudo apt-get update
sudo apt-get install -y cmake build-essential libssl-dev libsasl2-dev zlib1g-dev libzstd-dev liblz4-dev pkg-config libcurl4-openssl-dev
- uses: dtolnay/rust-toolchain@1.93
with:
targets: ${{ matrix.target }}
- name: Rust version
id: rust_version
run: echo "version=$(rustc --version | awk '{print $2}')" >> $GITHUB_OUTPUT
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ steps.rust_version.outputs.version }}-${{ matrix.target }}-${{ github.event.release.tag_name }}-${{ hashFiles('**/Cargo.lock') }}
cache-targets: true
cache-on-failure: true
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package binary
run: |
cd target/${{ matrix.target }}/release
tar czvf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
cd ../../..
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.tar.gz
# Upload binaries to GitHub Release
upload-binaries:
name: Upload Binaries to Release
needs: build-binaries
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Upload binaries to release
uses: softprops/action-gh-release@v2
with:
files: artifacts/**/*.tar.gz
tag_name: ${{ github.event.release.tag_name }}
make_latest: true
# Build and push Docker image
docker:
name: Build and Push Docker Image
needs: build-binaries
runs-on: ubuntu-22.04
permissions:
contents: write
packages: write
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.event.release.tag_name }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare binaries for Docker
run: |
mkdir -p binaries/amd64 binaries/arm64
tar -xzf artifacts/klag-exporter-linux-x86_64/klag-exporter-linux-x86_64.tar.gz -C binaries/amd64
tar -xzf artifacts/klag-exporter-linux-aarch64/klag-exporter-linux-aarch64.tar.gz -C binaries/arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.release
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
helm-chart:
name: Package and Push Helm Chart
runs-on: ubuntu-22.04
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.release.tag_name }}
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: "latest"
- name: Package Helm chart
run: |
helm package ./helm/klag-exporter -d /tmp
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract chart version
id: chart_version
run: |
echo "version=$(grep '^version:' ./helm/klag-exporter/Chart.yaml | awk '{print $2}')" >> $GITHUB_OUTPUT
- name: Push chart to OCI registry
run: |
helm push /tmp/klag-exporter-${{ steps.chart_version.outputs.version }}.tgz oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/helm