Skip to content

Commit

Permalink
Merge pull request #241 from semantic-release/fix/globs
Browse files Browse the repository at this point in the history
fix: Fixed nested globbing
  • Loading branch information
seebeen authored Sep 18, 2024
2 parents 1f2e079 + 3e7ebf1 commit 63fb045
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 15 deletions.
7 changes: 6 additions & 1 deletion lib/utils/copy-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export async function copyAssets(
const basePath = path.resolve(path.join(workDir, '.wordpress-org', 'assets'));

const assets = await glob(
['screenshot*', 'banner-*'].map((g) => `${g}.{jpg,png,gif,jpeg}`),
[
...['icon-*', 'screenshot*', 'banner-*'].map(
(g) => `${g}.{jpg,png,gif,jpeg}`,
),
'blueprints/**.json',
],
{
cwd: basePath,
},
Expand Down
12 changes: 8 additions & 4 deletions lib/utils/copy-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export function getInclude(workDir: string, files?: string[]): string[] {
...new Set(getFileArray(workDir, '.distinclude') ?? files ?? []),
];

return include.length !== 0 ? include : ['**/*'];
return include.length > 0
? include
.filter((p) => p.includes('*') || fs.existsSync(path.join(workDir, p)))
.map((p) => remapGlobs(workDir, p))
: ['**'];
}

/**
Expand All @@ -51,8 +55,7 @@ export function getIgnore(workDir: string, files?: string[]): string[] {
.filter(
(ignorePath) =>
ignorePath.includes('*') ||
(!ignorePath.includes('*') &&
fs.existsSync(path.join(workDir, ignorePath))),
fs.existsSync(path.join(workDir, ignorePath)),
)
.map((ignorePath) => remapGlobs(workDir, ignorePath));
}
Expand All @@ -67,7 +70,8 @@ export async function copyFiles(
const files = await glob(getInclude(workDir, config.include), {
cwd: workDir,
ignore: getIgnore(workDir, config.exclude),
// maxDepth: 1,
nodir: true,
mark: true,
});

await fs.mkdir(releasePath, { recursive: true });
Expand Down
43 changes: 39 additions & 4 deletions test/0-corner-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,51 @@ describe('Corner cases affecting releases', () => {
const ignore1 = DEFAULT_EXCLUDES;
const include2 = getInclude(workDir, ['dist-test.php']);
const ignore2 = getIgnore(workDir);
const expected = ['dist-test.php', 'test1.php', 'vendor'].sort();
const expected = [
'dist-test.php',
'test1.php',
'vendor/composer.php',
].sort();

expect(include1.sort()).toEqual(['dist-test.php', 'test1.php', 'vendor']);
expect(include1.sort()).toEqual([
'dist-test.php',
'test1.php',
'vendor/**',
]);
expect(
(
await glob(include1, { cwd: workDir, ignore: ignore1, maxDepth: 1 })
await glob(include1, {
cwd: workDir,
ignore: ignore1,
nodir: true,
mark: true,
})
).sort(),
).toEqual(expected);
expect(
(await glob(include2, { cwd: workDir, ignore: ignore2 })).sort(),
(
await glob(include2, {
cwd: workDir,
ignore: ignore2,
nodir: true,
mark: true,
})
).sort(),
).toEqual(['dist-test.php']);
});

it('Should glob properly with nesting', async () => {
const workDir = path.resolve('./test/fixtures/nested-exclude');

expect(
(
await glob(getInclude(workDir), {
cwd: workDir,
ignore: getIgnore(workDir),
nodir: true,
mark: true,
})
).sort(),
).toEqual(['assets/need-this.js', 'file.php']);
});
});
3 changes: 2 additions & 1 deletion test/2-prepare-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ describe('Package preparation - default work directory', () => {

const assets = fs.readdirSync(path.join(releasePath, 'assets'));

expect(assets).toHaveLength(4);
expect(assets).toHaveLength(5);
expect(assets.sort()).toStrictEqual(
[
'blueprints',
'banner-low.jpg',
'banner-high.jpg',
'screenshot-1.jpg',
Expand Down
9 changes: 4 additions & 5 deletions test/2-prepare-theme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ beforeEach(() => {
afterEach(async () => {
fs.rmSync('/tmp/workDir', { recursive: true, force: true });
fs.rmSync('/tmp/wp-release', { recursive: true, force: true });
fs.rmSync('./test/fixtures/complete-theme-copy', {
recursive: true,
force: true,
});
});

it('Should fail on a badly versioned theme', async () => {
Expand Down Expand Up @@ -131,9 +135,4 @@ it('Should fully prepare a theme for release', async () => {
);
expect(versions).toMatch(/1\.0\.0/);
expect(versions).toMatch(/3\.2\.111/);

await fs.rm('./test/fixtures/complete-theme-copy', {
recursive: true,
force: true,
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"landingPage": "/wp-admin/index.php",
"preferredVersions": {
"php": "8.0",
"wp": "6.4"
},
"phpExtensionBundles": ["kitchen-sink"],
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "setSiteOptions",
"options": {
"WPLANG": "sr_RS",
"wcsrb_settings_general": "a:3:{s:22:\"enabled_customer_types\";s:4:\"both\";s:22:\"remove_unneeded_fields\";s:3:\"yes\";s:19:\"fix_currency_symbol\";s:3:\"yes\";}",
"woocommerce_store_name": "Oblak Solutions DOO",
"woocommerce_store_address": "Pozeska",
"woocommerce_store_city": "Beograd",
"woocommerce_store_postcode": "11000",
"woocommerce_default_country": "RS:RS00",
"woocommerce_store_bank_accounts": {
"acct": ["160-428634-06"]
},
"woocommerce_currency": "RSD",
"woocommerce_currency_pos": "right_space",
"woocommerce_wcsrb_payment_slip_settings": {
"enabled": "yes",
"title": "Op\u0161ta uplatnica",
"description": "Platite narud\u017ebinu op\u0161tom uplatnicom",
"basic": "",
"style": "modern",
"bank_account": "160-428634-06",
"payment_code": "auto",
"payment_model": "mod97",
"payment_reference": "%mod97%-%order_id%-%year%",
"payment_purpose": "Pla\u0107anje narud\u017ebine",
"qrcode": "",
"qrcode_shown": "yes",
"qrcode_color": "#000000",
"qrcode_corner_color": "#0e77c0",
"qrcode_image": "no",
"advanced": "",
"debug": "no"
}
}
},
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "woocommerce"
},
"options": {
"activate": true
}
},
{
"step": "runPHP",
"code": "<?php\ninclude 'wordpress/wp-load.php';\ndelete_transient('_wc_activation_redirect');"
}
]
}
3 changes: 3 additions & 0 deletions test/fixtures/nested-exclude/.distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
assets/src/**/*.*
assets/ignore-this.js
example.js
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 63fb045

Please sign in to comment.