-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (195 loc) · 7.38 KB
/
build.yml
File metadata and controls
221 lines (195 loc) · 7.38 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
221
# .github/workflows/release.yml
name: Releases
on:
push:
tags:
- '**' # Match all tags, e.g. 1.0.0, release-1, beta, etc.
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
REGISTRY_GHCR: ghcr.io/aurabx/harmony
REGISTRY_DOCKERHUB: aurabox/harmony
IMAGE_NAME: harmony
PKG_CONFIG_ALLOW_CROSS: 1
jobs:
build-binaries:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux (most common distros and containers)
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu # Ubuntu, Debian, Fedora, RHEL, etc.
- os: ubuntu-24.04
target: aarch64-unknown-linux-gnu # ARM64 Ubuntu/Debian servers
# macOS (Intel + Apple Silicon)
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
# Windows (x64)
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Rust build
uses: Swatinem/rust-cache@v2
with:
# Use different cache for cross-compilation to avoid glibc version conflicts
key: ${{ matrix.target }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
# --- Cross Compilation Setup (ARM) ---
- name: Install cross for ARM builds
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'armv7-unknown-linux-gnueabihf'
run: cargo install cross --git https://github.com/cross-rs/cross
# --- Build step per OS ---
- name: Build Harmony
shell: bash
run: |
case "${{ runner.os }}" in
Windows)
echo "Building for Windows..."
cargo build --release --target ${{ matrix.target }}
;;
macOS)
echo "Building for macOS..."
cargo build --release --target ${{ matrix.target }}
;;
Linux)
case "${{ matrix.target }}" in
aarch64-unknown-linux-gnu|armv7-unknown-linux-gnueabihf)
echo "Building for ARM target ${{ matrix.target }} with cross..."
cross build --release --target ${{ matrix.target }}
;;
*)
echo "Building for Linux target ${{ matrix.target }}..."
cargo build --release --target ${{ matrix.target }}
;;
esac
;;
esac
# --- Package ---
- name: Package artefacts
shell: bash
run: |
mkdir -p release
cp target/${{ matrix.target }}/release/harmony* release/ 2>/dev/null || \
cp target/${{ matrix.target }}/release/harmony.exe release/ || true
cd release
if [ "${{ runner.os }}" = "Windows" ]; then
tar czf harmony-${{ matrix.target }}.tar.gz harmony*.exe || true
else
tar czf harmony-${{ matrix.target }}.tar.gz harmony* || true
fi
# --- Checksums ---
- name: Generate SHA256 (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Get-FileHash "release/harmony-${{ matrix.target }}.tar.gz" -Algorithm SHA256 |
ForEach-Object { "$($_.Hash) harmony-${{ matrix.target }}.tar.gz" } |
Out-File "release/harmony-${{ matrix.target }}.sha256" -Encoding ascii
- name: Generate SHA256 (non-Windows)
if: runner.os != 'Windows'
shell: bash
run: |
shasum -a 256 release/harmony-${{ matrix.target }}.tar.gz > release/harmony-${{ matrix.target }}.sha256
- name: Upload artefacts
uses: actions/upload-artifact@v4
with:
name: harmony-${{ matrix.target }}
path: release/
# ---------- 2. Build and push Docker images ----------
docker:
name: Build and push multi-arch Docker images
runs-on: ubuntu-latest
needs: build-binaries
permissions:
contents: read
packages: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./binaries
- name: Prepare Linux binaries
run: |
# Extract binaries from tarballs
cd binaries/harmony-x86_64-unknown-linux-gnu && tar xzf harmony-x86_64-unknown-linux-gnu.tar.gz && cd ../..
cd binaries/harmony-aarch64-unknown-linux-gnu && tar xzf harmony-aarch64-unknown-linux-gnu.tar.gz && cd ../..
# Move to expected locations for Docker build
mv binaries/harmony-x86_64-unknown-linux-gnu/harmony harmony-amd64 || true
mv binaries/harmony-aarch64-unknown-linux-gnu/harmony harmony-arm64 || true
# Verify binaries exist
ls -lh harmony-* || echo "Warning: binaries not found"
- uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image tags
id: meta
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG=${GITHUB_REF_NAME}
echo "tags=${{ env.REGISTRY_DOCKERHUB }}:${TAG},${{ env.REGISTRY_DOCKERHUB }}:latest,${{ env.REGISTRY_GHCR }}:${TAG},${{ env.REGISTRY_GHCR }}:latest" >> $GITHUB_OUTPUT
else
TAG="test-${GITHUB_SHA::8}"
echo "tags=${{ env.REGISTRY_DOCKERHUB }}:${TAG},${{ env.REGISTRY_GHCR }}:${TAG}" >> $GITHUB_OUTPUT
fi
echo "push=true" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: ${{ steps.meta.outputs.push }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ---------- 3. Publish GitHub Release ----------
release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs: [build-binaries] # Docker runs in parallel, doesn't block release
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Download Harmony build artefacts only
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: harmony-* # Only match real binaries
merge-multiple: true # Flattens them into one directory
- name: Generate combined checksums manifest
shell: bash
run: |
cd artifacts
find . -type f -name "*.sha256" -exec cat {} \; > checksums.txt
echo "Combined checksums:"
cat checksums.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Harmony ${{ github.ref_name }}
files: ./artifacts/**/*
draft: false
prerelease: ${{ contains(github.ref, 'beta') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}