Skip to content

Commit 4b72df8

Browse files
laltenkormide
andauthored
Cope with missing version attribute on module (#139)
Cope with missing `version` attribute on module --------- Co-authored-by: Derek Cormier <[email protected]>
1 parent e765a50 commit 4b72df8

File tree

13 files changed

+218
-21
lines changed

13 files changed

+218
-21
lines changed

e2e/__snapshots__/e2e.spec.ts.snap

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,21 @@ modules/unversioned/1.0.0/MODULE.bazel
170170
----------------------------------------------------
171171
module(
172172
name = \\"unversioned\\",
173-
version = \\"1.0.0\\",
173+
version = \\"1.0.0\\",
174174
)
175+
175176
----------------------------------------------------
176177
modules/unversioned/1.0.0/patches/module_dot_bazel_version.patch
177178
----------------------------------------------------
178179
===================================================================
179180
--- a/MODULE.bazel
180181
+++ b/MODULE.bazel
181-
@@ -1,4 +1,4 @@
182+
@@ -1,3 +1,4 @@
182183
module(
183-
name = \\"unversioned\\",
184-
- version = \\"0.0.0\\",
185-
+ version = \\"1.0.0\\",
184+
- name = \\"unversioned\\"
185+
+ name = \\"unversioned\\",
186+
+ version = \\"1.0.0\\",
186187
)
187-
\\\\ No newline at end of file
188188
189189
----------------------------------------------------
190190
modules/unversioned/1.0.0/presubmit.yml
@@ -204,11 +204,11 @@ bcr_test_module:
204204
modules/unversioned/1.0.0/source.json
205205
----------------------------------------------------
206206
{
207-
\\"integrity\\": \\"sha256-eXQOU+DNwg/Q29tX59jP0+SFLvRHrQf3z+KJVS/gIRk=\\",
207+
\\"integrity\\": \\"sha256-oLg/mgWyhr6DFepRYkjoPphQ8KOriLgu6M4x2RSsLbU=\\",
208208
\\"strip_prefix\\": \\"unversioned-1.0.0\\",
209209
\\"url\\": \\"https://github.com/testorg/unversioned/archive/refs/tags/v1.0.0.tar.gz\\",
210210
\\"patches\\": {
211-
\\"module_dot_bazel_version.patch\\": \\"sha256-y0kC8heeH9bQKhrfx2JuX+RK0KyjwHhPac3wBc4Nkg4=\\"
211+
\\"module_dot_bazel_version.patch\\": \\"sha256-LGXyh9FLhgIPbe0gHfxAPnEQ7HVR+HUP/IDbPdl3ZkA=\\"
212212
},
213213
\\"patch_strip\\": 1
214214
}
@@ -292,6 +292,79 @@ modules/versioned/metadata.json
292292
"
293293
`;
294294

295+
exports[`e2e tests [snapshot] ruleset with zero-versioned module in source 1`] = `
296+
"----------------------------------------------------
297+
modules/zero-versioned/1.0.0/MODULE.bazel
298+
----------------------------------------------------
299+
module(
300+
name = \\"zero-versioned\\",
301+
version = \\"1.0.0\\",
302+
)
303+
304+
----------------------------------------------------
305+
modules/zero-versioned/1.0.0/patches/module_dot_bazel_version.patch
306+
----------------------------------------------------
307+
===================================================================
308+
--- a/MODULE.bazel
309+
+++ b/MODULE.bazel
310+
@@ -1,4 +1,4 @@
311+
module(
312+
name = \\"zero-versioned\\",
313+
- version = \\"0.0.0\\",
314+
+ version = \\"1.0.0\\",
315+
)
316+
317+
----------------------------------------------------
318+
modules/zero-versioned/1.0.0/presubmit.yml
319+
----------------------------------------------------
320+
bcr_test_module:
321+
module_path: \\"e2e/bzlmod\\"
322+
matrix:
323+
platform: [\\"debian10\\", \\"macos\\", \\"ubuntu2004\\", \\"windows\\"]
324+
tasks:
325+
run_tests:
326+
name: \\"Run test module\\"
327+
platform: \${{ platform }}
328+
test_targets:
329+
- \\"//...\\"
330+
331+
----------------------------------------------------
332+
modules/zero-versioned/1.0.0/source.json
333+
----------------------------------------------------
334+
{
335+
\\"integrity\\": \\"sha256-sLh05DKTEOuO3vz9+IDUJJNOf0GSLxdGDJ8qOLZRUCQ=\\",
336+
\\"strip_prefix\\": \\"zero-versioned-1.0.0\\",
337+
\\"url\\": \\"https://github.com/testorg/zero-versioned/archive/refs/tags/v1.0.0.tar.gz\\",
338+
\\"patches\\": {
339+
\\"module_dot_bazel_version.patch\\": \\"sha256-KpbuC1vv5mfhdTs5nnTl3/pH7Y/6JCnD1b1XLsqyOAo=\\"
340+
},
341+
\\"patch_strip\\": 1
342+
}
343+
344+
----------------------------------------------------
345+
modules/zero-versioned/metadata.json
346+
----------------------------------------------------
347+
{
348+
\\"homepage\\": \\"https://github.com/testorg/zero-versioned\\",
349+
\\"maintainers\\": [
350+
{
351+
\\"name\\": \\"Foo McBar\\",
352+
\\"email\\": \\"[email protected]\\",
353+
\\"github\\": \\"foobar\\"
354+
}
355+
],
356+
\\"repository\\": [
357+
\\"github:testorg/zero-versioned\\"
358+
],
359+
\\"versions\\": [
360+
\\"1.0.0\\"
361+
],
362+
\\"yanked_versions\\": {}
363+
}
364+
365+
"
366+
`;
367+
295368
exports[`e2e tests [snapshot] ruleset with zip release archive 1`] = `
296369
"----------------------------------------------------
297370
modules/zip/1.0.0/MODULE.bazel

e2e/e2e.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,45 @@ describe("e2e tests", () => {
133133
expect(snapshot).toMatchSnapshot();
134134
});
135135

136+
test("[snapshot] ruleset with zero-versioned module in source", async () => {
137+
const repo = Fixture.ZeroVersioned;
138+
const tag = "v1.0.0";
139+
await setupLocalRemoteRulesetRepo(repo, tag, releaser);
140+
141+
fakeGitHub.mockUser(releaser);
142+
fakeGitHub.mockRepository(testOrg, repo);
143+
fakeGitHub.mockRepository(
144+
testOrg,
145+
"bazel-central-registry",
146+
"bazelbuild",
147+
"bazel-central-registry"
148+
);
149+
const installationId = fakeGitHub.mockAppInstallation(testOrg, repo);
150+
fakeGitHub.mockAppInstallation(testOrg, "bazel-central-registry");
151+
152+
const releaseArchive = await makeReleaseTarball(repo, "zero-versioned-1.0.0");
153+
await fakeGitHub.mockReleaseArchive(
154+
`/${testOrg}/${repo}/archive/refs/tags/${tag}.tar.gz`,
155+
releaseArchive
156+
);
157+
158+
const response = await publishReleaseEvent(
159+
cloudFunctions.getBaseUrl(),
160+
secrets.webhookSecret,
161+
installationId,
162+
{
163+
owner: testOrg,
164+
repo,
165+
tag,
166+
releaser,
167+
}
168+
);
169+
expect(response.status).toEqual(200);
170+
171+
const snapshot = await rollupEntryFiles();
172+
expect(snapshot).toMatchSnapshot();
173+
});
174+
136175
test("[snapshot] ruleset with versioned module in source", async () => {
137176
const repo = Fixture.Versioned;
138177
const tag = "v1.0.0";
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
module(
2-
name = "unversioned",
3-
version = "0.0.0",
4-
)
2+
name = "unversioned"
3+
)

e2e/fixtures/unversioned/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Ruleset repo that doesn't update the source MODULE.bazel's `version` field.
1+
Ruleset repo that doesn't have the source MODULE.bazel's `version` field.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"homepage": "https://github.com/testorg/zero-versioned",
3+
"maintainers": [
4+
{
5+
"name": "Foo McBar",
6+
"email": "[email protected]",
7+
"github": "foobar"
8+
}
9+
],
10+
"repository": [
11+
"github:testorg/zero-versioned"
12+
],
13+
"versions": [],
14+
"yanked_versions": {}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bcr_test_module:
2+
module_path: "e2e/bzlmod"
3+
matrix:
4+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
5+
tasks:
6+
run_tests:
7+
name: "Run test module"
8+
platform: ${{ platform }}
9+
test_targets:
10+
- "//..."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module(
2+
name = "zero-versioned",
3+
version = "0.0.0",
4+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ruleset repo that doesn't set the source MODULE.bazel's `version` field.

e2e/helpers/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enum Fixture {
1616
NoPrefix = "no-prefix",
1717
Tarball = "tarball",
1818
Unversioned = "unversioned",
19+
ZeroVersioned = "zero-versioned",
1920
Versioned = "versioned",
2021
Zip = "zip",
2122
}

0 commit comments

Comments
 (0)