Skip to content

Commit aee11ae

Browse files
committed
Upload the configured Compose file to GitHub releases
The release asset filter only matched the default compose pattern (compose*.yml), so a release built with --compose-file-name docker-compose.yaml or production.yml silently left its Compose file out; the old *.yml/*.yaml filter had uploaded it. The configured Compose file name is now matched exactly (regex-escaped).
1 parent 7fc8437 commit aee11ae

2 files changed

Lines changed: 69 additions & 13 deletions

File tree

‎src/tasks/createGithubRelease/subtasks/getCreateReleaseTask.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { releaseFiles } from "@dappnode/types";
2+
import { escapeRegExp } from "lodash-es";
23
import path from "path";
34
import fs from "fs";
45
import { Github } from "../../../providers/github/Github.js";
@@ -55,7 +56,8 @@ export function getCreateReleaseTask({
5556
releaseDetailsMap,
5657
github,
5758
releaseId,
58-
isMultiVariant
59+
isMultiVariant,
60+
composeFileName
5961
});
6062
}
6163
};
@@ -86,16 +88,36 @@ function prepareGithubReleaseFiles({
8688
}
8789
}
8890

91+
/**
92+
* Release assets: image archives, the content hash, every defined release file
93+
* (except the avatar, uploaded once separately) and the configured Compose file,
94+
* whose name (e.g. docker-compose.yaml) need not match the default compose pattern.
95+
*/
96+
export function getReleaseAssetPattern(composeFileName?: string): RegExp {
97+
return new RegExp(
98+
[
99+
"\\.txz$",
100+
`^${escapeRegExp(contentHashFileName)}$`,
101+
...(composeFileName ? [`^${escapeRegExp(composeFileName)}$`] : []),
102+
...Object.entries(releaseFiles)
103+
.filter(([id]) => id !== "avatar")
104+
.map(([, spec]) => spec.regex.source)
105+
].join("|")
106+
);
107+
}
108+
89109
async function uploadAssets({
90110
releaseDetailsMap,
91111
github,
92112
releaseId,
93-
isMultiVariant
113+
isMultiVariant,
114+
composeFileName
94115
}: {
95116
releaseDetailsMap: ReleaseDetailsMap;
96117
github: Github;
97118
releaseId: number;
98119
isMultiVariant: boolean;
120+
composeFileName?: string;
99121
}) {
100122
const releaseEntries = Object.entries(releaseDetailsMap);
101123
const [, { releaseDir: firstReleaseDir }] = releaseEntries[0];
@@ -108,16 +130,7 @@ async function uploadAssets({
108130
await github.uploadReleaseAssets({
109131
releaseId,
110132
assetsDir: releaseDir,
111-
// Use the shared release-file definitions so optional artifacts are retained.
112-
matchPattern: new RegExp(
113-
[
114-
"\\.txz$",
115-
`^${contentHashFileName}$`,
116-
...Object.entries(releaseFiles)
117-
.filter(([id]) => id !== "avatar")
118-
.map(([, spec]) => spec.regex.source)
119-
].join("|")
120-
),
133+
matchPattern: getReleaseAssetPattern(composeFileName),
121134
fileNamePrefix: isMultiVariant ? `${shortDnpName}_` : ""
122135
});
123136
}

‎test/tasks/releaseAssets.test.ts‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import fs from "fs";
22
import path from "path";
33
import { expect } from "chai";
44
import Listr from "listr";
5-
import { getCreateReleaseTask } from "../../src/tasks/createGithubRelease/subtasks/getCreateReleaseTask.js";
5+
import {
6+
getCreateReleaseTask,
7+
getReleaseAssetPattern
8+
} from "../../src/tasks/createGithubRelease/subtasks/getCreateReleaseTask.js";
69
import { Github } from "../../src/providers/github/Github.js";
710
import type { ListrContextPublish } from "../../src/types.js";
811
import { temporaryDirectory } from "../helpers/fixtures.js";
@@ -77,6 +80,46 @@ describe("complete GitHub releases", () => {
7780
]);
7881
});
7982

83+
it("uploads a Compose file with a custom --compose-file-name", async () => {
84+
fs.renameSync(
85+
path.join(dir, "docker-compose.yml"),
86+
path.join(dir, "docker-compose.yaml")
87+
);
88+
const uploaded: string[] = [];
89+
const github = {
90+
deleteReleaseAndAssets: async () => {},
91+
createRelease: async () => 1,
92+
uploadReleaseAssets: async ({
93+
matchPattern
94+
}: {
95+
matchPattern: RegExp;
96+
}) => {
97+
uploaded.push(
98+
...fs.readdirSync(dir).filter(file => matchPattern.test(file))
99+
);
100+
}
101+
} as unknown as Github;
102+
await new Listr(
103+
[
104+
getCreateReleaseTask({
105+
github,
106+
isMultiVariant: false,
107+
composeFileName: "docker-compose.yaml"
108+
})
109+
],
110+
{ renderer: "silent" }
111+
).run(ctx);
112+
expect(uploaded).to.include("docker-compose.yaml");
113+
});
114+
115+
it("matches the configured Compose file name exactly", () => {
116+
const pattern = getReleaseAssetPattern("production.yml");
117+
expect(pattern.test("production.yml")).to.equal(true);
118+
expect(pattern.test("productionXyml")).to.equal(false);
119+
expect(getReleaseAssetPattern().test("production.yml")).to.equal(false);
120+
expect(getReleaseAssetPattern().test("docker-compose.yml")).to.equal(true);
121+
});
122+
80123
it("fails the release when asset upload fails", async () => {
81124
const github = {
82125
deleteReleaseAndAssets: async () => {},

0 commit comments

Comments
 (0)