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 ' in JSON at position 0 | Multiline client_payload #157

Closed
justmike1 opened this issue Jan 31, 2023 · 5 comments
Closed

Comments

@justmike1
Copy link

So I am trying to implement a multiline client_payload, my configuration:

  call-gke-cd:
    if: >
      ${{
      (startsWith(github.event.head_commit.message, '[PROD]:')) || 
      (github.ref != 'refs/heads/master')
      }}
    name: CD / Deploy to Kubernetes
    runs-on: ubuntu-22.04
    needs: [affected-services, build-and-push-docker]
    steps:
      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v2
        with:
          token: ${{ secrets.GIT_ACCESS_TOKEN }}
          repository: myorg/myrepo
          event-type: deploy
          client-payload: >
            '{"ref": "${{ github.ref }}", 
            "image_tag": "${{ needs.affected-services.outputs.project_version }}", 
            "services": "${{ needs.affected-services.outputs.matrix }}"}'

I get fails of Unexpected token ' in JSON at position 0

@peter-evans
Copy link
Owner

Hi @justmike1

This site might help you:
https://yaml-multiline.info/

You probably want >-, but I'm not sure.

          client-payload: >-
            '{"ref": "${{ github.ref }}", 
            "image_tag": "${{ needs.affected-services.outputs.project_version }}", 
            "services": "${{ needs.affected-services.outputs.matrix }}"}'

Or it might be complaining about the quotes. Try removing them.

          client-payload: >-
            {"ref": "${{ github.ref }}", 
            "image_tag": "${{ needs.affected-services.outputs.project_version }}", 
            "services": "${{ needs.affected-services.outputs.matrix }}"}

@baracudda
Copy link

The following works well for me:

    steps:
      - name: Trigger Container Build and Deploy
        uses: peter-evans/repository-dispatch@v2
        with:
          token: ${{ secrets.CI_WEBHOOK_TOKEN }}
          repository: mystuff/ci-docker
          event-type: build-repo
          client-payload: |-
            {
              "repo": {
                "name": "${{ github.repository }}",
                "branch": "${{ needs.build_cfg.outputs.REPO_BRANCH }}",
                "tag": "${{ needs.build_cfg.outputs.REPO_TAG }}"
              },
              "image": {
                "dockerfile": "Dockerfile",
                "name": "${{ github.repository }}",
                "tag": "${{ needs.build_cfg.outputs.VERSION_STR }}",
                "build_args": [
                  "VERSION=${{ needs.build_cfg.outputs.VERSION_STR }}"
                ]
              },
              "deployment": {
                "project": "${{ env.MY_PROJECT }}",
                "container": "${{ env.MY_CONTAINER }}",
                "deploy_msg": "${{ env.SLACK_DEPLOY_MSG }}",
              }
            }

@justmike1
Copy link
Author

cool, thanks!

@liamhelmer
Copy link

Could we add a multiline example to the docs? It took a while to find this...

@peter-evans
Copy link
Owner

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

4 participants