Skip to content

Commit

Permalink
feat: allow to disable publishing (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger authored Jul 26, 2022
1 parent c227919 commit 8bc2f44
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
| Option | Type | Description |
| ------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `packageVsix` | `boolean` or `string` | If set to `true`, the plugin will generate a `.vsix` file. If is a string, it will be used as value for `--out` of `vsce package`. |
| `publish` | `boolean` | The plugin will publish the package unless this option is set to `false`, in which case it will only package the extension `vsix`. |

### Environment Variables

| Variable | Description |
| ---------- | --------------------------------------------------------------------------------------- |
| `VSCE_PAT` | **Required**. The personal access token to publish the extension of VS Code Marketplace |
| `OVSX_PAT` | _Optional_. The personal access token to push to OpenVSX |
| Variable | Description |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `VSCE_PAT` | _**Required**_ unless `publish` is set to `false`. The personal access token to publish the extension of VS Code Marketplace |
| `OVSX_PAT` | _Optional_. The personal access token to push to OpenVSX |

### Publishing to OpenVSX

Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let prepared = false;
let packagePath;

async function verifyConditions (pluginConfig, { logger }) {
await verifyVsce(logger);
await verifyVsce(logger, pluginConfig);
verified = true;
}

Expand All @@ -30,6 +30,12 @@ async function publish (pluginConfig, { nextRelease: { version }, logger }) {
// BC: prior to semantic-release v15 prepare was part of publish
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger);
}

// If publishing is disabled, return early.
if (pluginConfig?.publish === false) {
return;
}

return vscePublish(version, packagePath, logger);
}

Expand Down
9 changes: 5 additions & 4 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const verifyPkg = require('./verify-pkg');
const verifyAuth = require('./verify-auth');
const verifyOvsxAuth = require('./verify-ovsx-auth');

module.exports = async logger => {
module.exports = async (logger, pluginConfig) => {
await verifyPkg();

await verifyAuth(logger);

await verifyOvsxAuth(logger);
if (pluginConfig?.publish !== false) {
await verifyAuth(logger);
await verifyOvsxAuth(logger);
}
};
15 changes: 15 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,18 @@ test('publish that is already verified & prepared', async t => {
semanticReleasePayload.logger
]);
});

test('it does not publish the package if publishing is disabled', async t => {
const { verifyVsceStub, vscePrepareStub, vscePublishStub } = t.context.stubs;
const { prepare, publish, verifyConditions } = proxyquire('../index.js', {
'./lib/verify': verifyVsceStub,
'./lib/publish': vscePublishStub,
'./lib/prepare': vscePrepareStub
});

await verifyConditions({ ...pluginConfig, publish: false }, semanticReleasePayload);
await prepare({ ...pluginConfig, publish: false }, semanticReleasePayload);
await publish({ ...pluginConfig, publish: false }, semanticReleasePayload);

t.true(vscePublishStub.notCalled);
});
18 changes: 18 additions & 0 deletions test/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@ test('rejects with verify-pkg', async t => {

await t.throwsAsync(() => verify(logger));
});

test('is does not verify the auth tokens if publishing is disabled', async t => {
const stubs = {
verifyPkgStub: sinon.stub().resolves(),
verifyAuthStub: sinon.stub().resolves(),
verifyOvsxAuthStub: sinon.stub().resolves()
};
const verify = proxyquire('../lib/verify', {
'./verify-pkg': stubs.verifyPkgStub,
'./verify-auth': stubs.verifyAuthStub,
'./verify-ovsx-auth': stubs.verifyOvsxAuthStub
});

await verify(logger, { publish: false });

t.true(stubs.verifyAuthStub.notCalled);
t.true(stubs.verifyOvsxAuthStub.notCalled);
});

0 comments on commit 8bc2f44

Please sign in to comment.