Skip to content

Commit

Permalink
Merge pull request #217 from semantic-release/fix/zip-check
Browse files Browse the repository at this point in the history
Implemented checking of zip command
  • Loading branch information
seebeen authored Jan 19, 2024
2 parents f68b4f8 + cf28b96 commit e9d5bab
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
48 changes: 20 additions & 28 deletions lib/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,37 @@ export async function publish(
context: PublishContext,
): Promise<void> {
config = await transformAndValidate(PluginConfig, config);

const releaseDir = path.resolve(config.releasePath);
const assetDir = path.resolve(releaseDir, 'assets');
const versionFile = path.resolve(releaseDir, 'VERSION');
const zipCommand = process.env.ZIP_COMMAND ?? 'zip';

const packageResult = await execa(
zipCommand,
['-qr', path.join(releaseDir, `package.zip`), config.slug],
{
reject: false,
cwd: config.releasePath,
timeout: 30 * 1000,
},
);

if (
('exitCode' in packageResult && packageResult.exitCode !== 0) ||
('code' in packageResult && packageResult.code !== 0)
) {
throw getError('EZIP', packageResult.stderr);
}

if (config.withAssets) {
const zipResult = await execa(
try {
const packageResult = await execa(
zipCommand,
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
['-qr', path.join(releaseDir, `package.zip`), config.slug],
{
reject: false,
cwd: assetDir,
cwd: config.releasePath,
timeout: 30 * 1000,
},
);
if (
('exitCode' in zipResult && zipResult.exitCode !== 0) ||
('code' in zipResult && zipResult.code !== 0)
) {
throw getError('EZIP', zipResult.stderr);

const zipResult = config.withAssets
? await execa(
zipCommand,
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
{
cwd: assetDir,
timeout: 30 * 1000,
},
)
: { exitCode: 0, stderr: '' };

if (packageResult.exitCode !== 0 || zipResult.exitCode !== 0) {
throw getError('EZIP', packageResult.stderr || zipResult.stderr);
}
} catch (err) {
throw getError(err.code ?? 'EZIP', err.message);
}

if (config.withVersionFile) {
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ export function EZIP(zipError: string) {
};
}

export function ENOENT(zipError: string) {
return {
message: `File not found.`,
details: `The file was not found: ${zipError}.`,
};
}

export function ETHEMEFILENOTFOUND(file: string) {
return {
message: `Your theme must contain these files: ${file}`,
Expand Down
4 changes: 2 additions & 2 deletions test/3-publish-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Publish step', () => {
await fs.remove(path.join(releasePath, 'assets'));
await publish(pluginConfig, contexts.publishContext);
} catch (err) {
expect((err as SemanticReleaseError).code).toBe('EZIP');
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);
}
}, 10000);

Expand All @@ -99,7 +99,7 @@ describe('Publish step', () => {
await prepare(pluginConfig, contexts.publishContext);
await publish(pluginConfig, contexts.publishContext);
} catch (err) {
expect((err as SemanticReleaseError).code).toBe('EZIP');
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);
}
}, 5000);
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"node",
"jest",
],
"useUnknownInCatchVariables": false,
"allowJs": true,
"removeComments": false,
"noLib": false,
Expand Down

0 comments on commit e9d5bab

Please sign in to comment.