Skip to content

Commit f68b4f8

Browse files
authored
Merge pull request #216 from semantic-release/feat/readme-path
Variable Readme path
2 parents 7395f6c + 9ea251e commit f68b4f8

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ end_of_line = lf
99
charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ If you have other variables which need to have the version replaced, you can add
7474

7575
If you need any further processing of the package files, next release version will be output to `/tmp/wp-release/VERSION` file, if the `withVersionFile` option is set to `true`.
7676

77-
> **Warning**
77+
> [!IMPORTANT]
7878
> Version in your plugin / theme must be set to 0.0.0 for this plugin to work
7979
8080
### Assets
8181
If your package is on [wp.org](https://wordpress.org) repository, you might have assets (screenshots, banners, logos) which you want to include in the assets file. Plugin respects the Codex, and expects those to be in ``.wordpress-org/assets`` folder. Main theme screenshot should be named ``screenshot`` and should be there as well.
8282

8383
### Readme
84-
readme.txt is a special Markdown file needed for packages on [wp.org](https://wordpress.org) to work. It needs to be in the `.wordpress-org` folder. Plugin will automatically replace the version in the file if the `withReadme` option is set to `true`.
84+
readme.txt is a special Markdown file needed for packages on [wp.org](https://wordpress.org) to work. It can be in the `.wordpress-org` folder, or in the repository root.
85+
Plugin will automatically replace the version in the file if the `withReadme` option is set to `true`.
8586

86-
> ** Warning**
87+
> [!WARNING]
8788
> Version in your readme.txt must also be set to 0.0.0 for this plugin to work
8889
8990
### Include / Exclude

lib/prepare.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export async function prepare(
3333
}
3434

3535
if (config.withReadme) {
36-
files.push('.wordpress-org/readme.txt');
36+
const readmePath = ['.wordpress-org/readme.txt', 'readme.txt'].reduce(
37+
(acc, p) => (fs.existsSync(path.join(workDir, p)) ? p : acc),
38+
undefined,
39+
);
40+
41+
readmePath && files.push(readmePath);
3742
}
3843

3944
errors.push(

test/2-prepare-plugin.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ describe('Package preparation - cusom work directory', () => {
108108
expect(readme).toMatch(/Stable tag: 1\.0\.0/);
109109
});
110110

111+
it('Should change the readme.txt version in the rootdir', async () => {
112+
await prepare(
113+
{
114+
type: 'plugin',
115+
slug: 'root-readme',
116+
path: './test/fixtures/root-readme',
117+
copyFiles: true,
118+
withReadme: true,
119+
releasePath,
120+
workDir,
121+
},
122+
contexts.prepareContext,
123+
);
124+
125+
const readme = fs.readFileSync(
126+
path.join(getWorkDir(workDir), 'root-readme/readme.txt'),
127+
'utf8',
128+
);
129+
130+
expect(readme).toMatch(/Stable tag: 1\.0\.0/);
131+
});
132+
111133
it('Should work with empty assets', async () => {
112134
await prepare(
113135
{

test/fixtures/root-readme/readme.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== Plugin with Readme ===
2+
Contributors: oblakstudio, seebeen
3+
Donate link: https://srbizasrbe.org
4+
Tags: serbia
5+
Requires at least: 5.6
6+
Tested up to: 6.1
7+
Requires PHP: 7.3
8+
Stable tag: 0.0.0
9+
License: GPLv2 or later
10+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
/**
3+
* Plugin Name: Plugin One
4+
* Version: 0.0.0
5+
*/

0 commit comments

Comments
 (0)