diff --git a/.github/workflows/upgrade-version-check.yml b/.github/workflows/upgrade-version-check.yml index 41f8f178573..f6abff297e5 100644 --- a/.github/workflows/upgrade-version-check.yml +++ b/.github/workflows/upgrade-version-check.yml @@ -15,8 +15,16 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + # pnpm is required for regenerating the typescript bindings + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - uses: pnpm/action-setup@v4 + with: + run_install: true - name: Verify that upgrade-version still works - run: cargo bump-versions 123.456.789 --rust-and-cli --csharp --typescript + run: cargo bump-versions 123.456.789 --rust-and-cli --csharp --typescript --accept-snapshots - name: Show diff run: git diff HEAD diff --git a/tools/upgrade-version/src/main.rs b/tools/upgrade-version/src/main.rs index cead3e53883..c9a02732ce8 100644 --- a/tools/upgrade-version/src/main.rs +++ b/tools/upgrade-version/src/main.rs @@ -127,6 +127,12 @@ fn main() -> anyhow::Result<()> { .help("Update all targets (equivalent to --typescript --rust-and-cli --csharp)") .conflicts_with_all(["typescript", "rust-and-cli", "csharp"]), ) + .arg( + Arg::new("accept-snapshots") + .long("accept-snapshots") + .action(clap::ArgAction::SetTrue) + .help("If there are snapshots to review automatically accept them all."), + ) .group( ArgGroup::new("update-targets") .args(["all", "typescript", "rust-and-cli", "csharp"]) @@ -184,7 +190,49 @@ fn main() -> anyhow::Result<()> { process_license_file("LICENSE.txt", &full_version); process_license_file("licenses/BSL.txt", &full_version); + println!("$> cargo check"); cmd!("cargo", "check").run().expect("Cargo check failed!"); + + println!("$> pnpm install"); + cmd!("pnpm", "install").run().expect("pnpm run build failed!"); + + println!("$> pnpm run build"); + cmd!("pnpm", "run", "build").run().expect("pnpm run build failed!"); + + println!("$> pnpm --dir templates/chat-react-ts generate"); + cmd!("pnpm", "--dir", "templates/chat-react-ts", "generate") + .run() + .expect("pnpm generate failed!"); + + if matches.get_flag("accept-snapshots") { + // Generate and auto-accept snapshots + println!("$> INSTA_UPDATE=always cargo test -p spacetimedb-codegen --test codegen"); + cmd!("cargo", "test", "-p", "spacetimedb-codegen", "--test", "codegen") + .env("INSTA_UPDATE", "always") + .run() + .expect("cargo test -p spacetimedb-codegen --test codegen (INSTA_UPDATE=always) failed!"); + } else { + println!("$> cargo install cargo-insta"); + cmd!("cargo", "install", "cargo-insta") + .run() + .expect("cargo install cargo-insta failed!"); + + // Initial test - this will generate snapshots. This is expected to fail. + println!("$> cargo test -p spacetimedb-codegen --test codegen"); + let _ = cmd!("cargo", "test", "-p", "spacetimedb-codegen", "--test", "codegen").run(); + + // Review the new snapshots + println!("$> cargo insta review"); + cmd!("cargo", "insta", "review") + .run() + .expect("cargo insta review failed!"); + + // Test again now that the user has had a chance to accept the snapshots + println!("$> cargo test -p spacetimedb-codegen --test codegen"); + cmd!("cargo", "test", "-p", "spacetimedb-codegen", "--test", "codegen") + .run() + .expect("cargo test -p spacetimedb-codegen --test codegen failed!"); + } } if matches.get_flag("typescript") || matches.get_flag("all") {