From patchwork Wed Oct 16 06:53:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 1177619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46tNLS427lz9sPF for ; Wed, 16 Oct 2019 17:53:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=russell.cc header.i=@russell.cc header.b="o/zOKpc+"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OvrRgsUU"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46tNLS0mwLzDqd1 for ; Wed, 16 Oct 2019 17:53:52 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=russell.cc (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=ruscur@russell.cc; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=russell.cc header.i=@russell.cc header.b="o/zOKpc+"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OvrRgsUU"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46tNLD0B22zDqVx for ; Wed, 16 Oct 2019 17:53:39 +1100 (AEDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 4158521C24; Wed, 16 Oct 2019 02:53:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 16 Oct 2019 02:53:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=X1TWqbtuZSveWfWLGYJF1EDQJL aWKy8LPCuOAktiCPA=; b=o/zOKpc+Wu9FLnG2p9zAC17SeXe2T6kbU8gW6cyhw6 C95tafo9I81v6AXPP85upcwxoZKkuNMG0ythR4IQyTWn1e8zLLSSTuWxG3uhxGQ4 rdw6KM/2QkiqnetbVX8HXLpJetbQwhijNYMw6HJYo9yKdsLfjsZ3okIX4o0iS4bI FHRGtZzavbF9NPUu25BTWxwl+kas+v4Zrw1GXFb3RwEykivNfBy5eWfVe22WyWTT NzzPcJ2KUaJG/sdNFvOydCRQJnAxcedLc9Fpbz83auM1pOh4mgrdkIjb9eCWazrA y8eTcwK+Jxt1kODmWS/yCteszWAuQwTz2EIdJCdJCSvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=X1TWqbtuZSveWfWLG YJF1EDQJLaWKy8LPCuOAktiCPA=; b=OvrRgsUU3gXI0ytkqKL4DhqLhgRqlWUH0 Knr0mEabAWvv23ci53VxH6j/yd6ijWANDvBg3aAwknLCvQnTZbvat9vLScUg6fOR s0es/Bam22uUiY6H+167HKpUDNe6DGgcQnh96j6BJwWX6VKf8UJLwTE2oiT0tWu3 k56diIooCj70qhySH1DoHKYjQR00oo4qrNnj+LoSiO19Obq4i8fWsk7C+0lWxe2S V5jSeP5EvPn/eBZXprEGUd5Ad4HPDMTQjT16q8wbPXWkuCbgt1cjtsNSutTuTTII 6JbH11ObSLXJoG3N/NTTClRzcT/cXDIjSYwOXUVRW+j4Uo1EkO5eA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrjeeggdduudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdludehmdenucfjughrpefhvf fufffkofgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhrvgih uceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuffhomhgrihhnpehskhhisghooh htrdhjohgsshenucfkphepuddvvddrleelrdekvddruddtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehruhhstghurhesrhhushhsvghllhdrtggtnecuvehluhhsthgvrhfuihiivg eptd X-ME-Proxy: Received: from crackle.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 2614DD6005B; Wed, 16 Oct 2019 02:53:33 -0400 (EDT) From: Russell Currey To: snowpatch@lists.ozlabs.org Date: Wed, 16 Oct 2019 17:53:05 +1100 Message-Id: <20191016065305.100695-1-ruscur@russell.cc> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [snowpatch] [PATCH] Implement tunable preservation of remote branches X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, Russell Currey Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" A new parameter, branch_preserve_policy, allows users to specify whether they want to preserve all remote branches, just full series or standalone patches, or none (default, current behaviour). In addition, users can specify a separate remote to push to, allowing branches to be preserved while still deleting them from the main remote used for testing. Signed-off-by: Russell Currey --- docs/configuration.md | 18 ++++++++++++++++-- examples/openpower.toml | 2 ++ src/main.rs | 26 ++++++++++++++++++++++++-- src/settings.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4402693..aba3a84 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -144,7 +144,21 @@ Example: - `remote_uri`: the URI of the remote -- `push_results`: whether test results should be pushed to Patchwork for this project +- `push_results`: whether test results should be pushed to Patchwork for this + project + +- `branch_preserve_policy`: set the policy for how snowpatch will handle + branches on git remotes after tests have run. + + "ALL": preserves all branches on the remote. + "SERIES": only preserves full series or standalone patches. + "NONE": deletes branches on the remote after testing. + + (Optional, defaults to NONE) + +- `branch_preserve_remote`: only valid if `branch_preserve_policy` is not NONE. + Specify the name of a git remote that will only be used for branch + preservation. If set, branches will be deleted on the main remote. (Optional) Individual jobs contain the following: @@ -169,4 +183,4 @@ Individual jobs contain the following: - `warn_on_fail`: if true, this job will return a warning rather than a failure if it fails (Optional, defaults to false) -- Any further parameters will be passed to Jenkins as build parameters \ No newline at end of file +- Any further parameters will be passed to Jenkins as build parameters diff --git a/examples/openpower.toml b/examples/openpower.toml index 5933145..f67d8f5 100644 --- a/examples/openpower.toml +++ b/examples/openpower.toml @@ -42,6 +42,8 @@ token = "33333333333333333333333333333333" remote_name = "github" remote_uri = "git@github.com:ruscur/skiboot.git" push_results = false + branch_preserve_policy = "SERIES" # defaults to NONE + branch_preserve_remote = "gitlab" # branch to push to, but not delete from [[projects.skiboot.jobs]] job = "skiboot-compile-test-snowpatch" diff --git a/src/main.rs b/src/main.rs index 809ff18..d92000c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ mod jenkins; use jenkins::JenkinsBackend; mod settings; -use settings::{Config, Job, Project}; +use settings::{BranchPreservePolicy, Config, Job, Project}; mod git; @@ -194,12 +194,16 @@ fn test_patch( hefty_tests: bool, ) -> Vec { let repo = project.get_repo().unwrap(); + let preserve_policy = project + .branch_preserve_policy + .unwrap_or(BranchPreservePolicy::None); let mut results: Vec = Vec::new(); if !path.is_file() { return results; } let tag = utils::sanitise_path(path.file_name().unwrap().to_str().unwrap()); let mut remote = repo.find_remote(&project.remote_name).unwrap(); + let preserve_remote = &project.branch_preserve_remote; let mut push_callbacks = RemoteCallbacks::new(); push_callbacks.credentials(|_, _, _| git::cred_from_settings(&settings.git)); @@ -234,6 +238,18 @@ fn test_patch( if output.is_ok() { git::push_to_remote(&mut remote, &branch, false, &mut push_opts).unwrap(); + if preserve_remote.is_some() + && (preserve_policy == BranchPreservePolicy::All + || (preserve_policy == BranchPreservePolicy::Series && hefty_tests)) + { + git::push_to_remote( + &mut repo.find_remote(preserve_remote.as_ref().unwrap()).unwrap(), + &branch, + false, + &mut push_opts, + ) + .unwrap(); + } } git::checkout_branch(&repo, &branch_name); @@ -282,6 +298,7 @@ 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 @@ -302,7 +319,12 @@ fn test_patch( results.append(&mut test.join().unwrap()); // Delete the remote branch now it's not needed any more - git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap(); + if preserve_remote.is_some() + || preserve_policy == BranchPreservePolicy::None + || (preserve_policy == BranchPreservePolicy::Series && !hefty_tests) + { + git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap(); + } if !test_all_branches { break; diff --git a/src/settings.rs b/src/settings.rs index 5cfd13b..d373b12 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -29,6 +29,13 @@ use std::io::Read; // TODO: Give more informative error messages when we fail to parse. +#[derive(Deserialize, Clone, PartialEq, Copy)] +pub enum BranchPreservePolicy { + All, + Series, + None, +} + #[derive(Deserialize, Clone)] pub struct Git { pub user: String, @@ -67,6 +74,10 @@ pub struct Project { pub remote_uri: String, pub jobs: Vec, pub push_results: bool, + #[serde(default)] // necessary for serde to treat as optional + #[serde(deserialize_with = "parse_preserve_policy")] + pub branch_preserve_policy: Option, + pub branch_preserve_remote: Option, pub category: Option, } @@ -88,6 +99,22 @@ pub struct Job { pub parameters: BTreeMap, } +fn parse_preserve_policy<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let s = String::deserialize(deserializer)?; + + match s.as_ref() { + "ALL" => Ok(Some(BranchPreservePolicy::All)), + "SERIES" => Ok(Some(BranchPreservePolicy::Series)), + "NONE" => Ok(Some(BranchPreservePolicy::None)), + _ => Err(serde::de::Error::custom( + "branch_preserve_policy not one of ALL, SERIES, NONE", + )), + } +} + impl<'de> Deserialize<'de> for Job { fn deserialize(deserializer: D) -> Result where