Skip to content

Commit

Permalink
Merge pull request #8 from Gusto/rc-more-options
Browse files Browse the repository at this point in the history
add more config options
  • Loading branch information
rylanc authored Jul 23, 2020
2 parents 2db9e7a + ade7b1c commit 7cc59eb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 26 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ end
| Options | Description | Default |
|--------------|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `gemHost` | The gem server to push the gem to. | `'https//rubygems.org'` |
| `updateGemfileLock` | Whether to update the version of the gem to publish in the `Gemfile.lock`. This is useful if you are using the [`@semantic-release/git`](https://github.com/semantic-release/git) plugin to keep the version up to date in your git repo. When set to `true` the plugin will run `bundle install` to update the version. If another command is desired, it can be set by passing a string (e.g. `bundle appraisal install`). | `false`
| `updateGemfileLock` | Whether to update the version of the gem to publish in the `Gemfile.lock`. This is useful if you are using the [`@semantic-release/git`](https://github.com/semantic-release/git) plugin to keep the version up to date in your git repo. When set to `true` the plugin will run `bundle install` to update the version. If another command is desired, it can be set by passing a string (e.g. `bundle appraisal install`). | `false` |
| `gemPublish` | Whether to publish your gem to the gem server. | `true` |
| `gemFileDir` | Directory path in which to write the the built `.gem` file. If `false`, the `.gem` file will not be kept on the file system. | `false` |
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dependencies": {
"@semantic-release/error": "^2.2.0",
"execa": "^4.0.2",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"tempy": "^0.5.0"
},
Expand Down
21 changes: 18 additions & 3 deletions src/__tests__/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ afterEach(async () => {
await cleanUp();
});

const expectFileExists = file => expect(access(path.resolve(cwd, file))).resolves.toBeUndefined();

it('writes the new version to the version.rb file', async () => {
await prepare({}, context, { versionFile, gemspec, gemName });
const versionContents = await readFile(path.resolve(cwd, versionFile), 'utf8');
Expand Down Expand Up @@ -68,7 +70,7 @@ end
);

expect(gemFile).toEqual('a-test-gem-1.0.0.alpha.1.gem');
await expect(access(path.resolve(cwd, gemFile))).resolves.toBeUndefined();
await expectFileExists(gemFile);
});
});

Expand Down Expand Up @@ -98,13 +100,26 @@ describe('when updateGemfileLock is set to a string', () => {
gemspec,
gemName,
});
await expect(access(path.resolve(cwd, 'command_run'))).resolves.toBeUndefined();
await expectFileExists('command_run');
});
});

it('builds the gem', async () => {
const { gemFile } = await prepare({}, context, { versionFile, gemspec, gemName });

expect(gemFile).toEqual('a-test-gem-1.2.0.gem');
await expect(access(path.resolve(cwd, gemFile))).resolves.toBeUndefined();
await expectFileExists(gemFile);
});

describe('when gemFileDir is set', () => {
it('builds the gem in the provided dir', async () => {
const { gemFile } = await prepare({ gemFileDir: 'some_dir' }, context, {
versionFile,
gemspec,
gemName,
});

expect(gemFile).toEqual('some_dir/a-test-gem-1.2.0.gem');
await expectFileExists(gemFile);
});
});
17 changes: 15 additions & 2 deletions src/prepare.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { readFile, writeFile } = require('fs').promises;
const path = require('path');
const execa = require('execa');
const { move } = require('fs-extra');
const { VERSION_REGEX } = require('./common');

const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => {
Expand Down Expand Up @@ -39,7 +40,7 @@ const buildGem = async ({ gemspec, gemName, version, cwd, env, logger, stdout, s
};

module.exports = async function prepare(
{ updateGemfileLock = false },
{ updateGemfileLock = false, gemFileDir = false },
{ nextRelease: { version }, cwd, env, logger, stdout, stderr },
{ versionFile, gemspec, gemName },
) {
Expand All @@ -49,7 +50,7 @@ module.exports = async function prepare(
await bundleInstall({ updateGemfileLock, cwd, env, logger, stdout, stderr });
}

const gemFile = await buildGem({
let gemFile = await buildGem({
gemspec,
gemName,
version: gemVersion,
Expand All @@ -60,5 +61,17 @@ module.exports = async function prepare(
stderr,
});

if (gemFileDir) {
const gemFileSource = path.resolve(cwd, gemFile);
const gemFileDestination = path.resolve(cwd, gemFileDir.trim(), gemFile);

// Only move the gem file if we need to
if (gemFileSource !== gemFileDestination) {
await move(gemFileSource, gemFileDestination);
}

gemFile = path.join(gemFileDir.trim(), gemFile);
}

return { gemFile };
};
29 changes: 18 additions & 11 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ const { unlink } = require('fs').promises;
const execa = require('execa');

module.exports = async function publish(
{ gemHost },
{ gemHost, gemPublish = true, gemFileDir = false },
{ cwd, env, logger, nextRelease: { version }, stdout, stderr },
{ gemFile, gemName, credentialsFile },
) {
logger.log(`Publishing version ${version} to gem server`);
const args = ['push', gemFile, '--config-file', credentialsFile];
if (gemHost) {
args.push('--host', gemHost);
if (gemPublish !== false) {
logger.log(`Publishing version ${version} to gem server`);
const args = ['push', gemFile, '--config-file', credentialsFile];
if (gemHost) {
args.push('--host', gemHost);
}
const pushResult = execa('gem', args, { cwd, env });
pushResult.stdout.pipe(stdout, { end: false });
pushResult.stderr.pipe(stderr, { end: false });
await pushResult;

logger.log(`Published version ${version} of ${gemName} to gem server`);
} else {
logger.log(`Skip publishing to gem server because gemPublish is ${gemPublish !== false}`);
}
const pushResult = execa('gem', args, { cwd, env });
pushResult.stdout.pipe(stdout, { end: false });
pushResult.stderr.pipe(stderr, { end: false });
await pushResult;

logger.log(`Published version ${version} of ${gemName} to gem server`);
await unlink(gemFile);
if (gemFileDir === false) {
await unlink(gemFile);
}
};
10 changes: 1 addition & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ from2@^2.1.0, from2@^2.3.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-extra@^9.0.0:
fs-extra@^9.0.0, fs-extra@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
Expand Down Expand Up @@ -5262,7 +5262,6 @@ npm@^6.10.3:
cmd-shim "^3.0.3"
columnify "~1.5.4"
config-chain "^1.1.12"
debuglog "*"
detect-indent "~5.0.0"
detect-newline "^2.1.0"
dezalgo "~1.0.3"
Expand All @@ -5277,7 +5276,6 @@ npm@^6.10.3:
has-unicode "~2.0.1"
hosted-git-info "^2.8.8"
iferr "^1.0.2"
imurmurhash "*"
infer-owner "^1.0.4"
inflight "~1.0.6"
inherits "^2.0.4"
Expand All @@ -5296,14 +5294,8 @@ npm@^6.10.3:
libnpx "^10.2.2"
lock-verify "^2.1.0"
lockfile "^1.0.4"
lodash._baseindexof "*"
lodash._baseuniq "~4.6.0"
lodash._bindcallback "*"
lodash._cacheindexof "*"
lodash._createcache "*"
lodash._getnative "*"
lodash.clonedeep "~4.5.0"
lodash.restparam "*"
lodash.union "~4.6.0"
lodash.uniq "~4.5.0"
lodash.without "~4.4.0"
Expand Down

0 comments on commit 7cc59eb

Please sign in to comment.