Skip to content

Commit

Permalink
Merge pull request #6 from Gusto/rc-fix-prerelease-version
Browse files Browse the repository at this point in the history
fix(prepare): use correct version for prereleases
  • Loading branch information
rylanc authored Jul 22, 2020
2 parents db9aa06 + 039f996 commit 80219d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('when the version.rb contains a prerelease version', () => {
expect(versionContents).toEqual(`# frozen_string_literal: true
module TestGem
VERSION = '1.0.0-alpha.1'
VERSION = '1.0.0.alpha.1'
end
`);
});
Expand Down
14 changes: 13 additions & 1 deletion src/__tests__/verifyConditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('when the gemspec has no name defined', () => {
});
});

it('finds the version file', async () => {
it('verifies the version file', async () => {
const { versionFile } = await verifyConditions(
{},
{ cwd: validCwd, env: defaultEnv },
Expand All @@ -57,6 +57,18 @@ it('finds the version file', async () => {
expect(versionFile).toEqual('lib/test-gem/version.rb');
});

describe('when the existing version file contains a prerelease version', () => {
it('verifies the version file', async () => {
const cwd = path.resolve(__dirname, './fixtures/prerelease');
const { versionFile } = await verifyConditions(
{},
{ cwd, env: defaultEnv },
{ credentialsFile },
);
expect(versionFile).toEqual('lib/test-gem/version.rb');
});
});

describe('when there is no version file', () => {
it('throws an error', async () => {
const cwd = path.resolve(__dirname, './fixtures/no-version-file');
Expand Down
7 changes: 6 additions & 1 deletion src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const { VERSION_REGEX } = require('./common');
const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => {
const fullVersionPath = path.resolve(cwd, versionFile);
const versionContents = await readFile(fullVersionPath, 'utf8');
const newContents = versionContents.replace(VERSION_REGEX, `$1${nextVersion}$2`);
const newContents = versionContents.replace(
VERSION_REGEX,
// Rubygems replaces all `-` with `.pre.`, which causes odd version differences between tags/releases
// and the published gem version. Replacing `-` with `.` is a smaller difference.
`$1${nextVersion.replace('-', '.')}$2`,
);
logger.log('Writing version %s to `%s`', nextVersion, versionFile);
await writeFile(fullVersionPath, newContents, 'utf8');
};
Expand Down

0 comments on commit 80219d2

Please sign in to comment.