Skip to content

Commit 2d0b412

Browse files
authored
CI - Test spacetimedb-update self-install (#2637)
Co-authored-by: Zeke Foppa <[email protected]>
1 parent ae85f64 commit 2d0b412

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,44 @@ jobs:
218218

219219
- name: Run bindgen tests
220220
run: cargo test -p spacetimedb-cli
221+
222+
update:
223+
name: Test spacetimedb-update flow
224+
permissions: read-all
225+
strategy:
226+
matrix:
227+
include:
228+
- { target: x86_64-unknown-linux-gnu, runner: spacetimedb-runner }
229+
- { target: aarch64-unknown-linux-gnu, runner: arm-runner }
230+
- { target: aarch64-apple-darwin, runner: macos-latest }
231+
- { target: x86_64-pc-windows-msvc, runner: windows-latest }
232+
runs-on: ${{ matrix.runner }}
233+
steps:
234+
- name: Checkout
235+
uses: actions/checkout@v3
236+
237+
- name: Install Rust
238+
uses: dsherret/rust-toolchain-file@v1
239+
240+
- name: Install rust target
241+
run: rustup target add ${{ matrix.target }}
242+
243+
- name: Install packages
244+
if: ${{ matrix.runner == 'arm-runner' }}
245+
shell: bash
246+
run: sudo apt install libssl-dev
247+
248+
- name: Build spacetimedb-update
249+
run: cargo build --features github-token-auth --target ${{ matrix.target }} -p spacetimedb-update
250+
251+
- name: Run self-install
252+
env:
253+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
254+
shell: bash
255+
run: |
256+
ROOT_DIR="$(mktemp -d)"
257+
# NOTE(bfops): We need the `github-token-auth` feature because we otherwise tend to get ratelimited when we try to fetch `/releases/latest`.
258+
# My best guess is that, on the GitHub runners, the "anonymous" ratelimit is shared by *all* users of that runner (I think this because it
259+
# happens very frequently on the `macos-runner`, but we haven't seen it on any others).
260+
cargo run --features github-token-auth --target ${{ matrix.target }} -p spacetimedb-update -- self-install --root-dir="${ROOT_DIR}" --yes
261+
"${ROOT_DIR}"/spacetime --root-dir="${ROOT_DIR}" help

crates/update/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ rust-version.workspace = true
66
license-file = "LICENSE"
77
publish = false
88

9+
[features]
10+
# NOTE(bfops): This is not a well-thought-through feature. It's really only meant for internal testing/debugging.
11+
# Specifically, we use it in some CI.
12+
github-token-auth = []
13+
914
[dependencies]
1015
spacetimedb-paths.workspace = true
1116

crates/update/src/cli.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ enum VersionSubcommand {
8989
}
9090

9191
fn reqwest_client() -> anyhow::Result<reqwest::Client> {
92-
Ok(reqwest::Client::builder()
93-
.user_agent(format!("SpacetimeDB CLI/{}", env!("CARGO_PKG_VERSION")))
94-
.build()?)
92+
let mut client = reqwest::Client::builder();
93+
#[cfg(feature = "github-token-auth")]
94+
{
95+
use reqwest::header;
96+
if let Ok(token) = std::env::var("GITHUB_TOKEN") {
97+
eprintln!("HTTP requests will use the GITHUB_TOKEN from your environment");
98+
let mut headers = header::HeaderMap::new();
99+
headers.insert(header::AUTHORIZATION, format!("Bearer {}", token).parse().unwrap());
100+
client = client.default_headers(headers);
101+
}
102+
}
103+
client = client.user_agent(format!("SpacetimeDB CLI/{}", env!("CARGO_PKG_VERSION")));
104+
Ok(client.build()?)
95105
}
96106

97107
fn tokio_block_on<Fut: Future>(fut: Fut) -> anyhow::Result<Fut::Output> {

0 commit comments

Comments
 (0)