← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:allow-empty-ci-output-files into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:allow-empty-ci-output-files into launchpad:master.

Commit message:
Allow CI build artifacts to be zero-length

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/444577

It isn't necessarily unreasonable for artifacts produced by CI builds to be zero-length: for example, https://git.launchpad.net/ubuntu-cdimage declares an output file resulting from from `./run-tests >output`, and the `./run-tests` command there produces no output if the tests succeed.  Allow this rather than OOPSing.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:allow-empty-ci-output-files into launchpad:master.
diff --git a/lib/lp/code/model/revisionstatus.py b/lib/lp/code/model/revisionstatus.py
index dbc910a..c079a87 100644
--- a/lib/lp/code/model/revisionstatus.py
+++ b/lib/lp/code/model/revisionstatus.py
@@ -141,6 +141,7 @@ class RevisionStatusReport(StormBase):
             file=file,
             contentType="application/octet-stream",
             restricted=self.git_repository.private,
+            allow_zero_length=True,
         )
         getUtility(IRevisionStatusArtifactSet).new(lfa, self, artifact_type)
 
diff --git a/lib/lp/code/model/tests/test_revisionstatus.py b/lib/lp/code/model/tests/test_revisionstatus.py
index 1ab7618..9ff6cc9 100644
--- a/lib/lp/code/model/tests/test_revisionstatus.py
+++ b/lib/lp/code/model/tests/test_revisionstatus.py
@@ -356,6 +356,23 @@ class TestRevisionStatusReportWebservice(TestCaseWithFactory):
             sha1(content.encode()).hexdigest(),
         )
 
+    def test_attach_empty_file(self):
+        report = self.factory.makeRevisionStatusReport(
+            title="build:0",
+            ci_build=self.factory.makeCIBuild(),
+        )
+
+        with person_logged_in(report.creator):
+            report.attach("empty", b"")
+
+        artifacts = list(
+            getUtility(IRevisionStatusArtifactSet).findByReport(report)
+        )
+        self.assertEqual(
+            artifacts[0].library_file.content.sha1,
+            hashlib.sha1(b"").hexdigest(),
+        )
+
     def test_update(self):
         test_properties = {
             "launchpad.source-name": "go-module",