[GH-ISSUE #1317] toJSON(github) fails in run: but works in env: #712

Closed
opened 2026-03-01 21:45:44 +03:00 by kerem · 3 comments
Owner

Originally created by @kanaka on GitHub (Aug 25, 2022).
Original GitHub issue: https://github.com/nektos/act/issues/1317

Bug report info

act version:            0.2.30-5-gb23bbef-dirty
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is unset/empty.
Sockets found:
        /var/run/docker.sock
Config files:           
        /home/jmartin/.actrc:
                -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
                -P ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04
                -P ubuntu-18.04=ghcr.io/catthehacker/ubuntu:act-18.04
Build info:
        Go version:            go1.18.1
        Module path:           command-line-arguments
        Main version:          
        Main path:             
        Main checksum:         
        Build settings:
                -compiler:            gc
                -ldflags:             -X main.version=0.2.30-5-gb23bbef-dirty
                CGO_ENABLED:          1
                CGO_CFLAGS:           
                CGO_CPPFLAGS:         
                CGO_CXXFLAGS:         
                CGO_LDFLAGS:          
                GOARCH:               amd64
                GOOS:                 linux
                GOAMD64:              v1
Docker Engine:
        Engine version:        20.10.7
        Engine runtime:        runc
        Cgroup version:        1
        Cgroup driver:         cgroupfs
        Storage driver:        overlay2
        Registry URI:          https://index.docker.io/v1/
        OS:                    NixOS 20.09 (Nightingale)
        OS type:               linux
        OS version:            20.09.4407.1c1f5649bb9
        OS arch:               x86_64
        OS kernel:             5.4.122
        OS CPU:                8
        OS memory:             63530 MB
        Security options:
                name=seccomp,profile=default

Command used with act

act -P self-hosted=ubuntu:latest -j basic

Describe issue

The use of ${{ toJSON(github) }} works in an env: section but not in a run: definition. Other contexts (job, steps, runner, etc) work in both places. It seems according to https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log that the github context should work in a run block too.

No response

Workflow content

name: Push (build and local tests)

on:
  push: {}

jobs:
  basic:
    runs-on: [ self-hosted ]
    steps:
      - name: Store context in variable
        env:
          GITHUB_CONTEXT: ${{ toJSON(github) }}
        run: |
          echo "Full github context: ${GITHUB_CONTEXT}"

      - name: Show github context directly
        run: | 
          echo "github.actor: ${{ github.actor }}"
          echo "Full github context: ${{ toJSON(github) }})"

Relevant log output

| github.actor: nektos/act
| /var/run/act/workflow/1: line 10: syntax error near unexpected token `('

Additional information

No response

Originally created by @kanaka on GitHub (Aug 25, 2022). Original GitHub issue: https://github.com/nektos/act/issues/1317 ### Bug report info ```plain text act version: 0.2.30-5-gb23bbef-dirty GOOS: linux GOARCH: amd64 NumCPU: 8 Docker host: DOCKER_HOST environment variable is unset/empty. Sockets found: /var/run/docker.sock Config files: /home/jmartin/.actrc: -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest -P ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04 -P ubuntu-18.04=ghcr.io/catthehacker/ubuntu:act-18.04 Build info: Go version: go1.18.1 Module path: command-line-arguments Main version: Main path: Main checksum: Build settings: -compiler: gc -ldflags: -X main.version=0.2.30-5-gb23bbef-dirty CGO_ENABLED: 1 CGO_CFLAGS: CGO_CPPFLAGS: CGO_CXXFLAGS: CGO_LDFLAGS: GOARCH: amd64 GOOS: linux GOAMD64: v1 Docker Engine: Engine version: 20.10.7 Engine runtime: runc Cgroup version: 1 Cgroup driver: cgroupfs Storage driver: overlay2 Registry URI: https://index.docker.io/v1/ OS: NixOS 20.09 (Nightingale) OS type: linux OS version: 20.09.4407.1c1f5649bb9 OS arch: x86_64 OS kernel: 5.4.122 OS CPU: 8 OS memory: 63530 MB Security options: name=seccomp,profile=default ``` ### Command used with act ```sh act -P self-hosted=ubuntu:latest -j basic ``` ### Describe issue The use of `${{ toJSON(github) }}` works in an `env:` section but not in a `run:` definition. Other contexts (job, steps, runner, etc) work in both places. It seems according to https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log that the github context should work in a `run` block too. ### Link to GitHub repository _No response_ ### Workflow content ```yml name: Push (build and local tests) on: push: {} jobs: basic: runs-on: [ self-hosted ] steps: - name: Store context in variable env: GITHUB_CONTEXT: ${{ toJSON(github) }} run: | echo "Full github context: ${GITHUB_CONTEXT}" - name: Show github context directly run: | echo "github.actor: ${{ github.actor }}" echo "Full github context: ${{ toJSON(github) }})" ``` ### Relevant log output ```sh | github.actor: nektos/act | /var/run/act/workflow/1: line 10: syntax error near unexpected token `(' ``` ### Additional information _No response_
kerem 2026-03-01 21:45:44 +03:00
Author
Owner

@ChristopherHX commented on GitHub (Aug 25, 2022):

I removed the bug label, because this works as designed like actions/runner.

Both json and and your echo statement use " quotes, this allows script injection and causes a bash syntax error.

If you use single quotes, you can echo more json objects unless they contain ' quotes. All json objects contains " quotes.

     - name: Show github context directly
        run: | 
          echo 'github.actor: ${{ github.actor }}'
          echo 'Full github context: ${{ toJSON(github) }})'
<!-- gh-comment-id:1227721336 --> @ChristopherHX commented on GitHub (Aug 25, 2022): I removed the bug label, because this works as designed like actions/runner. Both json and and your echo statement use `"` quotes, this allows script injection and causes a bash syntax error. If you use single quotes, you can echo more json objects unless they contain `'` quotes. All json objects contains `"` quotes. ```yaml - name: Show github context directly run: | echo 'github.actor: ${{ github.actor }}' echo 'Full github context: ${{ toJSON(github) }})' ```
Author
Owner

@kanaka commented on GitHub (Aug 25, 2022):

Interesting, this must have been changed in github enterprise 3.6. Thanks for following up.

<!-- gh-comment-id:1227851608 --> @kanaka commented on GitHub (Aug 25, 2022): Interesting, this must have been changed in github enterprise 3.6. Thanks for following up.
Author
Owner

@ChristopherHX commented on GitHub (Aug 26, 2022):

this must have been changed in github enterprise 3.6

No, nothing changed in this area since 2019 depending on the content of the github event it partially works.

I guess this modified workflow works, but the " are gone.

name: Push build and local tests

on:
  push: {}

jobs:
  basic:
    runs-on: [ self-hosted ]
    steps:
      - name: Store context in variable
        env:
          GITHUB_CONTEXT: ${{ toJSON(github) }}
        run: |
          echo "Full github context: ${GITHUB_CONTEXT}"

      - name: Show github context directly
        run: | 
          echo "github.actor: ${{ github.actor }}"
          echo "Full github context: ${{ toJSON(github) }})"

In azure devops some people come to the conclusion converttojson outputs invalid json, due to script injection and missing quotes.

<!-- gh-comment-id:1228774178 --> @ChristopherHX commented on GitHub (Aug 26, 2022): > this must have been changed in github enterprise 3.6 No, nothing changed in this area since 2019 depending on the content of the github event it partially works. I guess this modified workflow works, but the `"` are gone. ```yaml name: Push build and local tests on: push: {} jobs: basic: runs-on: [ self-hosted ] steps: - name: Store context in variable env: GITHUB_CONTEXT: ${{ toJSON(github) }} run: | echo "Full github context: ${GITHUB_CONTEXT}" - name: Show github context directly run: | echo "github.actor: ${{ github.actor }}" echo "Full github context: ${{ toJSON(github) }})" ``` In azure devops some people come to the conclusion converttojson outputs invalid json, due to script injection and missing quotes.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#712
No description provided.