Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug theme when specify path #120

Closed
AntoninoBonanno opened this issue Oct 29, 2023 · 3 comments
Closed

Bug theme when specify path #120

AntoninoBonanno opened this issue Oct 29, 2023 · 3 comments

Comments

@AntoninoBonanno
Copy link
Contributor

AntoninoBonanno commented Oct 29, 2023

Current behavior

hi @seebeen,

I generate my theme files inside the dist folder and I want the version to be replaced in this folder and then proceed to create the .zip file.

image

So i use this configuration

[
    "@semantic-release/wordpress",
    {
        "type": "theme",
        "slug" : "my-theme",
        "withReadme": true,
        "copyFiles": false,
        "releasePath": "/tmp/wp-release",
        "path": "./dist/"
    }
],

the verification step is successful but when the version replacement is carried out I get an error.

I think the file is not found because in verify-theme.ts the path is concatenated with the slug

? path.resolve(config.path, config.slug)

however in prepare.ts the path is not concatenated with the slug

: path.resolve(path.resolve(config.path));

My style.css is correct

/*
Theme Name: My Theme
Theme URI: https://gitlab.com....
Author: Antonino Bonanno
Version: 0.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: my-theme
Text Domain: my-theme
Requires at least: 6.3
Tested up to: 6.3.0
Requires PHP: 8.1
*/

Expected behavior

The version is replaced and the zip is passed through a specific path

semantic-release version

22.0.5

CI environment

GitLab

Plugins used

"@semantic-release/wordpress": "^1.5.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^12.0.6",

semantic-release configuration

[
    "@semantic-release/wordpress",
    {
        "type": "theme",
        "slug" : "my-theme",
        "withReadme": true,
        "copyFiles": false,
        "releasePath": "/tmp/wp-release",
        "path": "./dist/"
    }
],

CI logs

[11:30:50 PM] [semantic-release] › ✘  EFILEINVALID File is invalid: style.css
The file is invalid: style.css.
AggregateError
    at prepare (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/prepare.js:28:15)
    at async validator (file:///builds//my-theme/theme/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
    at async file:///builds//my-theme/theme/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
    at async Promise.all (index 0)
    at async next (file:///builds//my-theme/theme/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
  [errors]: [
    SemanticReleaseError: File is invalid: style.css
        at getError (file:///builds//my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/get-error.js:5:12)
        at replaceVersions (file:///builds//my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/replace-versions.js:20:25)
        at async prepare (file:///builds//my-theme/theme/node_modules/@semantic-release/wordpress/dist/prepare.js:26:21)
        at async validator (file:///builds//my-theme/theme/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///builds//my-theme/theme/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
        at async Promise.all (index 0)
        at async next (file:///builds//my-theme/theme/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
      code: 'EFILEINVALID',
      details: 'The file is invalid: style.css.',
      semanticRelease: true,
      pluginName: '@semantic-release/wordpress'
    }
  ]
}
@AntoninoBonanno
Copy link
Contributor Author

In tests the paths are not consistent:

path: './test/fixtures',

path: './test/fixtures/complete-theme',

@seebeen
Copy link
Member

seebeen commented Oct 30, 2023

Good catch 💪

You are correct, there is an error with a double path resolve, but the path creation and concatenation is proper in this context. Meaning - it should and must work.

path is an undocumented setting added primarily to make testing procedures easier, and maybe to support some advanced workflows in the future. Glad to see your putting it to good use 😊

You can see here

path: './test/fixtures/theme-bad-version',

That the full path to the theme needs to be provided - so it's an error in the config.

Your config:

[
    "@semantic-release/wordpress",
    {
        "type": "theme",
        "slug" : "my-theme",
        "withReadme": true,
        "copyFiles": false,
        "releasePath": "/tmp/wp-release",
        "path": "./dist"
    }
],

Needs to be

[
    "@semantic-release/wordpress",
    {
        "type": "theme",
        "slug" : "my-theme",
        "withReadme": true,
        "copyFiles": false,
        "releasePath": "/tmp/wp-release",
        "path": "./dist/my-theme"
    }
],

And then it should work.

P.S. I corrected the error with the double path.resolve and improved the test case to demonstrate that custom path works

seebeen added a commit that referenced this issue Oct 30, 2023
@seebeen seebeen closed this as completed Oct 30, 2023
@AntoninoBonanno
Copy link
Contributor Author

AntoninoBonanno commented Oct 30, 2023

Hi @seebeen, thanks for the immediate response.
I did a test but with this configuration the file verification fails.

[
    "@semantic-release/wordpress",
    {
        "type": "theme",
        "slug" : "my-theme",
        "withReadme": true,
        "copyFiles": false,
        "releasePath": "/tmp/wp-release",
        "path": "./dist/my-theme"
    }
],

i think because inside verify-theme.ts concat path with slug.

? path.resolve(config.path, config.slug)

So the path in verify state is "./dist/my-theme/my-theme" and in prepare state is "./dist/my-theme"

In my case the correct path is "./dist/my-theme".

[5:13:15 PM] [semantic-release] › ✘  ETHEMEFILENOTFOUND Your theme must contain these files: style.css, functions.php
Check if the files exist, and if not create them: style.css, functions.php.
AggregateError: 
    SemanticReleaseError: Your theme must contain these files: style.css, functions.php
        at getError (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/get-error.js:5:12)
        at verifyTheme (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/verify-theme.js:13:13)
        at async verifyConditions (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/verify-conditions.js:12:17)
        at async validator (file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
        at async Promise.all (index 0)
        at async next (file:///builds/my-theme/theme/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44)
    at file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/pipeline.js:55:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async pluginsConfigAccumulator.<computed> [as verifyConditions] (file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/index.js:87:11)
    at async run (file:///builds/my-theme/theme/node_modules/semantic-release/index.js:106:3)
    at async Module.default (file:///builds/my-theme/theme/node_modules/semantic-release/index.js:275:22)
    at async default (file:///builds/my-theme/theme/node_modules/semantic-release/cli.js:55:5) {
  errors: [
    SemanticReleaseError: Your theme must contain these files: style.css, functions.php
        at getError (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/get-error.js:5:12)
        at verifyTheme (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/utils/verify-theme.js:13:13)
        at async verifyConditions (file:///builds/my-theme/theme/node_modules/@semantic-release/wordpress/dist/verify-conditions.js:12:17)
        at async validator (file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///builds/my-theme/theme/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
        at async Promise.all (index 0)
        at async next (file:///builds/my-theme/theme/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
      code: 'ETHEMEFILENOTFOUND',
      details: 'Check if the files exist, and if not create them: style.css, functions.php.',
      semanticRelease: true,
      pluginName: '@semantic-release/wordpress'
    }
  ]

For test this user case, the prepare.specs.ts and verify-theme.spec.ts must have the same options

{
      type: 'theme',
      slug: 'complete-theme',
      path: './test/fixtures/complete-theme',
      copyFiles: false,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants