Skip to content

Commit c5be43d

Browse files
authored
Workflow to build the gnd binary (#6013)
* .github: Create a workflow for building gnd binaries * .github: Codesign gnd binary for macOs * .github: notarize gnd binary for macOs
1 parent 655764d commit c5be43d

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Build gnd Binaries
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
name: Build gnd for ${{ matrix.target }}
9+
runs-on: ${{ matrix.runner }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
include:
14+
- target: x86_64-unknown-linux-gnu
15+
runner: ubuntu-latest
16+
asset_name: gnd-linux-x86_64
17+
- target: aarch64-unknown-linux-gnu
18+
runner: ubuntu-24.04-arm
19+
asset_name: gnd-linux-aarch64
20+
- target: x86_64-apple-darwin
21+
runner: macos-13
22+
asset_name: gnd-macos-x86_64
23+
- target: aarch64-apple-darwin
24+
runner: macos-latest
25+
asset_name: gnd-macos-aarch64
26+
- target: x86_64-pc-windows-msvc
27+
runner: windows-latest
28+
asset_name: gnd-windows-x86_64.exe
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Install Rust toolchain
35+
run: |
36+
rustup toolchain install stable
37+
rustup target add ${{ matrix.target }}
38+
rustup default stable
39+
40+
- name: Rust Cache
41+
uses: Swatinem/rust-cache@v2
42+
with:
43+
key: ${{ matrix.target }}
44+
45+
- name: Install dependencies (Ubuntu)
46+
if: startsWith(matrix.runner, 'ubuntu')
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install -y libpq-dev protobuf-compiler musl-tools libssl-dev
50+
51+
- name: Install dependencies (macOS)
52+
if: startsWith(matrix.runner, 'macos')
53+
run: |
54+
brew install postgresql protobuf
55+
56+
- name: Install protobuf (Windows)
57+
if: startsWith(matrix.runner, 'windows')
58+
run: choco install protoc
59+
60+
- name: Cache vcpkg
61+
uses: actions/cache@v4
62+
if: startsWith(matrix.runner, 'windows')
63+
id: vcpkg-cache
64+
with:
65+
path: |
66+
${{ github.workspace }}/vcpkg
67+
C:/vcpkg/installed
68+
C:/vcpkg/packages
69+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/Cargo.lock') }}
70+
restore-keys: |
71+
${{ runner.os }}-vcpkg-
72+
73+
- name: Install vcpkg and dependencies (Windows)
74+
if: startsWith(matrix.runner, 'windows') && steps.vcpkg-cache.outputs.cache-hit != 'true'
75+
run: |
76+
# Install vcpkg
77+
git clone https://github.com/microsoft/vcpkg.git
78+
cd vcpkg
79+
.\bootstrap-vcpkg.bat
80+
81+
# Install libpq using vcpkg
82+
.\vcpkg.exe install libpq:x64-windows
83+
shell: pwsh
84+
85+
- name: Set Windows environment variables
86+
if: startsWith(matrix.runner, 'windows')
87+
run: |
88+
echo "VCPKG_ROOT=${{ github.workspace }}/vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Append
89+
echo "LIBPQ_DIR=${{ github.workspace }}/vcpkg/installed/x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append
90+
echo "RUSTFLAGS=-L ${{ github.workspace }}/vcpkg/installed/x64-windows/lib" | Out-File -FilePath $env:GITHUB_ENV -Append
91+
shell: pwsh
92+
93+
- name: Build gnd binary (Unix/Mac)
94+
if: ${{ !startsWith(matrix.runner, 'windows') }}
95+
run: cargo build --bin gnd --release --target ${{ matrix.target }}
96+
97+
- name: Build gnd binary (Windows)
98+
if: startsWith(matrix.runner, 'windows')
99+
run: cargo build --bin gnd --release --target ${{ matrix.target }}
100+
env:
101+
LIBPQ_DIR: ${{ format('{0}/vcpkg/installed/x64-windows', github.workspace) }}
102+
VCPKGRS_DYNAMIC: 1
103+
104+
- name: Sign macOS binary
105+
if: startsWith(matrix.runner, 'macos')
106+
uses: lando/code-sign-action@v3
107+
with:
108+
file: target/${{ matrix.target }}/release/gnd
109+
certificate-data: ${{ secrets.APPLE_CERT_DATA }}
110+
certificate-password: ${{ secrets.APPLE_CERT_PASSWORD }}
111+
certificate-id: ${{ secrets.APPLE_TEAM_ID }}
112+
options: --options runtime
113+
114+
- name: Notarize macOS binary
115+
if: startsWith(matrix.runner, 'macos')
116+
uses: lando/notarize-action@v2
117+
with:
118+
product-path: target/${{ matrix.target }}/release/gnd
119+
appstore-connect-username: ${{ secrets.NOTARIZATION_USERNAME }}
120+
appstore-connect-password: ${{ secrets.NOTARIZATION_PASSWORD }}
121+
appstore-connect-team-id: ${{ secrets.APPLE_TEAM_ID }}
122+
123+
- name: Prepare binary (Unix)
124+
if: ${{ !startsWith(matrix.runner, 'windows') }}
125+
run: |
126+
cp target/${{ matrix.target }}/release/gnd ${{ matrix.asset_name }}
127+
chmod +x ${{ matrix.asset_name }}
128+
gzip ${{ matrix.asset_name }}
129+
130+
- name: Prepare binary (Windows)
131+
if: startsWith(matrix.runner, 'windows')
132+
run: |
133+
copy target\${{ matrix.target }}\release\gnd.exe ${{ matrix.asset_name }}
134+
7z a -tzip ${{ matrix.asset_name }}.zip ${{ matrix.asset_name }}
135+
136+
- name: Upload artifact
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: ${{ matrix.asset_name }}
140+
path: |
141+
${{ matrix.asset_name }}.gz
142+
${{ matrix.asset_name }}.zip
143+
if-no-files-found: error
144+
145+
release:
146+
name: Create Release
147+
needs: build
148+
if: startsWith(github.ref, 'refs/tags/')
149+
runs-on: ubuntu-latest
150+
steps:
151+
- name: Checkout code
152+
uses: actions/checkout@v4
153+
154+
- name: Setup GitHub CLI
155+
run: |
156+
# GitHub CLI is pre-installed on GitHub-hosted runners
157+
gh --version
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
161+
- name: Download all artifacts
162+
uses: actions/download-artifact@v4
163+
with:
164+
path: artifacts
165+
166+
- name: Display structure of downloaded artifacts
167+
run: ls -R artifacts
168+
169+
- name: Upload Assets to Release
170+
run: |
171+
# Extract version from ref (remove refs/tags/ prefix)
172+
VERSION=${GITHUB_REF#refs/tags/}
173+
174+
# Upload Linux x86_64 asset
175+
gh release upload $VERSION artifacts/gnd-linux-x86_64/gnd-linux-x86_64.gz --repo $GITHUB_REPOSITORY
176+
177+
# Upload Linux ARM64 asset
178+
gh release upload $VERSION artifacts/gnd-linux-aarch64/gnd-linux-aarch64.gz --repo $GITHUB_REPOSITORY
179+
180+
# Upload macOS x86_64 asset
181+
gh release upload $VERSION artifacts/gnd-macos-x86_64/gnd-macos-x86_64.gz --repo $GITHUB_REPOSITORY
182+
183+
# Upload macOS ARM64 asset
184+
gh release upload $VERSION artifacts/gnd-macos-aarch64/gnd-macos-aarch64.gz --repo $GITHUB_REPOSITORY
185+
186+
# Upload Windows x86_64 asset
187+
gh release upload $VERSION artifacts/gnd-windows-x86_64.exe/gnd-windows-x86_64.exe.zip --repo $GITHUB_REPOSITORY
188+
env:
189+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)