From d079b25d1254b72c8259a3e429f372ef6fd39d5e Mon Sep 17 00:00:00 2001 From: Rylan Collins Date: Wed, 22 Jul 2020 12:41:07 -0700 Subject: [PATCH 1/2] fix(prepare): use correct version for prereleases this fix requires that all `-` be replaced by `.` in the gem version to avoid version inconsistencies --- src/__tests__/prepare.test.js | 2 +- src/__tests__/verifyConditions.test.js | 2 +- src/prepare.js | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/__tests__/prepare.test.js b/src/__tests__/prepare.test.js index 6cc55aa..66bd319 100644 --- a/src/__tests__/prepare.test.js +++ b/src/__tests__/prepare.test.js @@ -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 `); }); diff --git a/src/__tests__/verifyConditions.test.js b/src/__tests__/verifyConditions.test.js index 83b07af..2391ce2 100644 --- a/src/__tests__/verifyConditions.test.js +++ b/src/__tests__/verifyConditions.test.js @@ -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 }, diff --git a/src/prepare.js b/src/prepare.js index b6500c2..b3b9072 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -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'); }; From 039f996ef1a10420f1eb47df4eb942ae6b519e24 Mon Sep 17 00:00:00 2001 From: Rylan Collins Date: Wed, 22 Jul 2020 12:44:35 -0700 Subject: [PATCH 2/2] test: add test for prerelease version.rb verification --- src/__tests__/verifyConditions.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/__tests__/verifyConditions.test.js b/src/__tests__/verifyConditions.test.js index 2391ce2..9e7ed00 100644 --- a/src/__tests__/verifyConditions.test.js +++ b/src/__tests__/verifyConditions.test.js @@ -57,6 +57,18 @@ it('verifies 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');