Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Add the plugin to the [**semantic-release** configuration file](https://github.c

### Gem server authentication

The gem server authentication configuration is **required**.
The gem server authentication configuration is **required** unless `gemPublish` is explicitly set to `false`.

The API key must be set using the `GEM_HOST_API_KEY` environment variable. To retrieve the key, you can:
1. Login to [RubyGems.org](https://rubygems.org) and click on ['Edit Profile'](https://rubygems.org/profile/edit). You'll find the key in the 'API Access' section of the page.
Expand Down
22 changes: 18 additions & 4 deletions src/__tests__/verifyConditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,23 @@ it('creates the credentials file', async () => {
});

describe('when the API key env var is not defined', () => {
it('throws an error', async () => {
await expect(
verifyConditions({}, { cwd: validCwd, env: {} }, { credentialsFile }),
).rejects.toThrow(/^No gem API key specified.$/);
describe('with config defaults', () => {
it('throws an error', async () => {
await expect(
verifyConditions({}, { cwd: validCwd, env: {} }, { credentialsFile }),
).rejects.toThrow(/^No gem API key specified.$/);
});
});

describe('with gemPublish false', () => {
it('does not throw an error', async () => {
await expect(
verifyConditions({ gemPublish: false }, { cwd: validCwd, env: {} }, { credentialsFile }),
).resolves.toEqual({
gemName: 'a-test-gem',
gemspec: 'test-gem.gemspec',
versionFile: 'lib/test-gem/version.rb',
});
});
});
});
1 change: 1 addition & 0 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// taken from https://github.com/svenfuchs/gem-release/blob/0f5f2382ef960d40169400a8aa25085cd37d26b0/lib/gem/release/files/version.rb#L7
module.exports.VERSION_REGEX = /(VERSION\s*=\s*['"])(?:(?!"|').)*(['"])/;
module.exports.CONFIG_DEFAULTS = { gemPublish: true, gemFileDir: false };
7 changes: 6 additions & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const { unlink } = require('fs').promises;
const execa = require('execa');
const { CONFIG_DEFAULTS } = require('./common');

module.exports = async function publish(
{ gemHost, gemPublish = true, gemFileDir = false },
pluginConfig,
{ cwd, env, logger, nextRelease: { version }, stdout, stderr },
{ gemFile, gemName, credentialsFile },
) {
const { gemHost, gemPublish, gemFileDir } = {
...CONFIG_DEFAULTS,
...pluginConfig,
};
if (gemPublish !== false) {
logger.log(`Publishing version ${version} to gem server`);
const args = ['push', gemFile, '--config-file', credentialsFile];
Expand Down
12 changes: 9 additions & 3 deletions src/verifyConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const { writeFile, readFile } = require('fs').promises;
const SemanticReleaseError = require('@semantic-release/error');
const glob = util.promisify(require('glob'));
const { VERSION_REGEX } = require('./common');
const { VERSION_REGEX, CONFIG_DEFAULTS } = require('./common');

const loadGemspec = async cwd => {
const gemspecs = await glob('*.gemspec', { cwd });
Expand Down Expand Up @@ -113,15 +113,21 @@ You can retrieve an API key either from your \`~/.gem/credentials\` file or in y
*/
module.exports = async function verify(pluginConfig, { env, cwd }, { credentialsFile }) {
// - Verify ruby installed?
const { gemPublish } = {
...CONFIG_DEFAULTS,
...pluginConfig,
};

// - Locate gemspec and determine name
const { name, gemspec } = await loadGemspec(cwd);

// - Locate version file
const versionFile = await verifyVersionFile(cwd);

// - Verify env var
await verifyApiKey({ env, cwd, credentialsFile });
if (gemPublish) {
// - Verify env var
await verifyApiKey({ env, cwd, credentialsFile });
}

return { gemName: name, gemspec, versionFile };
};