Settle what the checks of the review fixes found
A difference that comes and goes no longer makes the account ask about a stop the user has already chosen on. The balance of the restrictions adds each period to what was published, so a change of capital does not rewrite the past. An image is published only under a tag that exists, and a file that is not part of it no longer marks it as unclean. refs #70 #74 #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d26d945818
commit
8d7efe425d
8 files changed
+199
-23
No files matched your search
@@ -324,6 +324,16 @@ public sealed partial class DeliveryTests
|
||||
StringAssert.Contains(tasks, "$\"ANUBIS_VERSION={Version()}\"");
|
||||
StringAssert.Contains(tasks, "$\"ANUBIS_COMMIT={Commit()}\"");
|
||||
StringAssert.Contains(tasks, "\"-dirty\"");
|
||||
|
||||
// Only what goes into the image makes it unclean: a file of the user's, or a note, does not.
|
||||
var parts = Regex.Match(tasks, "string\\[\\] imageSources = \\[(.*?)\\];", RegexOptions.Singleline).Groups[1].Value;
|
||||
var copied = Text("deploy/docker/Dockerfile").Split('\n').Where(l => l.StartsWith("COPY ", StringComparison.Ordinal) && !l.Contains("--from", StringComparison.Ordinal))
|
||||
.SelectMany(l => l.Split(' ', StringSplitOptions.RemoveEmptyEntries).Skip(1).SkipLast(1)).Where(p => !p.StartsWith("--", StringComparison.Ordinal)).ToList();
|
||||
Assert.IsNotEmpty(copied);
|
||||
foreach (var path in copied.Append(".dockerignore").Append("deploy/docker/Dockerfile"))
|
||||
{
|
||||
Assert.IsTrue(Regex.Matches(parts, "\"([^\"]+)\"").Any(m => path.TrimEnd('/') == m.Groups[1].Value || path.StartsWith(m.Groups[1].Value + "/", StringComparison.Ordinal)), path);
|
||||
}
|
||||
var build = (string)Steps("image").Single(s => ((string)s["run"]).Contains("docker build", StringComparison.Ordinal))["run"];
|
||||
StringAssert.Contains(build, "version=${REF_NAME#v}");
|
||||
StringAssert.Contains(build, "\"ANUBIS_VERSION=$version\"");
|
||||
@@ -412,6 +422,7 @@ public sealed partial class DeliveryTests
|
||||
[DataRow("v0.9.0", "0.9.0", "fedcba9876543210fedcba9876543210fedcba98", false)]
|
||||
[DataRow("v0.9.0", "0.9.0", "", false)]
|
||||
[DataRow("v0.9.0", "0.9.0", PublishRun.Commit, true)]
|
||||
[DataRow("v0.9.0", "0.9.0", PublishRun.TagObject, false)]
|
||||
public async Task TheScriptRefusesAnImageThatIsNotTheOneOfTheTag(string tag, string version, string revision, bool tagged)
|
||||
{
|
||||
using var run = new PublishRun("v0.7.0", version: version, revision: revision, tagged: tagged);
|
||||
@@ -427,25 +438,48 @@ public sealed partial class DeliveryTests
|
||||
[OSCondition(OperatingSystems.Linux)]
|
||||
[DataRow("v0.9.0", PublishRun.TagCommit, true)]
|
||||
[DataRow("v0.9.0-rc.1", PublishRun.TagCommit, true)]
|
||||
[DataRow("v0.9.0-rc.1", PublishRun.Commit, false)]
|
||||
[DataRow("v0.9.0-rc.1", PublishRun.RemoteCommit, false)]
|
||||
public async Task TheScriptTakesTheImageOfTheTasksAtTheCommitOfTheTag(string tag, string revision, bool tagged)
|
||||
{
|
||||
// The commit of the tag when the tag is here, otherwise the one checked out: in the workflow they are the same.
|
||||
// The commit of the tag when the tag is here, otherwise the one the repository on Gitea has for it.
|
||||
using var run = new PublishRun("v0.7.0", version: "0.9.0", revision: revision, tagged: tagged);
|
||||
var (code, output) = await run.RunAsync(tag, PublishRun.Token);
|
||||
Assert.AreEqual(0, code, output);
|
||||
Assert.IsNotEmpty(run.Pushed());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
[OSCondition(OperatingSystems.Linux)]
|
||||
public async Task TheScriptRefusesATagThatIsNowhere()
|
||||
{
|
||||
// The commit checked out is not asked: an image of it would be published under a tag nobody made.
|
||||
using var run = new PublishRun("v0.7.0", revision: PublishRun.Commit, pushed: false);
|
||||
var (code, output) = await run.RunAsync("v0.9.0", PublishRun.Token);
|
||||
Assert.AreEqual(1, code, output);
|
||||
StringAssert.Contains(output, "Pubblicazione non riuscita: il tag v0.9.0 non c'è");
|
||||
Assert.IsEmpty(run.Pushed());
|
||||
Assert.AreEqual("", run.Input, "Not even the login.");
|
||||
|
||||
// A light tag names its commit directly.
|
||||
using var light = new PublishRun("v0.7.0", revision: PublishRun.TagObject, light: true);
|
||||
(code, output) = await light.RunAsync("v0.9.0", PublishRun.Token);
|
||||
Assert.AreEqual(0, code, output);
|
||||
}
|
||||
|
||||
private sealed class PublishRun : IDisposable
|
||||
{
|
||||
// The annotated tag on Gitea, and the commit it names.
|
||||
public const string TagObject = "1111111111222222222233333333334444444444";
|
||||
public const string RemoteCommit = "5555555555666666666677777777778888888888";
|
||||
|
||||
public const string Token = "a-token-only-for-the-test";
|
||||
public const string Commit = "0123456789abcdef0123456789abcdef01234567";
|
||||
public const string TagCommit = "89abcdef0123456789abcdef0123456789abcdef";
|
||||
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "anubis-publish-" + Guid.NewGuid().ToString("N"));
|
||||
|
||||
public PublishRun(string others, bool gitFails = false, string? version = null, string revision = Commit, bool tagged = false)
|
||||
public PublishRun(string others, bool gitFails = false, string? version = null, string revision = RemoteCommit, bool tagged = false, bool pushed = true, bool light = false)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(_root, "deploy", "docker"));
|
||||
Directory.CreateDirectory(Path.Combine(_root, "bin"));
|
||||
@@ -455,7 +489,8 @@ public sealed partial class DeliveryTests
|
||||
Tool("docker", "printf '%s\\n' \"$*\" >> \"$RECORD/calls\"\nif [ \"$1\" = login ]; then cat > \"$RECORD/input\"; printf '%s' \"$DOCKER_CONFIG\" > \"$RECORD/config\"; fi\n" +
|
||||
$"case \"$*\" in *image.version*) printf '%s\\n' \"$VERSION\" ;; *image.revision*) printf '%s\\n' '{revision}' ;; esac\n");
|
||||
var tagCommit = tagged ? $"printf '%s\\n' {TagCommit}; exit 0" : "exit 1";
|
||||
Tool("git", $"case \"$*\" in *rev-parse*refs/tags/*) {tagCommit} ;; *rev-parse*HEAD*) printf '%s\\n' {Commit}; exit 0 ;; esac\n" +
|
||||
var remote = !pushed ? "" : $"printf '{TagObject}\\t%s\\n' \"refs/tags/$TAGGED\"; " + (light ? "" : $"printf '{RemoteCommit}\\t%s\\n' \"refs/tags/$TAGGED^{{}}\"; ");
|
||||
Tool("git", $"case \"$*\" in *rev-parse*refs/tags/*) {tagCommit} ;; *rev-parse*HEAD*) printf '%s\\n' {Commit}; exit 0 ;; *ls-remote*\\^{{}}*) {(gitFails ? "exit 128" : remote + "exit 0")} ;; esac\n" +
|
||||
(gitFails ? "exit 128\n" : string.Concat(others.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(o => $"printf 'abc\\trefs/tags/{o}\\n'\n"))));
|
||||
}
|
||||
|
||||
@@ -478,6 +513,7 @@ public sealed partial class DeliveryTests
|
||||
info.ArgumentList.Add(tag);
|
||||
info.Environment["PATH"] = Path.Combine(_root, "bin") + ":" + Environment.GetEnvironmentVariable("PATH");
|
||||
info.Environment["RECORD"] = _root;
|
||||
info.Environment["TAGGED"] = tag;
|
||||
info.Environment["VERSION"] = _version ?? tag[1..];
|
||||
info.Environment["REGISTRY"] = "registry.test";
|
||||
info.Environment["REGISTRY_USER"] = "someone";
|
||||
|
||||
Reference in new issue
Block a user