Skip to content

Commit

Permalink
Merge pull request #249 from semantic-release/revert-247-fix/asset-pu…
Browse files Browse the repository at this point in the history
…blish

Revert "Fix/asset-publish"
  • Loading branch information
seebeen authored Sep 21, 2024
2 parents af008dc + 6d59933 commit 67db9b0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lib/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function publish(
const zipResult = config.withAssets
? await execa(
zipCommand,
['-qr', path.join(releaseDir, `assets.zip`), '.'],
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
{
cwd: assetDir,
timeout: 30 * 1000,
Expand Down
20 changes: 0 additions & 20 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"devDependencies": {
"@babel/core": "7.24.7",
"@babel/preset-env": "7.24.7",
"@types/adm-zip": "^0.5.5",
"@types/fs-extra": "11.0.4",
"@types/jest": "29.5.12",
"@types/node": "20.14.7",
Expand All @@ -55,7 +54,6 @@
"@types/sinon": "17.0.3",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"adm-zip": "^0.5.16",
"babel-jest": "29.7.0",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
Expand Down
15 changes: 5 additions & 10 deletions test/2-prepare-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,17 @@ describe('Package preparation - default work directory', () => {
contexts.prepareContext,
);

const assets = new Set(
fs.readdirSync(path.join(releasePath, 'assets'), {
recursive: true,
}) as string[],
);
const assets = fs.readdirSync(path.join(releasePath, 'assets'));

expect([...assets]).toHaveLength(6);
expect(assets).toEqual(
new Set([
expect(assets).toHaveLength(5);
expect(assets.sort()).toStrictEqual(
[
'blueprints',
'blueprints/blueprint.json',
'banner-low.jpg',
'banner-high.jpg',
'screenshot-1.jpg',
'screenshot-2.jpg',
]),
].sort(),
);
});
});
56 changes: 14 additions & 42 deletions test/3-publish-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { replaceVersions } from '../lib/utils/replace-versions.js';
import { success } from '../lib/success.js';
import SemanticReleaseError from '@semantic-release/error';
import { publish } from '../lib/publish.js';
import AdmZip, { IZipEntry } from 'adm-zip';

const pluginConfig: PluginConfig = {
type: 'plugin',
Expand All @@ -22,37 +21,12 @@ const pluginConfig: PluginConfig = {
workDir: 'publish',
};

let wDir: string;
let releasePath: string;
const env = process.env;

function readZip(dir: string, file: string, pfx: RegExp = /.^/): Set<string> {
return new Set(
new AdmZip(path.join(dir, file))
.getEntries()
.map(({ entryName }) => entryName.replace(pfx, '').replace(/\/$/, ''))
.filter((e) => e !== '' && (pfx.source == '.^' || !e.match(/\//))),
);
}

function readDir(
root: string,
dir: string,
recursive: boolean = false,
): Set<string> {
return new Set(
fs.readdirSync(path.join(root, dir), {
recursive,
}) as string[],
);
}

function readFile(root: string, file: string): string {
return fs.readFileSync(path.join(root, file), 'utf8');
}

beforeAll(async () => {
wDir = fs.mkdtempSync('/tmp/wp-release-');
pluginConfig.releasePath = wDir;
releasePath = fs.mkdtempSync('/tmp/wp-release-');
pluginConfig.releasePath = releasePath;
});

beforeEach(() => {
Expand All @@ -77,30 +51,28 @@ afterEach(async () => {
});

afterAll(async () => {
fs.removeSync(wDir);
fs.removeSync(releasePath);
});

describe('Publish step', () => {
it('Should zip a complete plugin properly', async () => {
it('Should package a complete plugin', async () => {
await prepare(pluginConfig, contexts.publishContext);
await publish(pluginConfig, contexts.publishContext);

expect(readFile(path.join(wDir, 'dist-test'), 'readme.txt')).toMatch(
/^Stable tag: 1.0.0$/gm,
);
expect(readZip(wDir, 'package.zip', /^dist-test\//)).toEqual(
readDir(wDir, 'dist-test'),
);
expect(readZip(wDir, 'assets.zip')).toEqual(readDir(wDir, 'assets', true));
expect(readFile(wDir, 'VERSION')).toEqual('1.0.0');
const distFolder = fs
.readdirSync(path.join(releasePath, 'dist-test'))
.join(' ');

// expect readZip(releasePath, 'assets.zip');
expect(distFolder).not.toContain('node_modules');
expect(distFolder).toContain('vendor');
expect(distFolder).toContain('dist-test.php');
expect(distFolder).toContain('test1.php');
});

it('Should should remove folders on success', async () => {
await success(pluginConfig, contexts.publishContext);

const files = fs.readdirSync(wDir).join(' ');
const files = fs.readdirSync(releasePath).join(' ');

expect(files).toContain('package.zip');
expect(files).toContain('assets.zip');
Expand All @@ -113,7 +85,7 @@ describe('Publish step', () => {
try {
await prepare(pluginConfig, contexts.publishContext);

await fs.remove(path.join(wDir, 'assets'));
await fs.remove(path.join(releasePath, 'assets'));
await publish(pluginConfig, contexts.publishContext);
} catch (err) {
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);
Expand Down

0 comments on commit 67db9b0

Please # to comment.