-
Notifications
You must be signed in to change notification settings - Fork 42
170 lines (144 loc) · 5.61 KB
/
release.yaml
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
name: Build & release sidecar
on:
workflow_dispatch:
env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
VERSIONS_REPOSITORY: ${{ github.repository_owner }}/versions
jobs:
build:
name: ${{ matrix.job.name }}
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- { target: aarch64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true, name: linux-arm64 }
- { target: arm-unknown-linux-gnueabihf, os: ubuntu-24.04, use-cross: true, name: linux-armhf }
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-24.04, use-cross: true, name: linux-riscv64 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true, name: linux-x64 }
- { target: x86_64-pc-windows-msvc , os: windows-2019, name: win32-x64 }
- { target: aarch64-pc-windows-msvc , os: windows-2019, name: win32-arm64 }
- { target: x86_64-apple-darwin , os: macos-13, name: darwin-x64 }
- { target: aarch64-apple-darwin , os: macos-14, name: darwin-arm64 }
env:
BUILD_CMD: cargo
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Point gcloud SDK to Python
shell: bash
run: echo "CLOUDSDK_PYTHON=${{ steps.setup-python.outputs.python-path }}" >> $GITHUB_ENV
- name: Extract build target information
shell: bash
run: |
OS=$(echo "${{ matrix.job.name }}" | cut -d'-' -f1)
ARCH=$(echo "${{ matrix.job.name }}" | cut -d'-' -f2)
echo "OS_NAME=${OS}" >> $GITHUB_ENV
echo "ARCH=${ARCH}" >> $GITHUB_ENV
- name: Install Linux cross-compilation dependencies
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get -y update
case ${{ matrix.job.target }} in
arm-unknown-linux-*) sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
aarch64-unknown-linux-gnu) sudo apt-get -y install gcc-aarch64-linux-gnu ;;
esac
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.79.0
targets: ${{ matrix.job.target }}
components: rust-src
- name: Install target std library
if: matrix.job.target == 'aarch64-pc-windows-msvc'
run: |
rustup target add aarch64-pc-windows-msvc
rustup component add rust-std-aarch64-pc-windows-msvc
- name: Install cross for cross-compilation
if: matrix.job.use-cross
shell: bash
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Overwrite build command env variable
if: matrix.job.use-cross
shell: bash
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
- uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.job.target }}
- name: Build binary
shell: bash
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
- name: Set binary name & path
id: bin
shell: bash
run: |
# Figure out suffix of binary
EXE_suffix=""
case ${{ matrix.job.target }} in
*-pc-windows-*) EXE_suffix=".exe" ;;
esac;
# Setup paths
BIN_NAME="webserver${EXE_suffix}"
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
# Let subsequent steps know where to find the binary
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
- name: Create zip file
shell: pwsh
run: |
# Create a staging directory structure
New-Item -ItemType Directory -Force -Path staging/target/release
# Copy binary to staging directory with correct name
if ($env:RUNNER_OS -eq "Windows") {
Copy-Item "${{ steps.bin.outputs.BIN_PATH }}" "staging/target/release/webserver.exe"
} else {
Copy-Item "${{ steps.bin.outputs.BIN_PATH }}" "staging/target/release/webserver"
}
# Create zip file
Push-Location staging
if ($env:RUNNER_OS -eq "Windows") {
Compress-Archive -Path * -DestinationPath ../sidecar.zip -Force
} else {
zip -r ../sidecar.zip .
}
Pop-Location
- name: Authenticate with Google Cloud
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_GAE_SA_KEY }}'
- name: Configure Google Cloud SDK
uses: 'google-github-actions/setup-gcloud@v2'
with:
project_id: '${{ secrets.GCP_PROJECT_ID }}'
- name: Update version
env:
OS_NAME: ${{ env.OS_NAME }}
ARCH: ${{ env.ARCH }}
GITHUB_TOKEN: ${{ secrets.BINARIES_RELEASE_PAT }}
GITHUB_USERNAME: ${{ github.repository_owner }}
run: |
./update_version.sh
- name: Upload zip to GCP
env:
OS_NAME: ${{ env.OS_NAME }}
ARCH: ${{ env.ARCH }}
CARGO_PKG_VERSION: ${{ env.CARGO_PKG_VERSION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_BUCKET_NAME: ${{ secrets.GCP_BUCKET_NAME }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
shell: bash
run: |
SPECIFIC_VERSION_PATH="${CARGO_PKG_VERSION}/${OS_NAME}/${ARCH}/sidecar.zip"
LATEST_VERSION_PATH="latest/${OS_NAME}/${ARCH}/sidecar.zip"
# Copy the built binary to version-specific folder in GCP bucket
gsutil cp "./sidecar.zip" "gs://sidecar-bin/${SPECIFIC_VERSION_PATH}"
# Also update the latest version
gsutil cp "./sidecar.zip" "gs://sidecar-bin/${LATEST_VERSION_PATH}"