Skip to content

Commit db12297

Browse files
authored
fix: extraction of multi-module release archive (#147)
1 parent a1f7887 commit db12297

File tree

7 files changed

+25
-62
lines changed

7 files changed

+25
-62
lines changed

e2e/e2e.spec.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -469,23 +469,11 @@ describe("e2e tests", () => {
469469
const installationId = fakeGitHub.mockAppInstallation(testOrg, repo);
470470
fakeGitHub.mockAppInstallation(testOrg, "bazel-central-registry");
471471

472-
const releaseArchive1 = await makeReleaseTarball(
473-
repo,
474-
"multi-module-1.0.0"
475-
);
476-
const releaseArchive2 = await makeReleaseTarball(
477-
repo,
478-
"multi-module-1.0.0"
479-
);
472+
const releaseArchive = await makeReleaseTarball(repo, "multi-module-1.0.0");
480473

481474
await fakeGitHub.mockReleaseArchive(
482-
`/${testOrg}/${repo}/releases/download/${tag}/module-${tag}.tar.gz`,
483-
releaseArchive1
484-
);
485-
486-
await fakeGitHub.mockReleaseArchive(
487-
`/${testOrg}/${repo}/releases/download/${tag}/submodule-${tag}.tar.gz`,
488-
releaseArchive2
475+
`/${testOrg}/${repo}/releases/download/${tag}.tar.gz`,
476+
releaseArchive
489477
);
490478

491479
const response = await publishReleaseEvent(
@@ -791,18 +779,18 @@ describe("e2e tests", () => {
791779
const testReleaseArchives: string[] = [];
792780
async function makeReleaseTarball(
793781
fixture: Fixture,
794-
stripPrefix?: string
782+
prefix?: string
795783
): Promise<string> {
796-
const filename = await _makeReleaseTarball(fixture, stripPrefix);
784+
const filename = await _makeReleaseTarball(fixture, prefix);
797785
testReleaseArchives.push(filename);
798786
return filename;
799787
}
800788

801789
async function makeReleaseZip(
802790
fixture: string,
803-
stripPrefix?: string
791+
prefix?: string
804792
): Promise<string> {
805-
const filename = await _makeReleaseZip(fixture, stripPrefix);
793+
const filename = await _makeReleaseZip(fixture, prefix);
806794
testReleaseArchives.push(filename);
807795
return filename;
808796
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"integrity": "",
3-
"strip_prefix": "{REPO}-{VERSION}/submodule",
4-
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/module-{TAG}.tar.gz"
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}.tar.gz"
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"integrity": "",
3-
"strip_prefix": "{REPO}-{VERSION}",
4-
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/submodule-{TAG}.tar.gz"
3+
"strip_prefix": "{REPO}-{VERSION}/submodule",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}.tar.gz"
55
}

e2e/helpers/archive.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import tar from "tar";
77

88
export async function makeReleaseTarball(
99
fixture: string,
10-
stripPrefix?: string
10+
prefix?: string
1111
): Promise<string> {
1212
const filename = path.join(
1313
os.tmpdir(),
@@ -17,7 +17,7 @@ export async function makeReleaseTarball(
1717
await tar.create(
1818
{
1919
gzip: { level: 1 },
20-
prefix: stripPrefix,
20+
prefix,
2121
file: filename,
2222
cwd: path.join("e2e", "fixtures", fixture),
2323
portable: true,
@@ -31,7 +31,7 @@ export async function makeReleaseTarball(
3131

3232
export async function makeReleaseZip(
3333
fixture: string,
34-
stripPrefix?: string
34+
prefix?: string
3535
): Promise<string> {
3636
const filename = path.join(
3737
os.tmpdir(),
@@ -44,13 +44,9 @@ export async function makeReleaseZip(
4444
archive.pipe(output);
4545

4646
const hermeticDate = new Date(0);
47-
archive.directory(
48-
path.join("e2e", "fixtures", fixture),
49-
stripPrefix || false,
50-
{
51-
date: hermeticDate,
52-
}
53-
);
47+
archive.directory(path.join("e2e", "fixtures", fixture), prefix || false, {
48+
date: hermeticDate,
49+
});
5450

5551
await archive.finalize();
5652

src/domain/create-entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class CreateEntryService {
6363
const integrityHash = computeIntegrityHash(releaseArchive.diskPath);
6464
sourceTemplate.setIntegrityHash(integrityHash);
6565

66-
const moduleFile = await releaseArchive.extractModuleFile(moduleRoot);
66+
const moduleFile = await releaseArchive.extractModuleFile();
6767

6868
const bcrEntryPath = path.resolve(
6969
bcrRepo.diskPath,

src/domain/release-archive.spec.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe("extractModuleFile", () => {
149149
);
150150

151151
const thrownError = await expectThrownError(
152-
() => releaseArchive.extractModuleFile("."),
152+
() => releaseArchive.extractModuleFile(),
153153
UnsupportedArchiveFormat
154154
);
155155
expect(thrownError.message.includes("deb")).toEqual(true);
@@ -160,7 +160,7 @@ describe("extractModuleFile", () => {
160160
"https://foo.bar/rules-foo-v1.2.3.tar.gz",
161161
STRIP_PREFIX
162162
);
163-
await releaseArchive.extractModuleFile(".");
163+
await releaseArchive.extractModuleFile();
164164

165165
expect(tar.x).toHaveBeenCalledWith({
166166
cwd: path.dirname(releaseArchive.diskPath),
@@ -173,7 +173,7 @@ describe("extractModuleFile", () => {
173173
RELEASE_ARCHIVE_URL,
174174
STRIP_PREFIX
175175
);
176-
await releaseArchive.extractModuleFile(".");
176+
await releaseArchive.extractModuleFile();
177177

178178
const expectedPath = path.join(
179179
path.dirname(releaseArchive.diskPath),
@@ -183,29 +183,12 @@ describe("extractModuleFile", () => {
183183
expect(fs.readFileSync).toHaveBeenCalledWith(expectedPath, "utf8");
184184
});
185185

186-
test("loads an extracted MODULE.bazel file in a different module root", async () => {
187-
const releaseArchive = await ReleaseArchive.fetch(
188-
RELEASE_ARCHIVE_URL,
189-
STRIP_PREFIX
190-
);
191-
await releaseArchive.extractModuleFile("sub/dir");
192-
193-
const expectedPath = path.join(
194-
path.dirname(releaseArchive.diskPath),
195-
STRIP_PREFIX,
196-
"sub",
197-
"dir",
198-
"MODULE.bazel"
199-
);
200-
expect(fs.readFileSync).toHaveBeenCalledWith(expectedPath, "utf8");
201-
});
202-
203186
test("returns a module file representation", async () => {
204187
const releaseArchive = await ReleaseArchive.fetch(
205188
RELEASE_ARCHIVE_URL,
206189
STRIP_PREFIX
207190
);
208-
const moduleFile = await releaseArchive.extractModuleFile(".");
191+
const moduleFile = await releaseArchive.extractModuleFile();
209192

210193
expect(moduleFile.moduleName).toEqual("rules_foo");
211194
expect(moduleFile.version).toEqual("1.2.3");
@@ -219,7 +202,7 @@ describe("extractModuleFile", () => {
219202

220203
mocked(fs.existsSync).mockReturnValue(false);
221204

222-
await expect(releaseArchive.extractModuleFile(".")).rejects.toThrow(
205+
await expect(releaseArchive.extractModuleFile()).rejects.toThrow(
223206
MissingModuleFileError
224207
);
225208
});

src/domain/release-archive.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ReleaseArchive {
5858
private readonly stripPrefix: string
5959
) {}
6060

61-
public async extractModuleFile(moduleRoot: string): Promise<ModuleFile> {
61+
public async extractModuleFile(): Promise<ModuleFile> {
6262
this.extractDir = path.dirname(this._diskPath);
6363

6464
if (this._diskPath.endsWith(".tar.gz")) {
@@ -70,11 +70,7 @@ export class ReleaseArchive {
7070
throw new UnsupportedArchiveFormat(extension);
7171
}
7272

73-
const pathInArchive = path.join(
74-
this.stripPrefix,
75-
moduleRoot,
76-
"MODULE.bazel"
77-
);
73+
const pathInArchive = path.join(this.stripPrefix, "MODULE.bazel");
7874

7975
const extractedModulePath = path.join(this.extractDir, pathInArchive);
8076

0 commit comments

Comments
 (0)