From nobody Wed May 15 07:07:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1586452904; cv=none; d=zohomail.com; s=zohoarc; b=YxarT2VgkMF9Crz3XU0j4cdNd82zHXZ7aRCpoh9VXnt4y0Vci7s84hNkJSwZFImxzZS3xI5UWRGULr17TFCunIp9GP27Ij5WjPj/yqPrmCG+Jsv4qZ+eG3AcTjujQzEJ215kqta3kMOyXDFIL4yZ/MRiWHk9TaTQDdv8siTBBpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586452904; 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=c6fxiVD4BO+o21r7P5rBLU9a6wl4sDq2nE5AIEnwfT8=; b=B9vu8rgEvIO44J5E3nyXPde5MimnuA9ny8GA7+oMvkZEaje6bGdsZ/bkc2shN/IW8dRiyIHtqpZKdl5AgHFDFBxP0zcdl2niSB0vLkXZApK0FfIkYfCJFsaEm6LOgdKMgKXgBQCjbGybPjDlVnZhCdCQ0JcBA8VyIHgkMvngCKw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1586452904791126.73707001645641; Thu, 9 Apr 2020 10:21:44 -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-200-dl-gQofvN9WeSNodXk3Vpg-1; Thu, 09 Apr 2020 13:21:39 -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 0CB6F107ACC4; Thu, 9 Apr 2020 17:21:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83F9A60BF3; Thu, 9 Apr 2020 17:21:33 +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 55A6618089CD; Thu, 9 Apr 2020 17:21:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 039HLUAr014380 for ; Thu, 9 Apr 2020 13:21:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id DA97260C05; Thu, 9 Apr 2020 17:21:30 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE07360BF3; Thu, 9 Apr 2020 17:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586452903; 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=c6fxiVD4BO+o21r7P5rBLU9a6wl4sDq2nE5AIEnwfT8=; b=KotxF8dJMBxDa1H4nfTkEMwG9cgm9a0HgHkDCgySKDDUVfOtztXaLpHEDh+ERQjrrVCWkG ZbPJMsRkDpiw5o8qR2jMsUyl7DDJ/5GgT83KJA5ifZXM5CBOEAucIR1aKGSXuuCHw57kYz Dngoelazs7B//jjXZeTkHsdDZWr7zc0= X-MC-Unique: dl-gQofvN9WeSNodXk3Vpg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt-ci PATCH v2] dco: build and publish a container image for DCO check Date: Thu, 9 Apr 2020 18:21:25 +0100 Message-Id: <20200409172125.1333744-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 --- In v2: - Drop -f arg to docker - Drop .py suffix .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..7735bb3 --- /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= } ${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 + only: + - branches + except: + - master diff --git a/check-dco/Dockerfile b/check-dco/Dockerfile new file mode 100644 index 0000000..366f72b --- /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 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