Skip to content

Commit e9d5bab

Browse files
authored
Merge pull request #217 from semantic-release/fix/zip-check
Implemented checking of zip command
2 parents f68b4f8 + cf28b96 commit e9d5bab

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

lib/publish.ts

+20-28
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,37 @@ export async function publish(
1111
context: PublishContext,
1212
): Promise<void> {
1313
config = await transformAndValidate(PluginConfig, config);
14-
1514
const releaseDir = path.resolve(config.releasePath);
1615
const assetDir = path.resolve(releaseDir, 'assets');
1716
const versionFile = path.resolve(releaseDir, 'VERSION');
1817
const zipCommand = process.env.ZIP_COMMAND ?? 'zip';
1918

20-
const packageResult = await execa(
21-
zipCommand,
22-
['-qr', path.join(releaseDir, `package.zip`), config.slug],
23-
{
24-
reject: false,
25-
cwd: config.releasePath,
26-
timeout: 30 * 1000,
27-
},
28-
);
29-
30-
if (
31-
('exitCode' in packageResult && packageResult.exitCode !== 0) ||
32-
('code' in packageResult && packageResult.code !== 0)
33-
) {
34-
throw getError('EZIP', packageResult.stderr);
35-
}
36-
37-
if (config.withAssets) {
38-
const zipResult = await execa(
19+
try {
20+
const packageResult = await execa(
3921
zipCommand,
40-
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
22+
['-qr', path.join(releaseDir, `package.zip`), config.slug],
4123
{
42-
reject: false,
43-
cwd: assetDir,
24+
cwd: config.releasePath,
4425
timeout: 30 * 1000,
4526
},
4627
);
47-
if (
48-
('exitCode' in zipResult && zipResult.exitCode !== 0) ||
49-
('code' in zipResult && zipResult.code !== 0)
50-
) {
51-
throw getError('EZIP', zipResult.stderr);
28+
29+
const zipResult = config.withAssets
30+
? await execa(
31+
zipCommand,
32+
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
33+
{
34+
cwd: assetDir,
35+
timeout: 30 * 1000,
36+
},
37+
)
38+
: { exitCode: 0, stderr: '' };
39+
40+
if (packageResult.exitCode !== 0 || zipResult.exitCode !== 0) {
41+
throw getError('EZIP', packageResult.stderr || zipResult.stderr);
5242
}
43+
} catch (err) {
44+
throw getError(err.code ?? 'EZIP', err.message);
5345
}
5446

5547
if (config.withVersionFile) {

lib/utils/errors.ts

+7
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ export function EZIP(zipError: string) {
207207
};
208208
}
209209

210+
export function ENOENT(zipError: string) {
211+
return {
212+
message: `File not found.`,
213+
details: `The file was not found: ${zipError}.`,
214+
};
215+
}
216+
210217
export function ETHEMEFILENOTFOUND(file: string) {
211218
return {
212219
message: `Your theme must contain these files: ${file}`,

test/3-publish-plugin.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('Publish step', () => {
8888
await fs.remove(path.join(releasePath, 'assets'));
8989
await publish(pluginConfig, contexts.publishContext);
9090
} catch (err) {
91-
expect((err as SemanticReleaseError).code).toBe('EZIP');
91+
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);
9292
}
9393
}, 10000);
9494

@@ -99,7 +99,7 @@ describe('Publish step', () => {
9999
await prepare(pluginConfig, contexts.publishContext);
100100
await publish(pluginConfig, contexts.publishContext);
101101
} catch (err) {
102-
expect((err as SemanticReleaseError).code).toBe('EZIP');
102+
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);
103103
}
104104
}, 5000);
105105
});

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"node",
1414
"jest",
1515
],
16+
"useUnknownInCatchVariables": false,
1617
"allowJs": true,
1718
"removeComments": false,
1819
"noLib": false,

0 commit comments

Comments
 (0)