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

Unexpected token error when running s4u/[email protected] #293

Open
Ardesco opened this issue Jul 11, 2023 · 2 comments
Open

Unexpected token error when running s4u/[email protected] #293

Ardesco opened this issue Jul 11, 2023 · 2 comments

Comments

@Ardesco
Copy link

Ardesco commented Jul 11, 2023

Describe the bug

I'm getting an unexpected token error:

Run s4u/[email protected]
with:
servers: [{"id": "sonatype-nexus-snapshots", "username": "", "password": "", "privateKey": "", "passphrase": ""}]
sonatypeSnapshots: false
apacheSnapshots: false
override: true
githubServer: true
oracleRepo: false
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.19-7/x64
JAVA_HOME_11_X64: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.19-7/x64
Prepare maven setings: /home/runner/.m2/settings.xml
maven settings.xml already exists - override
Error: Unexpected token
in JSON at position 172

The config I have is:

      - name: Set up Sonatype Snapshots Repository
        uses: s4u/[email protected]
        with:
          servers: '[{"id": "sonatype-nexus-snapshots", "username": "${{ secrets.OSSRH_USERNAME }}", "password": "${{ secrets.OSSRH_TOKEN }}", "privateKey": "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}", "passphrase": "${{ secrets.MAVEN_GPG_PASSPHRASE }}"}]'

It looks like the position lines up with the ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} entry, but it;'s hard to work out why it's upset.

To Reproduce

Being reproduced on all my builds at the moment, but as I'm not sure of the exact cause I can't really provide repo instructions here.

Expected behaviour

My settings.xml setup should complete without issue.

Additional context

Could this be related to some characters in my GPG Private Key? Possible escaping issue maybe? I'm really looking for hints to help diagnose the problem.

@Ardesco
Copy link
Author

Ardesco commented Jul 11, 2023

OK I fixed it by passing in env variable instead of the secrets directly like this:

      - name: Set up Sonatype Snapshots Repository
        uses: s4u/[email protected]
        with:
          githubServer: false
          sonatypeSnapshots: true
          servers: |
            [{
              "id": "sonatype-nexus-snapshots", 
              "username": "${env.MAVEN_USERNAME}", 
              "password": "${env.MAVEN_PASSWORD}", 
              "privateKey": "${env.MAVEN_PRIVATE_KEY}", 
              "passphrase": "${env.MAVEN_PASSPHRASE}"
            }]

      - name: Publish to Sonatype Snapshots Repository
        run: mvn clean deploy -DskipTests
        env:
          MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
          MAVEN_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
          MAVEN_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

Not sure why that difference matters, may be worth adding that to the documentation

@slawekjaranowski
Copy link
Member

Probably your password contains a char which brake json parsing.

By the way providing sensitive data is better by environment variable it will not store in settings file.

PR with documentation improvement and examples are welcome 😄

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

No branches or pull requests

2 participants