Skip to content

Commit

Permalink
Merge pull request #7 from Gusto/rc-fix-gem-build
Browse files Browse the repository at this point in the history
fix(publish): use correct gemfile name when publishing prereleases
  • Loading branch information
rylanc authored Jul 22, 2020
2 parents 80219d2 + 2c04b0b commit 2db9e7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/__tests__/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`', () => {
Expand Down
25 changes: 17 additions & 8 deletions src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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 };
};

0 comments on commit 2db9e7a

Please sign in to comment.