From 5426d28b0114448930a004a7c8f7b2498005677d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 11 Oct 2019 17:29:38 +0200 Subject: Allow running the module updater over multiple branches This will make it easier to run the updater as a bot in the future. Change-Id: If9944225d7d245719f198b29935e71fb9713db76 Reviewed-by: Aapo Keskimolo --- src/qtmoduleupdater/autorun.go | 73 +++++++++++++++++++++++++++++++++ src/qtmoduleupdater/autorun.json | 5 +++ src/qtmoduleupdater/autorun_schema.json | 18 ++++++++ src/qtmoduleupdater/main.go | 17 +++++++- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/qtmoduleupdater/autorun.go create mode 100644 src/qtmoduleupdater/autorun.json create mode 100644 src/qtmoduleupdater/autorun_schema.json (limited to 'src') diff --git a/src/qtmoduleupdater/autorun.go b/src/qtmoduleupdater/autorun.go new file mode 100644 index 00000000..4cfc6fcc --- /dev/null +++ b/src/qtmoduleupdater/autorun.go @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the repo tools module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" +) + +// AutoRunSettings is used to read autorun.json. +type AutoRunSettings struct { + Version int `json:"version"` + Branches []string `json:"branches"` +} + +func (settings *AutoRunSettings) load() error { + file, err := os.Open("autorun.json") + if err != nil { + return fmt.Errorf("Error opening autorun.json for reading: %s", err) + } + defer file.Close() + content, err := ioutil.ReadAll(file) + if err != nil { + return fmt.Errorf("Error reading from autorun.json: %s", err) + } + return json.Unmarshal(content, settings) +} + +func (settings *AutoRunSettings) runUpdates(gerrit *gerritInstance) { + // ### might make sense to turn this into a loop over known products or read from settings. On the other hand we want + // to avoid coding products into the file for now but rather query a list of products from Gerrit (in the future). Therefore + // I'm keeping the product out of the file + product := "qt/qt5" + for _, branch := range settings.Branches { + batch, err := newModuleUpdateBatch(product, branch, "") + if err != nil { + fmt.Printf("Error loading update batch state for %s/%s: %s\n", product, branch, err) + continue + } + + if err := batch.runOneIteration(gerrit); err != nil { + fmt.Printf("Error iterating on update batch for %s/%s: %s\n", product, branch, err) + continue + } + } +} diff --git a/src/qtmoduleupdater/autorun.json b/src/qtmoduleupdater/autorun.json new file mode 100644 index 00000000..046f9c03 --- /dev/null +++ b/src/qtmoduleupdater/autorun.json @@ -0,0 +1,5 @@ +{ + "$schema": "./autorun_schema.json", + "version": 1, + "branches": ["dev"] +} diff --git a/src/qtmoduleupdater/autorun_schema.json b/src/qtmoduleupdater/autorun_schema.json new file mode 100644 index 00000000..3d8ff75b --- /dev/null +++ b/src/qtmoduleupdater/autorun_schema.json @@ -0,0 +1,18 @@ +{ + "title": "qtmoduleupdater auto-run configuration", + "type": "object", + "properties": { + "version": { + "type": "integer", + "description": "The file format version expected, currently 1." + }, + "branches": { + "type": "array", + "description": "List of qt5 branches to submit updates to.", + "items": { + "type": "string" + } + } + }, + "required": ["version"] +} diff --git a/src/qtmoduleupdater/main.go b/src/qtmoduleupdater/main.go index 0ad79735..301d0fe1 100644 --- a/src/qtmoduleupdater/main.go +++ b/src/qtmoduleupdater/main.go @@ -69,6 +69,8 @@ func appMain() error { flag.BoolVar(&summaryOnly, "summarize", false /*default*/, "") verbose := false flag.BoolVar(&verbose, "verbose", false /*default*/, "Enable verbose logging output") + autorun := false + flag.BoolVar(&autorun, "autorun", false, "Run automatically by reading settings from autorun.json") flag.Parse() if !verbose { @@ -77,8 +79,8 @@ func appMain() error { log.SetOutput(ioutil.Discard) } - if branch == "" { - return fmt.Errorf("missing branch. Please specify -branch=") + if autorun { + stageAsBot = true } gerrit := &gerritInstance{} @@ -92,6 +94,17 @@ func appMain() error { } } + if autorun { + autorun := &AutoRunSettings{} + autorun.load() + autorun.runUpdates(gerrit) + return nil + } + + if branch == "" { + return fmt.Errorf("missing branch. Please specify -branch=") + } + batch, err := newModuleUpdateBatch(product, branch, productRef) if err != nil { return err -- cgit v1.2.3