Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable signing in vsce using script #986

Merged
merged 9 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
196 changes: 196 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"@azure/identity": "^4.1.0",
"@vscode/vsce-sign": "^2.0.0",
"azure-devops-node-api": "^12.5.0",
"chalk": "^2.4.2",
"cheerio": "^1.0.0-rc.9",
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ module.exports = function (argv: string[]): void {
.option('--allow-star-activation', 'Allow using * in activation events')
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
.option('--skip-license', 'Allow packaging without license file')
.option('--sign-tool', 'Path to the VSIX signing tool. Will be invoked with two arguments: `SIGNTOOL <path/to/extension.signature.manifest> <path/to/extension.signature.p7s>`.')
.action(
(
version,
Expand All @@ -143,6 +144,7 @@ module.exports = function (argv: string[]): void {
allowStarActivation,
allowMissingRepository,
skipLicense,
signTool,
}
) =>
main(
Expand Down Expand Up @@ -170,6 +172,7 @@ module.exports = function (argv: string[]): void {
allowStarActivation,
allowMissingRepository,
skipLicense,
signTool,
})
)
);
Expand All @@ -195,6 +198,7 @@ module.exports = function (argv: string[]): void {
.option('--no-update-package-json', 'Do not update `package.json`. Valid only when [version] is provided.')
.option('-i, --packagePath <paths...>', 'Publish the provided VSIX packages.')
.option('--sigzipPath <paths...>', 'Signature archives to publish alongside the VSIX packages.')
.option('--sign-tool', 'Path to the VSIX signing tool. Will be invoked with two arguments: `SIGNTOOL <path/to/extension.signature.manifest> <path/to/extension.signature.p7s>`. This will be ignored if --sigzipPath is provided.')
.option(
'--githubBranch <branch>',
'The GitHub branch used to infer relative links in README.md. Can be overridden by --baseContentUrl and --baseImagesUrl.'
Expand Down Expand Up @@ -249,6 +253,7 @@ module.exports = function (argv: string[]): void {
allowMissingRepository,
skipDuplicate,
skipLicense,
signTool,
}
) =>
main(
Expand Down Expand Up @@ -280,6 +285,7 @@ module.exports = function (argv: string[]): void {
allowMissingRepository,
skipDuplicate,
skipLicense,
signTool
})
)
);
Expand Down
22 changes: 22 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { detectYarn, getDependencies } from './npm';
import * as GitHost from 'hosted-git-info';
import parseSemver from 'parse-semver';
import * as jsonc from 'jsonc-parser';
import { generateManifest, zip } from '@vscode/vsce-sign';

const MinimatchOptions: minimatch.IOptions = { dot: true };

Expand Down Expand Up @@ -151,6 +152,8 @@ export interface IPackageOptions {
readonly allowStarActivation?: boolean;
readonly allowMissingRepository?: boolean;
readonly skipLicense?: boolean;

readonly signTool?: string;
}

export interface IProcessor {
Expand Down Expand Up @@ -1840,6 +1843,20 @@ export async function pack(options: IPackageOptions = {}): Promise<IPackageResul
return { manifest, packagePath, files };
}

export async function signPackage(packageFile: string, signScript: string): Promise<string> {
const packageFolder = path.dirname(packageFile);
const packageName = path.basename(packageFile, '.vsix');
const manifestFile = path.join(packageFolder, `${packageName}.signature.manifest`);
const signatureFile = path.join(packageFolder, `${packageName}.signature.p7s`);
const signatureZip = path.join(packageFolder, `${packageName}.signature.zip`);

await generateManifest(packageFile, manifestFile);
const { stdout } = await promisify(cp.execFile)(signScript, [manifestFile, signatureFile]);
console.log(stdout);
sandy081 marked this conversation as resolved.
Show resolved Hide resolved

return zip(manifestFile, signatureFile, signatureZip);
}

export async function packageCommand(options: IPackageOptions = {}): Promise<any> {
const cwd = options.cwd || process.cwd();
const manifest = await readManifest(cwd);
Expand All @@ -1849,6 +1866,11 @@ export async function packageCommand(options: IPackageOptions = {}): Promise<any
await versionBump(options);

const { packagePath, files } = await pack(options);

if (options.signTool) {
await signPackage(packagePath, options.signTool);
}

const stats = await fs.promises.stat(packagePath);

let size = 0;
Expand Down
17 changes: 13 additions & 4 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import { promisify } from 'util';
import * as semver from 'semver';
import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
import { pack, readManifest, versionBump, prepublish } from './package';
import { pack, readManifest, versionBump, prepublish, signPackage } from './package';
import * as tmp from 'tmp';
import { IVerifyPatOptions, getPublisher } from './store';
import { getGalleryAPI, read, getPublishedUrl, log, getHubUrl, patchOptionsWithManifest, getAzureCredentialAccessToken } from './util';
Expand Down Expand Up @@ -76,6 +76,7 @@ export interface IPublishOptions {
readonly skipLicense?: boolean;

readonly sigzipPath?: string[];
readonly signTool?: string;
}

export async function publish(options: IPublishOptions = {}): Promise<any> {
Expand Down Expand Up @@ -117,7 +118,13 @@ export async function publish(options: IPublishOptions = {}): Promise<any> {

validateMarketplaceRequirements(vsix.manifest, options);

await _publish(packagePath, options.sigzipPath?.[index], vsix.manifest, { ...options, target });
let sigzipPath = options.sigzipPath?.[index];
if (!sigzipPath && options.signTool) {
sigzipPath = await signPackage(packagePath, options.signTool);
}


await _publish(packagePath, sigzipPath, vsix.manifest, { ...options, target });
}
} else {
const cwd = options.cwd || process.cwd();
Expand All @@ -134,12 +141,14 @@ export async function publish(options: IPublishOptions = {}): Promise<any> {
for (const target of options.targets) {
const packagePath = await tmpName();
const packageResult = await pack({ ...options, target, packagePath });
await _publish(packagePath, undefined, packageResult.manifest, { ...options, target });
const sigzipPath = options.signTool ? await signPackage(packagePath, options.signTool) : undefined;
await _publish(packagePath, sigzipPath, packageResult.manifest, { ...options, target });
}
} else {
const packagePath = await tmpName();
const packageResult = await pack({ ...options, packagePath });
await _publish(packagePath, undefined, packageResult.manifest, options);
const sigzipPath = options.signTool ? await signPackage(packagePath, options.signTool) : undefined;
await _publish(packagePath, sigzipPath, packageResult.manifest, options);
}
}
}
Expand Down