diff --git a/src/__tests__/prepare.test.js b/src/__tests__/prepare.test.js index 66bd319..06ee50f 100644 --- a/src/__tests__/prepare.test.js +++ b/src/__tests__/prepare.test.js @@ -59,6 +59,17 @@ module TestGem end `); }); + + it('builds the gem', async () => { + const { gemFile } = await prepare( + {}, + { ...context, nextRelease: { version: '1.0.0-alpha.1' } }, + { versionFile, gemspec, gemName }, + ); + + expect(gemFile).toEqual('a-test-gem-1.0.0.alpha.1.gem'); + await expect(access(path.resolve(cwd, gemFile))).resolves.toBeUndefined(); + }); }); describe('when updateGemfileLock is set to `true`', () => { diff --git a/src/prepare.js b/src/prepare.js index b3b9072..d2b64ef 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -4,16 +4,16 @@ const execa = require('execa'); const { VERSION_REGEX } = require('./common'); const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => { + // Rubygems replaces all `-` with `.pre.`, which causes odd version differences between tags/releases + // and the published gem version. Replacing `-` with `.` is a smaller difference. + const gemVersion = nextVersion.replace('-', '.'); const fullVersionPath = path.resolve(cwd, versionFile); const versionContents = await readFile(fullVersionPath, 'utf8'); - 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`, - ); + const newContents = versionContents.replace(VERSION_REGEX, `$1${gemVersion}$2`); logger.log('Writing version %s to `%s`', nextVersion, versionFile); await writeFile(fullVersionPath, newContents, 'utf8'); + + return { gemVersion }; }; const bundleInstall = async ({ updateGemfileLock, cwd, env, logger, stdout, stderr }) => { @@ -43,13 +43,22 @@ module.exports = async function prepare( { nextRelease: { version }, cwd, env, logger, stdout, stderr }, { versionFile, gemspec, gemName }, ) { - await writeVersion({ versionFile, nextVersion: version, logger, cwd }); + const { gemVersion } = await writeVersion({ versionFile, nextVersion: version, logger, cwd }); if (updateGemfileLock) { await bundleInstall({ updateGemfileLock, cwd, env, logger, stdout, stderr }); } - const gemFile = await buildGem({ gemspec, gemName, version, cwd, env, logger, stdout, stderr }); + const gemFile = await buildGem({ + gemspec, + gemName, + version: gemVersion, + cwd, + env, + logger, + stdout, + stderr, + }); return { gemFile }; };