[2/2] Post base SHA as a parameter to job
diff mbox series

Message ID 20190305062206.25872-2-andrew.donnellan@au1.ibm.com
State New
Headers show
Series
  • [1/2] main: Make apply_patch check description more useful
Related show

Commit Message

Andrew Donnellan March 5, 2019, 6:22 a.m. UTC
It's often useful for jobs to be able to know the specific commit on top of
which the patches have been applied.

Add an extra job parameter, "base", which allows us to send the base commit
ID to Jenkins. Update documentation accordingly.

Closes: #56 ("Post base SHA as a parameter to job")
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 docs/configuration.md   |  3 +++
 examples/openpower.toml |  1 +
 src/main.rs             | 11 +++++++++--
 src/settings.rs         |  9 +++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/docs/configuration.md b/docs/configuration.md
index c7b3b8d66a8e..4402693cab99 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -159,6 +159,9 @@  Individual jobs contain the following:
 - `branch`: the name of the Jenkins build parameter in which the name of the git
   branch to which the patch has been applied will be filled
 
+- `base`: the name of the Jenkins build parameter in which the commit ID on top
+  of which the patch has been applied will be filled (Optional)
+
 - `hefty`: whether this job is a "hefty" test. Hefty tests will only be run on
   the final patch of a series, while non-hefty tests will be run on every patch
   in the series. (Optional, defaults to false)
diff --git a/examples/openpower.toml b/examples/openpower.toml
index c3aedc5f0a57..59331455fc68 100644
--- a/examples/openpower.toml
+++ b/examples/openpower.toml
@@ -47,6 +47,7 @@  token = "33333333333333333333333333333333"
         job = "skiboot-compile-test-snowpatch"
         remote = "GIT_REPO"
         branch = "GIT_REF"
+        base = "GIT_BASE"
 
         [[projects.skiboot.jobs]]
         job = "skiboot-boot-test-snowpatch"
diff --git a/src/main.rs b/src/main.rs
index 5f60cc2293ea..ba8c54d792d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -107,6 +107,7 @@  fn run_test(
     project: &Project,
     tag: &str,
     branch_name: &str,
+    base: &str,
     job: &Job,
 ) -> TestResult {
     let mut params = Vec::<(&str, &str)>::new();
@@ -117,6 +118,10 @@  fn run_test(
     }
     params.push((&job.remote, &project.remote_uri));
     params.push((&job.branch, tag));
+    match job.base {
+        Some(ref base_param) => params.push((&base_param, base)),
+        _ => { }
+    };
 
     info!("Starting job: {}", &job.title);
     let res = backend
@@ -158,6 +163,7 @@  fn run_tests(
     project: &Project,
     tag: &str,
     branch_name: &str,
+    base: &str,
     hefty_tests: bool,
 ) -> Vec<TestResult> {
     let mut results: Vec<TestResult> = Vec::new();
@@ -174,7 +180,7 @@  fn run_tests(
             continue;
         }
 
-        let result = run_test(&jenkins, &project, &tag, &branch_name, &job);
+        let result = run_test(&jenkins, &project, &tag, &branch_name, &base, &job);
 
         results.push(result);
     }
@@ -277,11 +283,12 @@  fn test_patch(
         let project = project.clone();
         let client = client.clone();
         let test_all_branches = project.test_all_branches.unwrap_or(true);
+        let base = commit.id().to_string();
 
         // We've set up a remote branch, time to kick off tests
         let test = thread::Builder::new()
             .name(tag.to_string())
-            .spawn(move || run_tests(&settings, client, &project, &tag, &branch_name, hefty_tests))
+            .spawn(move || run_tests(&settings, client, &project, &tag, &branch_name, &base, hefty_tests))
             .unwrap();
         results.append(&mut test.join().unwrap());
 
diff --git a/src/settings.rs b/src/settings.rs
index 83097dde1e27..128f2030e467 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -82,6 +82,7 @@  pub struct Job {
     pub title: String,
     pub remote: String,
     pub branch: String,
+    pub base: Option<String>,
     pub hefty: bool,
     pub warn_on_fail: bool,
     pub parameters: BTreeMap<String, String>,
@@ -109,6 +110,7 @@  impl<'de> Deserialize<'de> for Job {
                 let mut title = None;
                 let mut remote = None;
                 let mut branch = None;
+                let mut base = None;
                 let mut hefty = None;
                 let mut warn_on_fail = None;
                 let mut parameters = BTreeMap::new();
@@ -138,6 +140,12 @@  impl<'de> Deserialize<'de> for Job {
                             }
                             branch = Some(map.next_value()?);
                         }
+                        "base" => {
+                            if base.is_some() {
+                                return Err(de::Error::duplicate_field("base"));
+                            }
+                            base = Some(map.next_value()?);
+                        }
                         "hefty" => {
                             if hefty.is_some() {
                                 return Err(de::Error::duplicate_field("hefty"));
@@ -168,6 +176,7 @@  impl<'de> Deserialize<'de> for Job {
                     title,
                     remote,
                     branch,
+                    base,
                     hefty,
                     warn_on_fail,
                     parameters,