Skip to content

Commit

Permalink
Fix CI on push broken by #506 (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Jun 3, 2024
1 parent 32dbefd commit 513464d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions crates/protocol/crates/schema/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ use wasefire_wire::schema::{View, ViewEnum, ViewFields};
use wasefire_wire::{Wire, Yoke};

fn main() -> Result<()> {
let base = std::env::var("BASE_REF").unwrap_or_else(|_| {
format!("origin/{}", std::env::var("GITHUB_BASE_REF").as_deref().unwrap_or("main"))
});
let new = Schema::new();
new.write().context("writing bin")?;
new.print().context("printing txt")?;
let hash = cmd::output_line(Command::new("git").args(["rev-parse", &base]))?;
if hash == "13a0d6eb5ed261c2c0e89744bb339b99e24d2e2a" {
return Ok(());
}
let old = Schema::old(&base)?;
let old = Schema::old()?;
check(&old.get().result, &new.result).context("checking result")?;
check(&old.get().request, &new.request).context("checking request")?;
check(&old.get().response, &new.response).context("checking response")?;
Expand Down Expand Up @@ -121,13 +114,30 @@ impl Schema<'static> {
}
}

fn old(base: &str) -> Result<Yoke<Schema<'static>>> {
fn old() -> Result<Yoke<Schema<'static>>> {
let base = Self::base()?;
let mut git = Command::new("git");
git.args(["show", &format!("{base}:./{SIDE}.bin")]);
let data = cmd::output(&mut git)?.stdout.into_boxed_slice();
Ok(wasefire_wire::decode_yoke(data)?)
}

fn base() -> Result<String> {
use std::env::var;
use std::env::VarError::*;
Ok(match var("GITHUB_EVENT_NAME").as_deref() {
Ok("pull_request") => format!("origin/{}", var("GITHUB_BASE_REF")?),
Ok("push") => format!("origin/{}", var("GITHUB_REF_NAME")?),
Ok(x) => bail!("unexpected GITHUB_EVENT_NAME {x:?}"),
Err(NotPresent) => match var("BASE_REF") {
Ok(x) => x,
Err(NotPresent) => "origin/main".to_string(),
Err(NotUnicode(x)) => bail!("invalid BASE_REF {x:?}"),
},
Err(NotUnicode(x)) => bail!("invalid GITHUB_EVENT_NAME {x:?}"),
})
}

fn write(&self) -> Result<()> {
fs::write(format!("{SIDE}.bin"), wasefire_wire::encode(self)?)
}
Expand Down

0 comments on commit 513464d

Please sign in to comment.