From: Cleber Rosa <crosa@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>,
"Erik Skultety" <eskultet@redhat.com>,
qemu-devel@nongnu.org,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Willian Rampazzo" <wrampazz@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: [PATCH v2 1/2] GitLab Gating CI: introduce pipeline-status contrib script
Date: Wed, 2 Sep 2020 18:09:44 -0400 [thread overview]
Message-ID: <20200902220944.GB55646@localhost.localdomain> (raw)
In-Reply-To: <538bde71-5e96-e56d-cbcd-44cf0942590e@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 5787 bytes --]
On Thu, Jul 09, 2020 at 12:13:11PM +0200, Philippe Mathieu-Daudé wrote:
> On 7/9/20 10:55 AM, Erik Skultety wrote:
> > On Wed, Jul 08, 2020 at 10:46:56PM -0400, Cleber Rosa wrote:
> >> This script is intended to be used right after a push to a branch.
> >>
> >> By default, it will look for the pipeline associated with the commit
> >> that is the HEAD of the *local* staging branch. It can be used as a
> >> one time check, or with the `--wait` option to wait until the pipeline
> >> completes.
> >>
> >> If the pipeline is successful, then a merge of the staging branch into
> >> the master branch should be the next step.
> >>
> >> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> >> ---
> >> scripts/ci/gitlab-pipeline-status | 156 ++++++++++++++++++++++++++++++
> >> 1 file changed, 156 insertions(+)
> >> create mode 100755 scripts/ci/gitlab-pipeline-status
> >>
> >> diff --git a/scripts/ci/gitlab-pipeline-status b/scripts/ci/gitlab-pipeline-status
> >> new file mode 100755
> >> index 0000000000..4a9de39872
> >> --- /dev/null
> >> +++ b/scripts/ci/gitlab-pipeline-status
> >> @@ -0,0 +1,156 @@
> >> +#!/usr/bin/env python3
> >> +#
> >> +# Copyright (c) 2019-2020 Red Hat, Inc.
> >> +#
> >> +# Author:
> >> +# Cleber Rosa <crosa@redhat.com>
> >> +#
> >> +# This work is licensed under the terms of the GNU GPL, version 2 or
> >> +# later. See the COPYING file in the top-level directory.
> >> +
> >> +"""
> >> +Checks the GitLab pipeline status for a given commit commit
> >
> > s/commit$/(hash|sha|ID|)
> >
> >> +"""
> >> +
> >> +# pylint: disable=C0103
> >> +
> >> +import argparse
> >> +import http.client
> >> +import json
> >> +import os
> >> +import subprocess
> >> +import time
> >> +import sys
> >> +
> >> +
> >> +def get_local_staging_branch_commit():
> >> + """
> >> + Returns the commit sha1 for the *local* branch named "staging"
> >> + """
> >> + result = subprocess.run(['git', 'rev-parse', 'staging'],
> >
> > If one day Peter decides that "staging" is not a cool name anymore and use a
> > different name for the branch :) we should account for that and make it a
> > variable, possibly even parametrize this function with it.
>
> This script can be used by any fork, not only Peter.
> So having a parameter (default to 'staging') is a requisite IMO.
>
Right, as explained in the reply to Erik, this is just used for
finding the commit ID for the staging branch. Still, I'm making it
configurable in a new patch, and if people want, we can change the
current behavior to accept any kind of revision (but this would
probably mean changing the options or names, given that -c/--commit is
quite descriptive).
> >> + stdin=subprocess.DEVNULL,
> >> + stdout=subprocess.PIPE,
> >> + stderr=subprocess.DEVNULL,
> >> + cwd=os.path.dirname(__file__),
> >> + universal_newlines=True).stdout.strip()
> >> + if result == 'staging':
> >> + raise ValueError("There's no local staging branch")
> >
> > "There's no local branch named 'staging'" would IMO be more descriptive, so as
> > not to confuse it with staging in git.
> >
> >> + if len(result) != 40:
> >> + raise ValueError("Branch staging HEAD doesn't look like a sha1")
> >> + return result
> >> +
> >> +
> >> +def get_pipeline_status(project_id, commit_sha1):
> >> + """
> >> + Returns the JSON content of the pipeline status API response
> >> + """
> >> + url = '/api/v4/projects/{}/pipelines?sha={}'.format(project_id,
> >> + commit_sha1)
> >> + connection = http.client.HTTPSConnection('gitlab.com')
> >> + connection.request('GET', url=url)
> >> + response = connection.getresponse()
> >> + if response.code != http.HTTPStatus.OK:
> >> + raise ValueError("Failed to receive a successful response")
> >> + json_response = json.loads(response.read())
> >
> > a blank line separating the commentary block would slightly help readability
> >
> >> + # afaict, there should one one pipeline for the same project + commit
> >
> > s/one one/be only one/
>
> 'afaict' is not a word.
>
Yes, good point. Thomas has addressed this.
> >
> >> + # if this assumption is false, we can add further filters to the
> >> + # url, such as username, and order_by.
> >> + if not json_response:
> >> + raise ValueError("No pipeline found")
> >> + return json_response[0]
> >> +
> >> +
> >> +def wait_on_pipeline_success(timeout, interval,
> >> + project_id, commit_sha):
> >> + """
> >> + Waits for the pipeline to end up to the timeout given
> >
> > "Waits for the pipeline to finish within the given timeout"
> >
> >> + """
> >> + start = time.time()
> >> + while True:
> >> + if time.time() >= (start + timeout):
> >> + print("Waiting on the pipeline success timed out")
> >
> > s/success//
> > (the pipeline doesn't always have to finish with success)
> >
> >> + return False
> >> +
> >> + status = get_pipeline_status(project_id, commit_sha)
> >> + if status['status'] == 'running':
> >> + time.sleep(interval)
> >> + print('running...')
>
> If we want to automate the use of this script by a daemon, it would
> be better to use the logging class. Then maybe 'running...' is for
> the DEBUG level, Other print() calls can be updated to WARN/INFO
> levels.
>
Makes sense. I'll look into using proper logging in a future
improvement series.
Thanks,
- Cleber.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-09-02 22:10 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 2:46 [PATCH v2 0/2] QEMU Gating CI Cleber Rosa
2020-07-09 2:46 ` [PATCH v2 1/2] GitLab Gating CI: introduce pipeline-status contrib script Cleber Rosa
2020-07-09 8:55 ` Erik Skultety
2020-07-09 10:13 ` Philippe Mathieu-Daudé
2020-07-13 7:20 ` Thomas Huth
2020-09-02 22:09 ` Cleber Rosa [this message]
2020-09-02 22:01 ` Cleber Rosa
2020-07-09 11:50 ` Thomas Huth
2020-07-09 2:46 ` [PATCH v2 2/2] GitLab Gating CI: initial set of jobs, documentation and scripts Cleber Rosa
2020-07-09 8:55 ` Erik Skultety
2020-09-03 21:12 ` Cleber Rosa
2020-09-04 9:11 ` Andrea Bolognani
2020-09-04 14:27 ` Cleber Rosa
2020-07-09 10:07 ` Philippe Mathieu-Daudé
2020-09-03 23:17 ` Cleber Rosa
2020-07-09 10:30 ` Daniel P. Berrangé
2020-07-09 11:28 ` Andrea Bolognani
2020-09-04 0:18 ` Cleber Rosa
2020-09-04 8:23 ` Daniel P. Berrangé
2020-09-04 14:40 ` Cleber Rosa
2020-09-04 0:11 ` Cleber Rosa
2020-09-04 8:18 ` Daniel P. Berrangé
2020-09-04 15:10 ` Cleber Rosa
2020-09-04 9:53 ` Gerd Hoffmann
2020-07-29 10:16 ` Stefan Hajnoczi
2020-09-04 0:36 ` Cleber Rosa
2020-09-04 9:47 ` Philippe Mathieu-Daudé
2020-07-20 16:18 ` [PATCH v2 0/2] QEMU Gating CI Peter Maydell
2020-07-20 17:22 ` Cleber Rosa
2020-07-28 14:48 ` Peter Maydell
2020-07-28 14:51 ` Daniel P. Berrangé
2020-07-28 16:13 ` Cleber Rosa
2020-07-28 16:15 ` Daniel P. Berrangé
2020-07-28 16:24 ` Cleber Rosa
2020-07-28 15:50 ` Cleber Rosa
2020-07-28 16:08 ` Peter Maydell
2020-07-28 16:33 ` Cleber Rosa
2020-07-28 16:41 ` Philippe Mathieu-Daudé
2020-07-28 16:54 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200902220944.GB55646@localhost.localdomain \
--to=crosa@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=ehabkost@redhat.com \
--cc=eskultet@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
--cc=wrampazz@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.