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

settingsPath is not getting expanded by the shell #37

Closed
jebeaudet opened this issue May 16, 2024 · 7 comments
Closed

settingsPath is not getting expanded by the shell #37

jebeaudet opened this issue May 16, 2024 · 7 comments

Comments

@jebeaudet
Copy link

Hi!

I'm trying to use your plugin in a standalone way, this is my .releaserc.json file :

{
  "branches": ["main"],
  "plugins": [
    [
      "@semantic-release/commit-analyzer",
      {
        "preset": "conventionalcommits"
      }
    ],
    ["@terrestris/maven-semantic-release",
      {
        "settingsPath": " "
      }
    ],
    [
      "@semantic-release/git",
      {
          "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
          "assets": ["CHANGELOG.md"]
      }
    ]
  ]
}

Running with GH_TOKEN=XXX npx semantic-release --no-ci leads to the following error (irrelevant parts omitted):

Error log
[10:49:20 a.m.] [semantic-release] [@terrestris/maven-semantic-release] › ℹ  Updating pom.xml to version 1.0.0
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /Users/jebeaudet/Projects/organizationservice/~/.m2/settings.xml
[10:49:21 a.m.] [semantic-release] › ✘  Failed step "prepare" of plugin "@terrestris/maven-semantic-release"
[10:49:21 a.m.] [semantic-release] › ✘  An error occurred while running semantic-release: Error: Command failed with exit code 1: mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /Users/jebeaudet/Projects/organizationservice/~/.m2/settings.xml
  at makeError (/Users/jebeaudet/Projects/organizationservice/node_modules/execa/lib/error.js:60:11)
  at handlePromise (/Users/jebeaudet/Projects/organizationservice/node_modules/execa/index.js:118:26)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async updateVersion (/Users/jebeaudet/Projects/organizationservice/node_modules/@terrestris/maven-semantic-release/src/maven.js:23:5)
  at async prepare (/Users/jebeaudet/Projects/organizationservice/node_modules/@terrestris/maven-semantic-release/src/prepare.js:26:5)
  at async validator (file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
  at async file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
  at async Promise.all (index 0)
  at async next (file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
shortMessage: 'Command failed with exit code 1: mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0',
command: 'mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0',
escapedCommand: 'mvn "versions:set" --batch-mode --no-transfer-progress "-DgenerateBackupPoms=false" --settings "~/.m2/settings.xml" "-DnewVersion=1.0.0"',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: '[ERROR] Error executing Maven.\n' +
  '[ERROR] The specified user settings file does not exist: /Users/jebeaudet/Projects/organizationservice/~/.m2/settings.xml',
stderr: '',
failed: true,
timedOut: false,
isCanceled: false,
killed: false,
pluginName: '@terrestris/maven-semantic-release'
}
Error: Command failed with exit code 1: mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: /Users/jebeaudet/Projects/organizationservice/~/.m2/settings.xml
  at makeError (/Users/jebeaudet/Projects/organizationservice/node_modules/execa/lib/error.js:60:11)
  at handlePromise (/Users/jebeaudet/Projects/organizationservice/node_modules/execa/index.js:118:26)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async updateVersion (/Users/jebeaudet/Projects/organizationservice/node_modules/@terrestris/maven-semantic-release/src/maven.js:23:5)
  at async prepare (/Users/jebeaudet/Projects/organizationservice/node_modules/@terrestris/maven-semantic-release/src/prepare.js:26:5)
  at async validator (file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
  at async file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
  at async Promise.all (index 0)
  at async next (file:///Users/jebeaudet/Projects/organizationservice/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
shortMessage: 'Command failed with exit code 1: mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0',
command: 'mvn versions:set --batch-mode --no-transfer-progress -DgenerateBackupPoms=false --settings ~/.m2/settings.xml -DnewVersion=1.0.0',
escapedCommand: 'mvn "versions:set" --batch-mode --no-transfer-progress "-DgenerateBackupPoms=false" --settings "~/.m2/settings.xml" "-DnewVersion=1.0.0"',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: '[ERROR] Error executing Maven.\n' +
  '[ERROR] The specified user settings file does not exist: /Users/jebeaudet/Projects/organizationservice/~/.m2/settings.xml',
stderr: '',
failed: true,
timedOut: false,
isCanceled: false,
killed: false,
pluginName: '@terrestris/maven-semantic-release'

So, somehow, it does not expand ~ to my home directory and just append it to the current directory. Looking at the escaped command mvn "versions:set" --batch-mode --no-transfer-progress "-DgenerateBackupPoms=false" --settings "~/.m2/settings.xml" "-DnewVersion=1.0.0", if I run the same thing in my terminal I get the same error, it seems like enclosing it in double quotes is not the way to go.

The only way I can make it work is with a fully qualified path for now which is not an option for CI.

Any ideas? Thanks!

@simonseyock
Copy link
Member

Sorry for the late response.

This seems to be a windows problem. I think on windows the ~ in the default has no meaning. If you use WSL it should work I think.

A way to work around this would be to check in the local path for local development, but do not commit this to the repo.

@jebeaudet
Copy link
Author

Hi,

I'm on macOS and we had the same error on our CI setup, which is running on ubuntu 22.04!

Thanks

@simonseyock
Copy link
Member

I did a little digging. We are using the execa library to run the commands. I think, in general we cannot rely on the ~ character being expanded to the home directory. For example on Windows the ~ does not have a meaning.

See also this discussion in the nodejs repository itself: nodejs/node#684

I would follow these arguments and not do an expansion of the ~ in the plugin.

I think you would need to override the settingsPath with the correct value for different environments. You can do that in the configuration (inside package.json or in releaserc files).

You can write the configuration as an javascript file that exports the correct plugin configuration and determine the settingsPath for example by an environment variable.

See: https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file

I hope that helps and you can achieve your desired workflow!

@simonseyock
Copy link
Member

If the default of the settingsPath in general does not work (even on linux), I would remove it entirely and only set the settingsPath if it was provided by the user.

@simonseyock
Copy link
Member

Maybe that actually would solve your problem because maven already knows where the default file should exist.

@jebeaudet
Copy link
Author

Hi

This is what we ended up doing, in a step before semantic-release, we copy the file from the home directory (GHA example) :

- name: Copy Maven settings
   shell: bash
   run: cp ~/.m2/settings.xml ./maven_settings.xml

to the current directory and specify the location like this in the .releaserc.json :

    ["@terrestris/maven-semantic-release",
      {
        "settingsPath": "maven_settings.xml"
      }
    ],

I'd suggest some documentation on the plugin readme would go a long way if you don't want to support the ~ with workaround mentioned in the thread.

Thanks again

@mymasse
Copy link

mymasse commented Jul 9, 2024

I agree with @simonseyock I would set settingsPath only if provided from the user, Maven should look at default locations for the file if not provided. Then the workaround provided above to copy the file is not required at all.

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

3 participants