Skip to content

Commit 18561a8

Browse files
committed
fix: Make GEM_HOST_API_KEY optional for gemPublish: false
1 parent f254976 commit 18561a8

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Add the plugin to the [**semantic-release** configuration file](https://github.c
3232

3333
### Gem server authentication
3434

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

3737
The API key must be set using the `GEM_HOST_API_KEY` environment variable. To retrieve the key, you can:
3838
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.

src/__tests__/verifyConditions.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,23 @@ it('creates the credentials file', async () => {
9696
});
9797

9898
describe('when the API key env var is not defined', () => {
99-
it('throws an error', async () => {
100-
await expect(
101-
verifyConditions({}, { cwd: validCwd, env: {} }, { credentialsFile }),
102-
).rejects.toThrow(/^No gem API key specified.$/);
99+
describe('with config defaults', () => {
100+
it('throws an error', async () => {
101+
await expect(
102+
verifyConditions({}, { cwd: validCwd, env: {} }, { credentialsFile }),
103+
).rejects.toThrow(/^No gem API key specified.$/);
104+
});
105+
});
106+
107+
describe('with gemPublish false', () => {
108+
it('does not throw an error', async () => {
109+
await expect(
110+
verifyConditions({ gemPublish: false }, { cwd: validCwd, env: {} }, { credentialsFile }),
111+
).resolves.toEqual({
112+
gemName: 'a-test-gem',
113+
gemspec: 'test-gem.gemspec',
114+
versionFile: 'lib/test-gem/version.rb',
115+
});
116+
});
103117
});
104118
});

src/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// taken from https://github.com/svenfuchs/gem-release/blob/0f5f2382ef960d40169400a8aa25085cd37d26b0/lib/gem/release/files/version.rb#L7
22
module.exports.VERSION_REGEX = /(VERSION\s*=\s*['"])(?:(?!"|').)*(['"])/;
3+
module.exports.CONFIG_DEFAULTS = { gemPublish: true, gemFileDir: false };

src/publish.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
const { unlink } = require('fs').promises;
22
const execa = require('execa');
3+
const { CONFIG_DEFAULTS } = require('./common');
34

45
module.exports = async function publish(
5-
{ gemHost, gemPublish = true, gemFileDir = false },
6+
pluginConfig,
67
{ cwd, env, logger, nextRelease: { version }, stdout, stderr },
78
{ gemFile, gemName, credentialsFile },
89
) {
10+
const { gemHost, gemPublish, gemFileDir } = {
11+
...CONFIG_DEFAULTS,
12+
...pluginConfig,
13+
};
914
if (gemPublish !== false) {
1015
logger.log(`Publishing version ${version} to gem server`);
1116
const args = ['push', gemFile, '--config-file', credentialsFile];

src/verifyConditions.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
const { writeFile, readFile } = require('fs').promises;
66
const SemanticReleaseError = require('@semantic-release/error');
77
const glob = util.promisify(require('glob'));
8-
const { VERSION_REGEX } = require('./common');
8+
const { VERSION_REGEX, CONFIG_DEFAULTS } = require('./common');
99

1010
const loadGemspec = async cwd => {
1111
const gemspecs = await glob('*.gemspec', { cwd });
@@ -113,15 +113,22 @@ You can retrieve an API key either from your \`~/.gem/credentials\` file or in y
113113
*/
114114
module.exports = async function verify(pluginConfig, { env, cwd }, { credentialsFile }) {
115115
// - Verify ruby installed?
116+
const { gemPublish } = {
117+
...CONFIG_DEFAULTS,
118+
...pluginConfig,
119+
};
116120

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

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

123-
// - Verify env var
124-
await verifyApiKey({ env, cwd, credentialsFile });
127+
console.log('gemPublish', gemPublish);
128+
if (gemPublish) {
129+
// - Verify env var
130+
await verifyApiKey({ env, cwd, credentialsFile });
131+
}
125132

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

0 commit comments

Comments
 (0)