|
| 1 | +import { Fixture, normalizeCommitSHAs, normalizeEnvironment } from "@lerna/e2e-utils"; |
| 2 | + |
| 3 | +expect.addSnapshotSerializer({ |
| 4 | + serialize(str: string) { |
| 5 | + return normalizeCommitSHAs(normalizeEnvironment(str)); |
| 6 | + }, |
| 7 | + test(val: string) { |
| 8 | + return val != null && typeof val === "string"; |
| 9 | + }, |
| 10 | +}); |
| 11 | + |
| 12 | +/** |
| 13 | + * NOTE: This test suite should only execute in CI/CD. |
| 14 | + * The reason is that using the `--sign-git-tag` flag requires a GPG key to be present on the machine, |
| 15 | + * which is not a guarantee in a local development environment. |
| 16 | + */ |
| 17 | +const describeFunc = process.env.CI === "true" ? describe : describe.skip; |
| 18 | + |
| 19 | +describeFunc("lerna-version-sign-git-tag", () => { |
| 20 | + describe("single package", () => { |
| 21 | + let fixture: Fixture; |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + fixture = await Fixture.create({ |
| 25 | + e2eRoot: process.env.E2E_ROOT, |
| 26 | + name: "lerna-version-sign-git-tag", |
| 27 | + packageManager: "npm", |
| 28 | + initializeGit: true, |
| 29 | + lernaInit: { args: [`--packages="packages/*"`] }, |
| 30 | + installDependencies: true, |
| 31 | + }); |
| 32 | + await fixture.lerna("create package-a -y"); |
| 33 | + await fixture.createInitialGitCommit(); |
| 34 | + await fixture.exec("git push origin test-main"); |
| 35 | + }); |
| 36 | + afterEach(() => fixture.destroy()); |
| 37 | + |
| 38 | + it("should create tags that match version when not using --sign-git-tag", async () => { |
| 39 | + const output = await fixture.lerna("version 3.3.3 -y"); |
| 40 | + |
| 41 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 42 | + lerna notice cli v999.9.9-e2e.0 |
| 43 | + lerna info current version 0.0.0 |
| 44 | + lerna info Assuming all packages changed |
| 45 | +
|
| 46 | + Changes: |
| 47 | + - package-a: 0.0.0 => 3.3.3 |
| 48 | +
|
| 49 | + lerna info auto-confirmed |
| 50 | + lerna info execute Skipping releases |
| 51 | + lerna info git Pushing tags... |
| 52 | + lerna success version finished |
| 53 | +
|
| 54 | + `); |
| 55 | + |
| 56 | + const checkTagIsPresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 57 | + |
| 58 | + expect(checkTagIsPresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 59 | + v3.3.3 |
| 60 | +
|
| 61 | + `); |
| 62 | + |
| 63 | + const checkTagIsPresentOnRemote = await fixture.exec("git ls-remote origin refs/tags/v3.3.3"); |
| 64 | + |
| 65 | + expect(checkTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 66 | + {FULL_COMMIT_SHA} refs/tags/v3.3.3 |
| 67 | +
|
| 68 | + `); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should create tags that match version when using --sign-git-tag", async () => { |
| 72 | + const output = await fixture.lerna("version 3.4.5 --sign-git-tag -y"); |
| 73 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 74 | + lerna notice cli v999.9.9-e2e.0 |
| 75 | + lerna info current version 0.0.0 |
| 76 | + lerna info Assuming all packages changed |
| 77 | +
|
| 78 | + Changes: |
| 79 | + - package-a: 0.0.0 => 3.4.5 |
| 80 | +
|
| 81 | + lerna info auto-confirmed |
| 82 | + lerna info execute Skipping releases |
| 83 | + lerna info git Pushing tags... |
| 84 | + lerna success version finished |
| 85 | +
|
| 86 | + `); |
| 87 | + |
| 88 | + const checkTagIsPresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 89 | + expect(checkTagIsPresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 90 | + v3.4.5 |
| 91 | +
|
| 92 | + `); |
| 93 | + |
| 94 | + const checkTagIsPresentOnRemote = await fixture.exec("git ls-remote origin refs/tags/v3.4.5"); |
| 95 | + expect(checkTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 96 | + {FULL_COMMIT_SHA} refs/tags/v3.4.5 |
| 97 | +
|
| 98 | + `); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + describe("multiple packages", () => { |
| 103 | + let fixture: Fixture; |
| 104 | + |
| 105 | + beforeEach(async () => { |
| 106 | + fixture = await Fixture.create({ |
| 107 | + e2eRoot: process.env.E2E_ROOT, |
| 108 | + name: "lerna-version-sign-git-tag-multiple-packages", |
| 109 | + packageManager: "npm", |
| 110 | + initializeGit: true, |
| 111 | + lernaInit: { args: [`--packages="packages/*"`] }, |
| 112 | + installDependencies: true, |
| 113 | + }); |
| 114 | + await fixture.lerna("create package-a -y"); |
| 115 | + await fixture.lerna("create package-b -y"); |
| 116 | + await fixture.createInitialGitCommit(); |
| 117 | + await fixture.exec("git push origin test-main"); |
| 118 | + }); |
| 119 | + afterEach(() => fixture.destroy()); |
| 120 | + |
| 121 | + it("should create tags that match version when not using --sign-git-tag", async () => { |
| 122 | + const output = await fixture.lerna("version 3.3.3 -y"); |
| 123 | + |
| 124 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 125 | + lerna notice cli v999.9.9-e2e.0 |
| 126 | + lerna info current version 0.0.0 |
| 127 | + lerna info Assuming all packages changed |
| 128 | +
|
| 129 | + Changes: |
| 130 | + - package-a: 0.0.0 => 3.3.3 |
| 131 | + - package-b: 0.0.0 => 3.3.3 |
| 132 | +
|
| 133 | + lerna info auto-confirmed |
| 134 | + lerna info execute Skipping releases |
| 135 | + lerna info git Pushing tags... |
| 136 | + lerna success version finished |
| 137 | +
|
| 138 | + `); |
| 139 | + |
| 140 | + const checkTagIsPresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 141 | + |
| 142 | + expect(checkTagIsPresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 143 | + v3.3.3 |
| 144 | +
|
| 145 | + `); |
| 146 | + |
| 147 | + const checkTagIsPresentOnRemote = await fixture.exec("git ls-remote origin refs/tags/v3.3.3"); |
| 148 | + |
| 149 | + expect(checkTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 150 | + {FULL_COMMIT_SHA} refs/tags/v3.3.3 |
| 151 | +
|
| 152 | + `); |
| 153 | + }); |
| 154 | + |
| 155 | + it("should create tags that match version when using --sign-git-tag", async () => { |
| 156 | + const output = await fixture.lerna("version 3.4.5 --sign-git-tag -y"); |
| 157 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 158 | + lerna notice cli v999.9.9-e2e.0 |
| 159 | + lerna info current version 0.0.0 |
| 160 | + lerna info Assuming all packages changed |
| 161 | +
|
| 162 | + Changes: |
| 163 | + - package-a: 0.0.0 => 3.4.5 |
| 164 | + - package-b: 0.0.0 => 3.4.5 |
| 165 | +
|
| 166 | + lerna info auto-confirmed |
| 167 | + lerna info execute Skipping releases |
| 168 | + lerna info git Pushing tags... |
| 169 | + lerna success version finished |
| 170 | +
|
| 171 | + `); |
| 172 | + |
| 173 | + const checkTagIsPresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 174 | + expect(checkTagIsPresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 175 | + v3.4.5 |
| 176 | +
|
| 177 | + `); |
| 178 | + |
| 179 | + const checkTagIsPresentOnRemote = await fixture.exec("git ls-remote origin refs/tags/v3.4.5"); |
| 180 | + expect(checkTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 181 | + {FULL_COMMIT_SHA} refs/tags/v3.4.5 |
| 182 | +
|
| 183 | + `); |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + describe("independent packages", () => { |
| 188 | + let fixture: Fixture; |
| 189 | + |
| 190 | + beforeEach(async () => { |
| 191 | + fixture = await Fixture.create({ |
| 192 | + e2eRoot: process.env.E2E_ROOT, |
| 193 | + name: "lerna-version-sign-git-tag-multiple-packages", |
| 194 | + packageManager: "npm", |
| 195 | + initializeGit: true, |
| 196 | + lernaInit: { args: [`--packages="packages/*" --independent`] }, |
| 197 | + installDependencies: true, |
| 198 | + }); |
| 199 | + await fixture.lerna("create package-a -y"); |
| 200 | + await fixture.lerna("create package-b -y"); |
| 201 | + await fixture.createInitialGitCommit(); |
| 202 | + await fixture.exec("git push origin test-main"); |
| 203 | + }); |
| 204 | + afterEach(() => fixture.destroy()); |
| 205 | + |
| 206 | + it("should create tags that match version when not using --sign-git-tag", async () => { |
| 207 | + const output = await fixture.lerna("version 3.3.3 -y"); |
| 208 | + |
| 209 | + // NOTE: In the independent case, lerna started with version 1.0.0 as its assumed baseline (not 0.0.0 as in the fixed mode case) |
| 210 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 211 | + lerna notice cli v999.9.9-e2e.0 |
| 212 | + lerna info versioning independent |
| 213 | + lerna info Assuming all packages changed |
| 214 | +
|
| 215 | + Changes: |
| 216 | + - package-a: 1.0.0 => 3.3.3 |
| 217 | + - package-b: 1.0.0 => 3.3.3 |
| 218 | +
|
| 219 | + lerna info auto-confirmed |
| 220 | + lerna info execute Skipping releases |
| 221 | + lerna info git Pushing tags... |
| 222 | + lerna success version finished |
| 223 | +
|
| 224 | + `); |
| 225 | + |
| 226 | + // It should create one tag for each independently versioned package |
| 227 | + const checkPackageTagsArePresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 228 | + expect(checkPackageTagsArePresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 229 | + package-a@3.3.3 |
| 230 | +
|
| 231 | + `); |
| 232 | + |
| 233 | + const checkPackageATagIsPresentOnRemote = await fixture.exec( |
| 234 | + "git ls-remote origin refs/tags/package-a@3.3.3" |
| 235 | + ); |
| 236 | + expect(checkPackageATagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 237 | + {FULL_COMMIT_SHA} refs/tags/package-a@3.3.3 |
| 238 | +
|
| 239 | + `); |
| 240 | + const checkPackageBTagIsPresentOnRemote = await fixture.exec( |
| 241 | + "git ls-remote origin refs/tags/package-b@3.3.3" |
| 242 | + ); |
| 243 | + expect(checkPackageBTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 244 | + {FULL_COMMIT_SHA} refs/tags/package-b@3.3.3 |
| 245 | +
|
| 246 | + `); |
| 247 | + }); |
| 248 | + |
| 249 | + it("should create tags that match version when using --sign-git-tag", async () => { |
| 250 | + const output = await fixture.lerna("version 3.4.5 --sign-git-tag -y"); |
| 251 | + |
| 252 | + // NOTE: In the independent case, lerna started with version 1.0.0 as its assumed baseline (not 0.0.0 as in the fixed mode case) |
| 253 | + expect(output.combinedOutput).toMatchInlineSnapshot(` |
| 254 | + lerna notice cli v999.9.9-e2e.0 |
| 255 | + lerna info versioning independent |
| 256 | + lerna info Assuming all packages changed |
| 257 | +
|
| 258 | + Changes: |
| 259 | + - package-a: 1.0.0 => 3.4.5 |
| 260 | + - package-b: 1.0.0 => 3.4.5 |
| 261 | +
|
| 262 | + lerna info auto-confirmed |
| 263 | + lerna info execute Skipping releases |
| 264 | + lerna info git Pushing tags... |
| 265 | + lerna success version finished |
| 266 | +
|
| 267 | + `); |
| 268 | + |
| 269 | + // It should create one tag for each independently versioned package |
| 270 | + const checkPackageTagsArePresentLocally = await fixture.exec("git describe --abbrev=0"); |
| 271 | + expect(checkPackageTagsArePresentLocally.combinedOutput).toMatchInlineSnapshot(` |
| 272 | + package-a@3.4.5 |
| 273 | +
|
| 274 | + `); |
| 275 | + |
| 276 | + const checkPackageATagIsPresentOnRemote = await fixture.exec( |
| 277 | + "git ls-remote origin refs/tags/package-a@3.4.5" |
| 278 | + ); |
| 279 | + expect(checkPackageATagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 280 | + {FULL_COMMIT_SHA} refs/tags/package-a@3.4.5 |
| 281 | +
|
| 282 | + `); |
| 283 | + const checkPackageBTagIsPresentOnRemote = await fixture.exec( |
| 284 | + "git ls-remote origin refs/tags/package-b@3.4.5" |
| 285 | + ); |
| 286 | + expect(checkPackageBTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(` |
| 287 | + {FULL_COMMIT_SHA} refs/tags/package-b@3.4.5 |
| 288 | +
|
| 289 | + `); |
| 290 | + }); |
| 291 | + }); |
| 292 | +}); |
0 commit comments