Skip to content

Commit

Permalink
Merge pull request #216 from semantic-release/feat/readme-path
Browse files Browse the repository at this point in the history
Variable Readme path
  • Loading branch information
seebeen authored Jan 19, 2024
2 parents 7395f6c + 9ea251e commit f68b4f8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ If you have other variables which need to have the version replaced, you can add

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`.

> **Warning**
> [!IMPORTANT]
> Version in your plugin / theme must be set to 0.0.0 for this plugin to work
### Assets
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.

### Readme
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`.
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.
Plugin will automatically replace the version in the file if the `withReadme` option is set to `true`.

> ** Warning**
> [!WARNING]
> Version in your readme.txt must also be set to 0.0.0 for this plugin to work
### Include / Exclude
Expand Down
7 changes: 6 additions & 1 deletion lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export async function prepare(
}

if (config.withReadme) {
files.push('.wordpress-org/readme.txt');
const readmePath = ['.wordpress-org/readme.txt', 'readme.txt'].reduce(
(acc, p) => (fs.existsSync(path.join(workDir, p)) ? p : acc),
undefined,
);

readmePath && files.push(readmePath);
}

errors.push(
Expand Down
22 changes: 22 additions & 0 deletions test/2-prepare-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ describe('Package preparation - cusom work directory', () => {
expect(readme).toMatch(/Stable tag: 1\.0\.0/);
});

it('Should change the readme.txt version in the rootdir', async () => {
await prepare(
{
type: 'plugin',
slug: 'root-readme',
path: './test/fixtures/root-readme',
copyFiles: true,
withReadme: true,
releasePath,
workDir,
},
contexts.prepareContext,
);

const readme = fs.readFileSync(
path.join(getWorkDir(workDir), 'root-readme/readme.txt'),
'utf8',
);

expect(readme).toMatch(/Stable tag: 1\.0\.0/);
});

it('Should work with empty assets', async () => {
await prepare(
{
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/root-readme/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Plugin with Readme ===
Contributors: oblakstudio, seebeen
Donate link: https://srbizasrbe.org
Tags: serbia
Requires at least: 5.6
Tested up to: 6.1
Requires PHP: 7.3
Stable tag: 0.0.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
5 changes: 5 additions & 0 deletions test/fixtures/root-readme/root-readme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/**
* Plugin Name: Plugin One
* Version: 0.0.0
*/

0 comments on commit f68b4f8

Please sign in to comment.