-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (144 loc) · 6.99 KB
/
Copy pathrelease.yml
File metadata and controls
169 lines (144 loc) · 6.99 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
name: Build and release
on:
push:
tags:
- 'v*'
jobs:
build-linux:
name: Build Linux binaries (glibc)
runs-on: ubuntu-22.04
outputs:
glibc-version: ${{ steps.versions.outputs.glibc-version }}
rust-version: ${{ steps.versions.outputs.rust-version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf
- name: Install cross-compilation dependencies
run: |
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "21.12"
- name: Build Linux binaries (release)
run: |
cargo build --profile optimized --locked --target x86_64-unknown-linux-gnu
cargo build --profile optimized --locked --target aarch64-unknown-linux-gnu
cargo build --profile optimized --locked --target armv7-unknown-linux-gnueabihf
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-aarch64-linux-gnu.tar.gz" --transform 's|.*/||' "target/aarch64-unknown-linux-gnu/optimized/${{ github.event.repository.name }}"
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-armv7-linux-gnueabihf.tar.gz" --transform 's|.*/||' "target/armv7-unknown-linux-gnueabihf/optimized/${{ github.event.repository.name }}"
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-x86_64-linux-gnu.tar.gz" --transform 's|.*/||' "target/x86_64-unknown-linux-gnu/optimized/${{ github.event.repository.name }}"
ls -alh *.tar.gz
- name: Get versions
id: versions
run: |
echo "rust-version=$(rustc --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"
GLIBC_VER=$(ldd --version | awk '/ldd/{print $NF}')
echo "glibc-version=$GLIBC_VER" >> "$GITHUB_OUTPUT"
- name: Upload Linux artifacts
uses: actions/upload-artifact@v7
with:
name: linux-binaries
path: |
${{ github.event.repository.name }}-${{ github.ref_name }}-*.tar.gz
build-macos:
name: Build macOS universal binary
runs-on: macos-latest
outputs:
macos-deployment-target: ${{ steps.build.outputs.macos-deployment-target }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-apple-darwin, aarch64-apple-darwin
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "21.12"
- name: Build macOS universal (release)
id: build
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
run: |
cargo build --profile optimized --locked --target x86_64-apple-darwin
cargo build --profile optimized --locked --target aarch64-apple-darwin
BINARY_NAME="${{ github.event.repository.name }}"
TAG="${{ github.ref_name }}"
lipo -create -output "${BINARY_NAME}" \
target/x86_64-apple-darwin/optimized/"${BINARY_NAME}" \
target/aarch64-apple-darwin/optimized/"${BINARY_NAME}"
zip "${BINARY_NAME}-${TAG}-universal-apple-darwin.zip" "${BINARY_NAME}"
echo "macos-deployment-target=$MACOSX_DEPLOYMENT_TARGET" >> "$GITHUB_OUTPUT"
ls -alh *.zip
- name: Verify macOS deployment target
env:
EXPECTED_TARGET: ${{ steps.build.outputs.macos-deployment-target }}
run: |
BINARY="${{ github.event.repository.name }}"
echo "Verifying deployment target for universal binary: $BINARY"
echo "Expected minimum macOS version: $EXPECTED_TARGET"
echo
# Check x86_64 slice
X86_MINOS=$(otool -l -arch x86_64 "$BINARY" | awk '
/LC_BUILD_VERSION/ || /LC_VERSION_MIN_MACOSX/ {getline; getline; getline; if ($1 == "minos") print $2}
')
echo "x86_64 slice minos: $X86_MINOS"
# Check arm64 slice
ARM64_MINOS=$(otool -l -arch arm64 "$BINARY" | awk '
/LC_BUILD_VERSION/ || /LC_VERSION_MIN_MACOSX/ {getline; getline; getline; if ($1 == "minos") print $2}
')
echo "arm64 slice minos: $ARM64_MINOS"
# Fail if either doesn't match
if [ "$X86_MINOS" != "$EXPECTED_TARGET" ] || [ "$ARM64_MINOS" != "$EXPECTED_TARGET" ]; then
echo "ERROR: Deployment target mismatch!"
echo "Expected: $EXPECTED_TARGET"
echo "Got: x86_64=$X86_MINOS, arm64=$ARM64_MINOS"
exit 1
fi
echo "Success: Both architectures have deployment target $EXPECTED_TARGET"
- name: Upload macOS artifacts
uses: actions/upload-artifact@v7
with:
name: macos-binaries
path: |
${{ github.event.repository.name }}-${{ github.ref_name }}-universal-apple-darwin.zip
release:
name: Github Release
needs: [build-linux, build-macos]
runs-on: "ubuntu-latest"
permissions:
contents: write
steps:
- name: Get semver version from tag
id: tag_name
run: echo "current_version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
- name: Checkout code
uses: actions/checkout@v6
- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
validation_level: warn
version: ${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md
- name: Download Artifacts
uses: actions/download-artifact@v8
with:
merge-multiple: true
- name: Release
uses: ncipollo/release-action@v1
with:
allowUpdates: false
artifactErrorsFailBuild: true
body: "${{ steps.changelog_reader.outputs.changes }} \n\n### Release binaries info\n\n- Release binaries were built using rust ${{ needs.build-linux.outputs.rust-version }}\n- Linux release binaries require glibc>=${{ needs.build-linux.outputs.glibc-version }} (check yours with ``ldd --version``)\n- macOS universal binary (x86_64 + aarch64), requires macOS >= ${{ needs.build-macos.outputs.macos-deployment-target }} (deployment target)"
artifacts: "${{ github.event.repository.name }}-${{github.ref_name}}-*.tar.gz,${{ github.event.repository.name }}-${{github.ref_name}}-*.zip"
immutableCreate: true