Search code examples
yamlcontinuous-integrationgithub-actionscustom-action

Error on Custom Action use (Unexpected type '' encountered while reading 'action manifest root'. The type 'MappingToken' was expected.)


<project-dir-name>/
├── .github/
│   ├── actions/
│   │   └── cached-deps/
│   │       ├── action.yml
└── .github/
    └── workflows/
        └── main.yml

Here is the custom action for dependencies getting and caching (action.yml):

name: "Get & cache dependencies"
description: "Get the dependencies and cache them."
runs:
  using: "composite"
  steps:
    - name: "Cache dependencies"
      id: cache
      uses: "actions/cache@v3"
      with:
        path: node_modules
        key: deps-node-modules-${{ hashFiles('**/package-lock.json') }}
    - name: Install Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: npm ci
        shell: bash

Here is the simple workflow where custom action should be used (main.yml):

name: Deploy
on:
  push:
    branches:
      - master
jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Get code
        uses: actions/checkout@v3

      - name: Load & cache dependencies
        uses: ./.github/actions/cached-deps

      - name: Run linters
        run: |
          npm run lint
          npm run lint-next
Error: /home/runner/work/<project-dir-name>/<project-dir-name>/./.github/actions/cached-deps/action.yml: (Line: 13, Col: 11, Idx: 355) - (Line: 13, Col: 11, Idx: 355): Mapping values are not allowed in this context.
Error: System.ArgumentException: Unexpected type '' encountered while reading 'action manifest root'. The type 'MappingToken' was expected.
   at GitHub.DistributedTask.ObjectTemplating.Tokens.TemplateTokenExtensions.AssertMapping(TemplateToken value, String objectDescription)
   at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)
Error: Failed to load /home/runner/work/<project-dir-name>/<project-dir-name>/./.github/actions/cached-deps/action.yml

Solution

  • As mentioned in the question comments by @GuiFalourd, the issue was because the if, run, and shell fields were not 2 spaces on the left.