Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package obs-service-go_modules for
openSUSE:Factory checked in at 2023-02-27 12:56:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/obs-service-go_modules (Old)
and /work/SRC/openSUSE:Factory/.obs-service-go_modules.new.31432 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "obs-service-go_modules"
Mon Feb 27 12:56:03 2023 rev:5 rq:1067956 version:0.6.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/obs-service-go_modules/obs-service-go_modules.changes
2022-06-12 17:43:21.526503593 +0200
+++
/work/SRC/openSUSE:Factory/.obs-service-go_modules.new.31432/obs-service-go_modules.changes
2023-02-27 12:56:03.795679460 +0100
@@ -1,0 +2,12 @@
+Mon Feb 27 10:51:08 UTC 2023 - [email protected]
+
+- Update to version 0.6.0:
+ * Make service arg subdir optional
+ * exit(1) immediately in extract() exception handler after recording error
+ * Use subprocess.run() options 'capture_output' & 'text' only when supported
+ * Add '--subdir' option: all to specify the directory to search go.mod in
+ * Use temporary directory to extract archive to
+ * Give the user the opprtunity to specify the name of the topmost directory
+ * Attempt to obtain name of top directory in archive from archive content
+
+-------------------------------------------------------------------
Old:
----
obs-service-go_modules-0.5.0.tar.gz
New:
----
obs-service-go_modules-0.6.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ obs-service-go_modules.spec ++++++
--- /var/tmp/diff_new_pack.LaBHwQ/_old 2023-02-27 12:56:04.187681876 +0100
+++ /var/tmp/diff_new_pack.LaBHwQ/_new 2023-02-27 12:56:04.191681900 +0100
@@ -1,7 +1,7 @@
#
# spec file
#
-# Copyright (c) 2022 SUSE LLC
+# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -37,7 +37,7 @@
%define use_test test
%endif
Name: obs-service-%{service}
-Version: 0.5.0
+Version: 0.6.0
Release: 0
Summary: An OBS source service: Download, verify and vendor Go module
dependencies
License: GPL-2.0-or-later
++++++ _service ++++++
--- /var/tmp/diff_new_pack.LaBHwQ/_old 2023-02-27 12:56:04.223682098 +0100
+++ /var/tmp/diff_new_pack.LaBHwQ/_new 2023-02-27 12:56:04.227682122 +0100
@@ -3,7 +3,7 @@
<param
name="url">https://github.com/openSUSE/obs-service-go_modules</param>
<param name="scm">git</param>
<param name="exclude">.git</param>
- <param name="revision">v0.5.0</param>
+ <param name="revision">v0.6.0</param>
<param name="versionformat">@PARENT_TAG@</param>
<param name="changesgenerate">enable</param>
<param name="versionrewrite-pattern">v(.*)</param>
++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.LaBHwQ/_old 2023-02-27 12:56:04.247682246 +0100
+++ /var/tmp/diff_new_pack.LaBHwQ/_new 2023-02-27 12:56:04.251682271 +0100
@@ -1,6 +1,6 @@
<servicedata>
<service name="tar_scm">
<param
name="url">https://github.com/openSUSE/obs-service-go_modules</param>
- <param
name="changesrevision">3ee3fd053c57ab951c7347243e6f4d017c36c7ee</param></service></servicedata>
+ <param
name="changesrevision">19eae60776556c82bd16373f8fbc3b7ba590bec7</param></service></servicedata>
(No newline at EOF)
++++++ obs-service-go_modules-0.5.0.tar.gz ->
obs-service-go_modules-0.6.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/obs-service-go_modules-0.5.0/go_modules
new/obs-service-go_modules-0.6.0/go_modules
--- old/obs-service-go_modules-0.5.0/go_modules 2022-06-11 02:15:31.000000000
+0200
+++ new/obs-service-go_modules-0.6.0/go_modules 2023-02-27 11:29:49.000000000
+0100
@@ -33,6 +33,8 @@
import libarchive
import os
import shutil
+import sys
+import tempfile
from pathlib import Path
from subprocess import run
@@ -82,11 +84,28 @@
def basename_from_archive_name(archive_name):
- return re.sub(
+ basename = re.sub(
"^(?P<service_prefix>_service:[^:]+:)?(?P<basename>.*)\.(?P<extension>obscpio|tar\.[^\.]+)$",
r"\g<basename>",
archive_name,
)
+ if basename:
+ log.info(f"Detected basename {basename} form archive name")
+ return basename
+
+
+def basename_from_archive(archive_name):
+ paths = []
+ with libarchive.file_reader(archive_name) as archive:
+ for entry in archive:
+ if entry.isdir:
+ paths.append(entry.name)
+ try:
+ basename = os.path.commonpath(paths)
+ except ValueError:
+ return
+ log.info(f"Detected basename {basename} from archive")
+ return basename
def archive_autodetect():
@@ -162,16 +181,11 @@
libarchive.extract_file(filename)
except libarchive.exception.ArchiveError as archive_error:
log.error(archive_error)
+ exit(1)
os.chdir(cwd)
-def find_file(path, filename):
- for root, dirs, files in os.walk(path):
- if filename in files:
- return os.path.join(root, filename)
-
-
def cmd_go_mod(cmd, dir):
"""Execute go mod subcommand using subprocess.run().
Capture both stderr and stdout as text.
@@ -180,12 +194,23 @@
"""
log.info(f"go mod {cmd}")
# subprocess.run() returns CompletedProcess cp
- cp = run(["go", "mod", cmd], cwd=dir, capture_output=True, text=True)
+ if sys.version_info >= (3, 7):
+ cp = run(["go", "mod", cmd], cwd=dir, capture_output=True, text=True)
+ else:
+ cp = run(["go", "mod", cmd], cwd=dir)
if cp.returncode:
log.error(cp.stderr.strip())
return cp
+def sanitize_subdir(dir, subdir):
+ ret = os.path.normpath(subdir)
+ if dir == os.path.commonpath([dir, ret]):
+ return ret
+ log.error("Invalid path: {ret} not subdir of {dir}")
+ exit(1)
+
+
def main():
log.info(f"Running OBS Source Service: {app_name}")
@@ -196,78 +221,85 @@
parser.add_argument("--archive")
parser.add_argument("--outdir")
parser.add_argument("--compression", default=DEFAULT_COMPRESSION)
+ parser.add_argument("--basename")
+ parser.add_argument("--subdir")
args = parser.parse_args()
outdir = args.outdir
+ subdir = args.subdir
archive_format, archive_compression, archive_ext =
get_archive_parameters(args)
vendor_tarname = f"vendor.{archive_ext}"
archive = args.archive or archive_autodetect()
log.info(f"Using archive {archive}")
- basename = basename_from_archive_name(archive)
- extract(archive, outdir)
-
- go_mod_path = find_file(outdir, "go.mod")
- if go_mod_path:
- go_mod_dir = os.path.dirname(go_mod_path)
- log.info(f"Using go.mod found at {go_mod_path}")
- else:
- log.error(f"File go.mod not found under {outdir}")
- exit(1)
-
- if args.strategy == "vendor":
- # go subcommand sequence:
- # - go mod download
- # (is sensitive to invalid module versions, try and log warn if
fails)
- # - go mod vendor
- # (also downloads but use separate steps for visibility in OBS
environment)
- # - go mod verify
- # (validates checksums)
-
- # return value cp is type subprocess.CompletedProcess
- cp = cmd_go_mod("download", go_mod_dir)
- if cp.returncode:
- if "invalid version" in cp.stderr:
- log.warning(
- f"go mod download is more sensitive to invalid module
versions than go mod vendor"
- )
- log.warning(
- f"if go mod vendor and go mod verify complete, vendoring
is successful"
- )
- else:
- log.error("go mod download failed")
- exit(1)
+ with tempfile.TemporaryDirectory() as tempdir:
+ extract(archive, tempdir)
- cp = cmd_go_mod("vendor", go_mod_dir)
- if cp.returncode:
- log.error("go mod vendor failed")
+ basename = (
+ args.basename
+ or basename_from_archive(archive)
+ or basename_from_archive_name(archive)
+ )
+ if subdir:
+ go_mod_path = sanitize_subdir(
+ tempdir, os.path.join(tempdir, basename, subdir, "go.mod")
+ )
+ else:
+ go_mod_path = sanitize_subdir(
+ tempdir, os.path.join(tempdir, basename, "go.mod")
+ )
+ if go_mod_path and os.path.exists(go_mod_path):
+ go_mod_dir = os.path.dirname(go_mod_path)
+ log.info(f"Using go.mod found at {go_mod_path}")
+ else:
+ log.error(f"File go.mod not found under {os.path.join(tempdir,
basename)}")
exit(1)
- cp = cmd_go_mod("verify", go_mod_dir)
- if cp.returncode:
- log.error("go mod verify failed")
- exit(1)
+ if args.strategy == "vendor":
+ # go subcommand sequence:
+ # - go mod download
+ # (is sensitive to invalid module versions, try and log warn if
fails)
+ # - go mod vendor
+ # (also downloads but use separate steps for visibility in OBS
environment)
+ # - go mod verify
+ # (validates checksums)
+
+ # return value cp is type subprocess.CompletedProcess
+ cp = cmd_go_mod("download", go_mod_dir)
+ if cp.returncode:
+ if "invalid version" in cp.stderr:
+ log.warning(
+ f"go mod download is more sensitive to invalid module
versions than go mod vendor"
+ )
+ log.warning(
+ f"if go mod vendor and go mod verify complete,
vendoring is successful"
+ )
+ else:
+ log.error("go mod download failed")
+ exit(1)
+
+ cp = cmd_go_mod("vendor", go_mod_dir)
+ if cp.returncode:
+ log.error("go mod vendor failed")
+ exit(1)
- log.info(f"Vendor go.mod dependencies to {vendor_tarname}")
- vendor_tarfile = os.path.join(outdir, vendor_tarname)
- cwd = os.getcwd()
- os.chdir(go_mod_dir)
- vendor_dir = "vendor"
-
- with libarchive.file_writer(
- vendor_tarfile, archive_format, archive_compression
- ) as new_archive:
- new_archive.add_files(vendor_dir)
- os.chdir(cwd)
+ cp = cmd_go_mod("verify", go_mod_dir)
+ if cp.returncode:
+ log.error("go mod verify failed")
+ exit(1)
- # remove extracted Go application source
- try:
- to_remove = os.path.join(outdir, basename)
- log.info(f"Cleaning up working dir {to_remove}")
- shutil.rmtree(to_remove)
- except FileNotFoundError:
- log.error(f"Could not remove directory not found {to_remove}")
+ log.info(f"Vendor go.mod dependencies to {vendor_tarname}")
+ vendor_tarfile = os.path.join(outdir, vendor_tarname)
+ cwd = os.getcwd()
+ os.chdir(go_mod_dir)
+ vendor_dir = "vendor"
+
+ with libarchive.file_writer(
+ vendor_tarfile, archive_format, archive_compression
+ ) as new_archive:
+ new_archive.add_files(vendor_dir)
+ os.chdir(cwd)
if __name__ == "__main__":
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/obs-service-go_modules-0.5.0/go_modules.service
new/obs-service-go_modules-0.6.0/go_modules.service
--- old/obs-service-go_modules-0.5.0/go_modules.service 2022-06-11
02:15:31.000000000 +0200
+++ new/obs-service-go_modules-0.6.0/go_modules.service 2023-02-27
11:29:49.000000000 +0100
@@ -14,4 +14,9 @@
<parameter name="compression">
<description>Specify the source / vendor tarballs compression method. When
using "tar" no compression is applied. Default: "gz".</description>
</parameter>
+ <parameter name="basename">
+ <description>Normally the go_modules service is able to determine the name
of the top directory. Should this not be possible for some reason, use this
option to specify.</description>
+ <parameter name="subdir">
+ <description>If go.mod is not available in the top directory of the
archive, specify its path (relative to the top directory).</description>
+ </parameter>
</service>