Unverified Commit a0019ba0 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Fix canary failure caused by the runner modifying Cargo.lock (#1185)

parent 1c90dc5f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1406,6 +1406,7 @@ dependencies = [
 "anyhow",
 "async-trait",
 "tokio",
 "tracing",
]

[[package]]
+6 −1
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@
//
// Also consider using the `AWS_PROFILE` and `AWS_REGION` environment variables
// when running this locally.
//
// CAUTION: This subcommand will `git reset --hard` in some cases. Don't ever run
// it against a smithy-rs repo that you're actively working in.

use anyhow::{bail, Context, Result};
use aws_sdk_cloudwatch as cloudwatch;
@@ -191,7 +194,9 @@ async fn use_correct_revision(opt: &RunOpt) -> Result<()> {
            version, commit_hash
        );
        let smithy_rs_root = git::find_git_repository_root("smithy-rs", ".").context(here!())?;
        git::CheckoutRevision::new(smithy_rs_root, *commit_hash)
        // Reset to the revision rather than checkout since the very act of running the
        // canary-runner can make the working tree dirty by modifying the Cargo.lock file
        git::Reset::new(smithy_rs_root, &["--hard", *commit_hash])
            .spawn()
            .await
            .context(here!())?;
+5 −0
Original line number Diff line number Diff line
#!/bin/bash
if [[ "$1" != "checkout" || "$2" != "test-revision" ]]; then
if [[ "$1" != "reset" || "$2" != "--hard" || "$3" != "some-commit-hash" ]]; then
    echo "wrong arguments" >&2
    exit 1
fi
+3 −3
Original line number Diff line number Diff line
@@ -9,9 +9,6 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use tracing::warn;

mod checkout_revision;
pub use checkout_revision::CheckoutRevision;

mod get_current_tag;
pub use get_current_tag::GetCurrentTag;

@@ -21,6 +18,9 @@ pub use get_last_commit::GetLastCommit;
mod get_repo_root;
pub use get_repo_root::GetRepoRoot;

mod reset;
pub use reset::Reset;

/// Attempts to find git repository root from the given location.
pub fn find_git_repository_root(repo_name: &str, location: impl AsRef<Path>) -> Result<PathBuf> {
    let path = GetRepoRoot::new(location.as_ref()).run()?;
+20 −18
Original line number Diff line number Diff line
@@ -8,33 +8,35 @@ use anyhow::Result;
use std::path::PathBuf;
use std::process::Command;

pub struct CheckoutRevision {
pub struct Reset {
    program: &'static str,
    path: PathBuf,
    revision: String,
    args: Vec<String>,
}

impl CheckoutRevision {
    pub fn new(path: impl Into<PathBuf>, revision: impl Into<String>) -> Self {
        CheckoutRevision {
impl Reset {
    pub fn new(path: impl Into<PathBuf>, args: &[&str]) -> Self {
        Reset {
            program: "git",
            path: path.into(),
            revision: revision.into(),
            args: args.iter().map(|&s| s.to_string()).collect(),
        }
    }
}

impl ShellOperation for CheckoutRevision {
impl ShellOperation for Reset {
    type Output = ();

    fn run(&self) -> Result<()> {
        let mut command = Command::new(self.program);
        command.arg("checkout");
        command.arg(&self.revision);
        command.arg("reset");
        for arg in &self.args {
            command.arg(arg);
        }
        command.current_dir(&self.path);

        let output = command.output()?;
        handle_failure("checkout revision", &output)?;
        handle_failure("git reset", &output)?;
        Ok(())
    }
}
@@ -44,28 +46,28 @@ mod tests {
    use super::*;

    #[test]
    fn checkout_revision_success() {
        CheckoutRevision {
            program: "./git_checkout_revision",
    fn reset_success() {
        Reset {
            program: "./git_reset",
            path: "./fake_git".into(),
            revision: "test-revision".into(),
            args: vec!["--hard".to_string(), "some-commit-hash".to_string()],
        }
        .run()
        .unwrap();
    }

    #[test]
    fn checkout_revision_failure() {
        let result = CheckoutRevision {
    fn reset_failure() {
        let result = Reset {
            program: "./git_fails",
            path: "./fake_git".into(),
            revision: "test-revision".into(),
            args: vec!["--hard".to_string(), "some-commit-hash".to_string()],
        }
        .run();

        assert!(result.is_err(), "expected error, got {:?}", result);
        assert_eq!(
            "Failed to checkout revision:\n\
            "Failed to git reset:\n\
            Status: 1\n\
            Stdout: some stdout failure message\n\n\
            Stderr: some stderr failure message\n\n",
Loading