actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.89k stars 959 forks source link

`toJSON` should tolerate properties that are only sometimes available instead of throwing a fatal `Unrecognized named-value` #2198

Open jsoref opened 2 years ago

jsoref commented 2 years ago

Describe the bug Actions need to be able to access contexts and be run regardless of which event a user chooses to use the action.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/jsoref/community-events/actions/runs/3233269851

Annotations

8 errors

debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17):

debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17): Unrecognized named-value: 'jobs'. Located at position 8 within expression: toJSON(jobs || '')Show more debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): Unrecognized named-value: 'secrets'. Located at position 8 within expression: toJSON(secrets || '')Show more debugjsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): Unrecognized named-value: 'needs'. Located at position 8 within expression: toJSON(needs || '')Show more debugGitHub.DistributedTask.ObjectTemplating.TemplateValidationException: The template is not valid. jsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17): Unrecognized named-value: 'jobs'. Located at position 8 within expression: toJSON(jobs || ''),jsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): Unrecognized named-value: 'secrets'. Located at position 8 within expression: toJSON(secrets || ''),jsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): Unrecognized named-value: 'needs'. Located at position 8 within expression: toJSON(needs || '') at GitHub.DistributedTask.ObjectTemplating.TemplateValidationErrors.Check() at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs) at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)Show more debugFail to load jsoref/community-events-action/a/b/c/d/action.yml

Annotations 8 errors debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17): debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17): Unrecognized named-value: 'jobs'. Located at position 8 within expression: toJSON(jobs || '') debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): Unrecognized named-value: 'secrets'. Located at position 8 within expression: toJSON(secrets || '') debug jsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): Unrecognized named-value: 'needs'. Located at position 8 within expression: toJSON(needs || '') debug GitHub.DistributedTask.ObjectTemplating.TemplateValidationException: The template is not valid. jsoref/community-events-action/a/b/c/d/action.yml (Line: 13, Col: 17): Unrecognized named-value: 'jobs'. Located at position 8 within expression: toJSON(jobs || ''),jsoref/community-events-action/a/b/c/d/action.yml (Line: 14, Col: 20): Unrecognized named-value: 'secrets'. Located at position 8 within expression: toJSON(secrets || ''),jsoref/community-events-action/a/b/c/d/action.yml (Line: 18, Col: 18): Unrecognized named-value: 'needs'. Located at position 8 within expression: toJSON(needs || '') at GitHub.DistributedTask.ObjectTemplating.TemplateValidationErrors.Check() at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs) at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile) debug Fail to load jsoref/community-events-action/a/b/c/d/action.yml

Expected behavior Offer a way to provide a fallback value, e.g. toJSON(x || '')

Runner Version and Platform

Version of your runner? 2.298.2

OS of the machine running the runner? Linux

What's not working?

Job Log Output

If applicable, include the relevant part of the job / step log output here. All sensitive information should already be masked out, but please double-check before pasting here.

Runner and Worker's Diagnostic Logs

If applicable, add relevant diagnostic log information. Logs are located in the runner's _diag folder. The runner logs are prefixed with Runner_ and the worker logs are prefixed with Worker_. Each job run correlates to a worker log. All sensitive information should already be masked out, but please double-check before pasting here.

name: Debug GHA
on:
  branch_protection_rule:
  check_run:
  check_suite:
  create:
  delete:
  deployment:
  deployment_status:
  discussion:
  discussion_comment:
  fork:
  gollum:
  issue_comment:
  issues:
  label:
  member:
  milestone:
  page_build:
  project:
  project_card:
  project_column:
  public:
  pull_request:
  pull_request_review:
  pull_request_review_comment:
  push:
  release:
  repository_dispatch:
  status:
  watch:
  workflow_dispatch:
  workflow_run:
    workflows: [Test]

jobs:
  debug:
    runs-on: ubuntu-latest
    steps:
    - name: set up
      run: |
          echo github.action: ${{github.action}};
          echo github.action_path: ${{github.action_path}};
          echo github.action_ref: ${{github.action_ref}};
          echo github.action_repository: ${{github.action_repository}};
          echo github.actor: ${{github.actor}};
          echo github.api_url: ${{github.api_url}};
          echo github.base_ref: ${{github.base_ref}};
          echo github.env: ${{github.env}};
          echo github.event: ${{github.event}};
          echo github.event_name: ${{github.event_name}};
          echo github.event_path: ${{github.event_path}};
          echo github.graphql_url: ${{github.graphql_url}};
          echo github.head_ref: ${{github.head_ref}};
          echo github.job: ${{github.job}};
          echo github.ref: ${{github.ref}};
          echo github.ref_name: ${{github.ref_name}};
          echo github.ref_protected: ${{github.ref_protected}};
          echo github.ref_type: ${{github.ref_type}};
          echo github.path: ${{github.path}};
          echo github.repository: ${{github.repository}};
          echo github.repository_owner: ${{github.repository_owner}};
          echo github.repositoryUrl: ${{github.repositoryUrl}};
          echo github.retention_days: ${{github.retention_days}};
          echo github.run_id: ${{github.run_id}};
          echo github.run_number: ${{github.run_number}};
          echo github.run_attempt: ${{github.run_attempt}};
          echo github.server_url: ${{github.server_url}};
          echo github.sha: ${{github.sha}};
          echo github.token: ${{github.token}};
          echo github.workflow: ${{github.workflow}};
          echo github.workspace: ${{github.workspace}};
          echo env:;
          env
    - name: debug
      uses: jsoref/community-events-action@a/b/c/d
name: 'Debug'
description: 'Debug'
runs:
  using: composite
  steps:
    - id: debug
      name: debug
      shell: bash
      env:
        x_env: ${{ toJSON(env || '') }}
        x_github: ${{ toJSON(github || '') }}
        x_job: ${{ toJSON(job || '') }}
        x_jobs: ${{ toJSON(jobs || '') }}
        x_secrets: ${{ toJSON(secrets || '') }}
        x_steps: ${{ toJSON(steps || '') }}
        x_runner: ${{ toJSON(runner || '') }}
        x_matrix: ${{ toJSON(matrix || '') }}
        x_needs: ${{ toJSON(needs || '') }}
        x_inputs: ${{ toJSON(inputs || '') }}
      run: |
        echo action-env
        env
        echo
        echo 'objects...'

        cat <<<'EOF'
        github:
        ${{ toJSON(github) }}"

        env:
        ${{ toJSON(env) }}"

        job:
        ${{ toJSON(job) }}"

        jobs:
        {{ toJSON(jobs) }}"

        steps:
        ${{ toJSON(steps) }}"

        runner:
        ${{ toJSON(runner) }}"

        secrets:
        {{ toJSON(secrets) }}"

        strategy:
        ${{ toJSON(strategy) }}"

        matrix:
        ${{ toJSON(matrix) }}"

        needs:
        {{ toJSON(needs) }}"

        inputs:
        ${{ toJSON(inputs) }}"
        EOF
nikola-jokic commented 2 years ago

Hey @jsoref,

Thanks for submitting this! I will mark this as a runner feature and add it to the board :relaxed:

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 15 days.

jsoref commented 1 year ago

@nikola-jokic ?