Alexander Mills
Alexander Mills

Reputation: 100010

YAML syntax issue

I am new to YAML, only know JSON and XML formats

I have this .yml configuration for TravisCI and it has a some weird syntax error and I cannot figure out how to fix it.

Originally I had this, and everything was fine:

language: node_js
node_js:
  - '7'
  - '6'
  - '5'
  - '4'
script: 'npm install istanbul && node cli.js --coverage test/testsrc/es5-es6/a.js'
after_script: 'npm install coveralls && cat coverage/lcov.info | ./node_modules/.bin/coveralls'
notifications:
  email: false
  slack:
    rooms:
      - sumanjs:gvauyHhXXXXXpV5v8LlQOAcI#general

But I read that we need to get some C++ libraries available in the container, so I had to add some some stuff to the .yml file according to these instructions:

https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements

So now I have this, which is invalid, but I have no idea why:

language: node_js
node_js:
  - '7':
   env:
      - CXX=g++-4.8
    addons:
      apt:
        sources:
          - ubuntu-toolchain-r-test
        packages:
          - g++-4.8
  - '6':
   env:
      - CXX=g++-4.8
    addons:
      apt:
        sources:
          - ubuntu-toolchain-r-test
        packages:
          - g++-4.8
  - '5':
  env:
    - CXX=g++-4.8
  addons:
    apt:
      sources:
        - ubuntu-toolchain-r-test
      packages:
        - g++-4.8
  - '4':
  env:
    - CXX=g++-4.8
  addons:
    apt:
      sources:
        - ubuntu-toolchain-r-test
      packages:
        - g++-4.8
script: 'npm install istanbul && node cli.js --coverage test/testsrc/es5-es6/a.js'
after_script: 'npm install coveralls && cat coverage/lcov.info | ./node_modules/.bin/coveralls'
notifications:
  email: false
  slack:
    rooms:
      - sumanjs:gvauyHhXXXXXcuzpV5QOAcI#general

I took this over to a YAML linter and it says:

enter image description here

Upvotes: 0

Views: 581

Answers (2)

Alexander Mills
Alexander Mills

Reputation: 100010

Apparently the right format to use was like so:

language: node_js
node_js:
  - '7'
  - '6'
  - '5'
  - '4'
env:
  - CXX=g++-4.8
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-4.8

script: 'npm install istanbul && node cli.js --coverage test/testsrc/es5-es6/a.js'
after_script: 'npm install coveralls && cat coverage/lcov.info | ./node_modules/.bin/coveralls'
notifications:
  email: false
  slack:
    rooms:XXXXXXXXXzpV5v8LXXcI#travis-ci

If we wanted to apply the env/addons keys to the Node.js versions individually, however, I am not sure how that would work.

Upvotes: 0

Anthon
Anthon

Reputation: 76599

This is not so weird. You have key '7' as the first key value pair of a mapping that is the first element of the sequence that is the value for the key node_js (i.e. the second occurence of that scalar in the file).

The indent for the key is four positions from the beginning of the line, so everything for the mapping it is part of should have at least that indentation. env: however is not indented four positions, so that is an error.

If the value for key '7' is (an invisible ) null then indent env one more. If the value is a mapping that (among others) has a key env) then indent env at least two more positions.

Upvotes: 2

Related Questions