From nobody Thu May 16 05:04:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586346909; cv=none; d=zohomail.com; s=zohoarc; b=ds3JXDS10iJ4Q5jh053GKBkkOy282m/rzEyDBSeRJTswVuiaWxjD2VOHdV+WxJY2MiK3eY3OStZTBLkSevzs9cvP/Qd+IzjmRVVZgi4XfMr0bIZunss30eQiD/mw+JyhMEZnS29E2pUwqcCvBJG1Hn3SY3yeOtPD25CaupT1UL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586346909; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=EDY2QEzGqZmS7mT53vzVnSOvwigaXArYuHnmw0McAWA=; b=XufyoDE6JAMCa9+UutkudRBpK7d5mvib/CPkm9Z+RcmJQGcI2mfc8NTtp5Tt3Z7eHcK6YgRtbX/hXhaRowwWT3MeM5kQLZXUI45RXhjeP2b1jXmcVr2HQ/9jnnSU6KAl27Iy5jl1K3GYj7eRSMLfH+IOIkuXOM8/g9OVcFqSabE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1586346909692865.4690628884713; Wed, 8 Apr 2020 04:55:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-243-iARSOXioOqaTAgz5J1IKcw-1; Wed, 08 Apr 2020 07:55:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FF4818B6394; Wed, 8 Apr 2020 11:54:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26DDE60BF7; Wed, 8 Apr 2020 11:54:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 464BD93A7D; Wed, 8 Apr 2020 11:54:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 038BskZw001403 for ; Wed, 8 Apr 2020 07:54:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 95B6F9D37E; Wed, 8 Apr 2020 11:54:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9438F7E303; Wed, 8 Apr 2020 11:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586346908; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EDY2QEzGqZmS7mT53vzVnSOvwigaXArYuHnmw0McAWA=; b=G9ot5raC+KnMKMtvut3CtyGqR/9QujrDv9yCiBlxONrVHIqAjgIvQWR54napUo1nqefmaT dbktHf+a4uUV81NZZ65ro4TZ3Q1HpVfYIOglCF6JQ5xHjLaZnYXkBeS1MaYpd7qB9srnxA nOKTbeoURlnv2gparjyShhm4gOrGlwc= X-MC-Unique: iARSOXioOqaTAgz5J1IKcw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt-jenkins-ci PATCH] dco: build and publish a container image for DCO check Date: Wed, 8 Apr 2020 12:54:40 +0100 Message-Id: <20200408115440.1080616-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This builds a container image containing the DCO checking script. It is then published at: registry.gitlab.com/libvirt/libvirt-jenkins-ci/check-dco:master from where it can be used in all other project repositories. This avoids having to copy the check-dco.py script into every repo when we want to make changes to it. Signed-off-by: Daniel P. Berrang=C3=A9 --- .gitlab-ci.yml | 39 +++++++++++++++++ check-dco/Dockerfile | 6 +++ check-dco/check-dco.py | 99 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 check-dco/Dockerfile create mode 100755 check-dco/check-dco.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..83b0d64 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,39 @@ + +stages: + - containers + - postbuild + +.build_container_template: &build_container_definition + image: docker:stable + stage: containers + services: + - docker:dind + before_script: + - docker info + - docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGI= STRY_PASSWORD} + script: + - docker build --tag ${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG= } -f ${NAME}/Dockerfile ${NAME} + - docker push ${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG} + after_script: + - docker logout + +build-dco: + <<: *build_container_definition + variables: + NAME: check-dco + +# Check that all commits are signed-off for the DCO. Skip +# on master branch and -maint branches, since we only need +# to test developer's personal branches. +check-dco: + # In most projects we'd put this in a "prebuild", but this + # repo is a special case as we need to actually build the + # container first! + stage: postbuild + image: ${CI_REGISTRY_IMAGE}/check-dco:${CI_COMMIT_REF_SLUG} + script: + - /check-dco.py + only: + - branches + except: + - master diff --git a/check-dco/Dockerfile b/check-dco/Dockerfile new file mode 100644 index 0000000..86cada7 --- /dev/null +++ b/check-dco/Dockerfile @@ -0,0 +1,6 @@ +FROM centos:8 + +RUN dnf -y install python3 git && \ + dnf -y clean all + +COPY check-dco.py check-dco.py diff --git a/check-dco/check-dco.py b/check-dco/check-dco.py new file mode 100755 index 0000000..f8204ca --- /dev/null +++ b/check-dco/check-dco.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +# +# ci-job.py: validate all commits are signed off +# +# Copyright (C) 2020 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . + +import os +import os.path +import sys +import subprocess + +cwd =3D os.getcwd() +reponame =3D os.path.basename(cwd) +repourl =3D "https://gitlab.com/libvirt/%s.git" % reponame + +subprocess.check_call(["git", "remote", "add", "dcocheck", repourl]) +subprocess.check_call(["git", "fetch", "dcocheck", "master"], + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.DEVNULL) + +ancestor =3D subprocess.check_output(["git", "merge-base", "dcocheck/maste= r", "HEAD"], + universal_newlines=3DTrue) + +ancestor =3D ancestor.strip() + +subprocess.check_call(["git", "remote", "rm", "dcocheck"]) + +errors =3D False + +print("\nChecking for 'Signed-off-by: NAME ' on all commits since %= s...\n" % ancestor) + +log =3D subprocess.check_output(["git", "log", "--format=3D%H %s", ancesto= r + "..."], + universal_newlines=3DTrue) + +if log =3D=3D "": + commits =3D [] +else: + commits =3D [[c[0:40], c[41:]] for c in log.strip().split("\n")] + +for sha, subject in commits: + + msg =3D subprocess.check_output(["git", "show", "-s", sha], + universal_newlines=3DTrue) + lines =3D msg.strip().split("\n") + + print("=F0=9F=94=8D %s %s" % (sha, subject)) + sob =3D False + for line in lines: + if "Signed-off-by:" in line: + sob =3D True + if "localhost" in line: + print(" =E2=9D=8C FAIL: bad email in %s" % line) + errors =3D True + + if not sob: + print(" =E2=9D=8C FAIL missing Signed-off-by tag") + errors =3D True + +if errors: + print(""" + +=E2=9D=8C ERROR: One or more commits are missing a valid Signed-off-By tag. + + +This project requires all contributors to assert that their contributions +are provided in compliance with the terms of the Developer's Certificate +of Origin 1.1 (DCO): + + https://developercertificate.org/ + +To indicate acceptance of the DCO every commit must have a tag + + Signed-off-by: REAL NAME + +This can be achieved by passing the "-s" flag to the "git commit" command. + +To bulk update all commits on current branch "git rebase" can be used: + + git rebase -i master -x 'git commit --amend --no-edit -s' + +""") + + sys.exit(1) + +sys.exit(0) --=20 2.24.1