ci: build Windows binaries; add cross-platform CI test matrix
- release.yml: add x86_64-pc-windows-msvc target, OS-aware packaging (.exe + .zip) - ci.yml: split into lint (fmt/clippy) + test matrix (ubuntu/windows/macos) - use getrandom for the admin/key token CSPRNG (secure on Windows too) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
74d0295181
commit
5b5f23b33c
@@ -2,11 +2,11 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, master ]
|
branches: [main, master]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -18,6 +18,18 @@ jobs:
|
|||||||
run: cargo fmt --all -- --check
|
run: cargo fmt --all -- --check
|
||||||
- name: Clippy
|
- name: Clippy
|
||||||
run: cargo clippy --all-targets -- -D warnings
|
run: cargo clippy --all-targets -- -D warnings
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: test (${{ matrix.os }})
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-14]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release
|
run: cargo build --release
|
||||||
- name: Test
|
- name: Test
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ jobs:
|
|||||||
target: x86_64-unknown-linux-gnu
|
target: x86_64-unknown-linux-gnu
|
||||||
- os: macos-14
|
- os: macos-14
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
|
- os: windows-latest
|
||||||
|
target: x86_64-pc-windows-msvc
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
@@ -47,12 +49,19 @@ jobs:
|
|||||||
- name: Package
|
- name: Package
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
bin=cortiq-gateway
|
||||||
|
[ "${{ runner.os }}" = "Windows" ] && bin=cortiq-gateway.exe
|
||||||
staging="cortiq-gateway-${{ github.ref_name }}-${{ matrix.target }}"
|
staging="cortiq-gateway-${{ github.ref_name }}-${{ matrix.target }}"
|
||||||
mkdir "$staging"
|
mkdir "$staging"
|
||||||
cp "target/${{ matrix.target }}/release/cortiq-gateway" "$staging"/
|
cp "target/${{ matrix.target }}/release/$bin" "$staging"/
|
||||||
cp README.md LICENSE config/gateway.example.toml "$staging"/
|
cp README.md LICENSE config/gateway.example.toml "$staging"/
|
||||||
tar czf "$staging.tar.gz" "$staging"
|
if [ "${{ runner.os }}" = "Windows" ]; then
|
||||||
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
|
7z a "$staging.zip" "$staging" >/dev/null
|
||||||
|
echo "ASSET=$staging.zip" >> "$GITHUB_ENV"
|
||||||
|
else
|
||||||
|
tar czf "$staging.tar.gz" "$staging"
|
||||||
|
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
|
||||||
|
fi
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
Generated
+1
@@ -272,6 +272,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
|
"getrandom 0.2.17",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ arc-swap = "1"
|
|||||||
rust-embed = "8"
|
rust-embed = "8"
|
||||||
mime_guess = "2"
|
mime_guess = "2"
|
||||||
|
|
||||||
|
# cross-platform CSPRNG for admin/key token generation (Linux/macOS/Windows)
|
||||||
|
getrandom = "0.2"
|
||||||
|
|
||||||
# streaming / async utils
|
# streaming / async utils
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
|||||||
+3
-4
@@ -73,12 +73,11 @@ fn current_cfg(state: &SharedState) -> Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Random hex token from `n_bytes` bytes of cryptographic randomness.
|
/// Random hex token from `n_bytes` bytes of cryptographic randomness.
|
||||||
|
/// Uses the OS CSPRNG via `getrandom` (works on Linux/macOS/Windows); falls back
|
||||||
|
/// to a time-based generator only in the extremely unlikely event that fails.
|
||||||
pub fn random_token(n_bytes: usize) -> String {
|
pub fn random_token(n_bytes: usize) -> String {
|
||||||
let mut buf = vec![0u8; n_bytes];
|
let mut buf = vec![0u8; n_bytes];
|
||||||
if let Ok(mut f) = std::fs::File::open("/dev/urandom") {
|
if getrandom::getrandom(&mut buf).is_err() {
|
||||||
use std::io::Read;
|
|
||||||
let _ = f.read_exact(&mut buf);
|
|
||||||
} else {
|
|
||||||
let t = std::time::SystemTime::now()
|
let t = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|||||||
Reference in New Issue
Block a user