Skip to content

Commit

Permalink
Update lockfile when writing new version
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Mar 2, 2022
1 parent d230876 commit 8651035
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
45 changes: 44 additions & 1 deletion plugins/gem/__tests__/gem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe("Gem Plugin", () => {
});

describe("version", () => {
test("bump version", async () => {
test("bump version without lock", async () => {
mockFs({
'test.gemspec': endent`
Gem::Specification.new do |spec|
Expand All @@ -248,6 +248,49 @@ describe("Gem Plugin", () => {
`);
})


test("bump version with lock", async () => {
mockFs({
'gem.gemspec': endent`
Gem::Specification.new do |spec|
spec.version = "0.1.0"
end
`,
'Gemfile.lock': endent`
PATH
remote: .
specs:
gem (0.1.0)
GEM
remote: https://rubygems.org/
specs:
foo-gem (0.1.0)
`
})

const plugin = new Gem();
const hooks = makeHooks();

plugin.apply({ hooks, logger } as any);
await hooks.version.promise({ bump: SEMVER.minor });

expect(await fs.readFile('gem.gemspec', { encoding: 'utf-8' })).toBe(endent`
Gem::Specification.new do |spec|
spec.version = "0.2.0"
end
`);
expect(await fs.readFile('Gemfile.lock', { encoding: 'utf-8' })).toBe(endent`
PATH
remote: .
specs:
gem (0.2.0)
GEM
remote: https://rubygems.org/
specs:
foo-gem (0.1.0)
`);
})

test("throws with invalid version", async () => {
mockFs({
'test.gemspec': endent`
Expand Down
39 changes: 19 additions & 20 deletions plugins/gem/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,18 @@ export default class GemPlugin implements IPlugin {

await this.writeNewVersion(version, canaryVersion, versionFile)

/** Commit the new version. we wait because "rake build" changes the lock file */
/** we don't push that version, is just to clean the stage */
const commitVersion = async () =>
execPromise("git", [
"commit",
"-am",
`"update version: ${canaryVersion} [skip ci]"`,
"--no-verify",
]);
/** Commit the new version which we don't push. It's just to clean the stage */
await execPromise("git", [
"commit",
"-am",
`"update version: ${canaryVersion} [skip ci]"`,
"--no-verify",
]);


auto.logger.verbose.info("Running default release command");
const buildResult = await execPromise("bundle", ["exec", "rake", "build"]);
const gemPath = GEM_PKG_BUILD_REGEX.exec(buildResult)?.[0]
await commitVersion();
// will push the canary gem
await execPromise("gem", ["push", `${gemPath}`]);

Expand All @@ -170,23 +167,19 @@ export default class GemPlugin implements IPlugin {

const [version] = await this.getVersion(auto);

/** Commit the new version. we wait because "rake build" changes the lock file */
const commitVersion = async () =>
execPromise("git", [
"commit",
"-am",
`"update version: ${version} [skip ci]"`,
"--no-verify",
]);
await execPromise("git", [
"commit",
"-am",
`"update version: ${version} [skip ci]"`,
"--no-verify",
]);

if (this.options.releaseCommand) {
auto.logger.verbose.info("Running custom release command");
await commitVersion();
execSync(this.options.releaseCommand, { stdio: "inherit" });
} else {
auto.logger.verbose.info("Running default release command");
await execPromise("bundle", ["exec", "rake", "build"]);
await commitVersion();
// will tag and push
await execPromise("bundle", ["exec", "rake", "release"]);
}
Expand Down Expand Up @@ -265,6 +258,12 @@ export default class GemPlugin implements IPlugin {
const content = await readFile(versionFile, { encoding: "utf8" });
await writeFile(versionFile, content.replace(version, newVersion));

/** Update the lockfile to ensure no changes would be made on bundle exec rake build */
const lockFile = 'Gemfile.lock';
if (fs.existsSync(lockFile)) {
const lockContent = await readFile(lockFile, { encoding: "utf8" })
await writeFile(lockFile, lockContent.replace(` ${this.name} (${version})`, ` ${this.name} (${newVersion})`))
}
}

/** Get the current version of the gem and where it was found */
Expand Down

0 comments on commit 8651035

Please sign in to comment.