travis-ci / travis-yaml

parses, normalizes, validates and serializes your .travis.yml
http://yaml.travis-ci.org/
MIT License
170 stars 66 forks source link

travis fails to validate syntax when comments are present #112

Closed zilinc closed 7 years ago

zilinc commented 7 years ago
# This file has been generated -- see https://github.com/hvr/multi-ghc-travis
language: c
sudo: false

cache:
  directories:
    - $HOME/.cabsnap
    # - $HOME/.cabal/packages

matrix:
  include:
    - env: CABALVER=1.22 GHCVER=7.10.3
      compiler: ": #GHC 7.10.3"
      addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}
    - env: CABALVER=1.24 GHCVER=8.0.1
      compiler: ": #GHC 8.0.1"
      addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}
    - env: CABALVER=1.24 GHCVER=8.0.2
      compiler: ": #GHC 8.0.2"
      addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,alex-3.1.7,happy-1.19.5], sources: [hvr-ghc]}}

before_install:
 - unset CC
 - export ALEXVER=3.1.7
 - export HAPPYVER=1.19.5
 - export REPO=$(pwd)
 - export SANDBOX=".cabal-sandbox"

script:
 - cabal --version
 - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"

 - if diff -u $HOME/.cabsnap/installplan.txt installplan.txt;
   then
     echo "cabal build-cache HIT";
     # OFFENDING COMMENT
   else
     echo "cabal build-cache MISS";
   fi

If the offending comment near the bottom is removed, then it validates.

BanzaiMan commented 7 years ago

It is not valid YAML; you can't have the octothorp in an implicit multi-line string.

You might mean something like:

 - |
   if diff -u $HOME/.cabsnap/installplan.txt installplan.txt;
   then
     echo "cabal build-cache HIT";
     # OFFENDING COMMENT
   else
     echo "cabal build-cache MISS";
   fi

See http://stackoverflow.com/a/21699210/136333.

zilinc commented 7 years ago

Thanks for the clarification.

BanzaiMan commented 7 years ago

A little more clarification. If the octothorp is the last line, for example, it is fine.

This is valid YAML (but the resulting string is not valid bash).

 - if diff -u $HOME/.cabsnap/installplan.txt installplan.txt;
   then
     echo "cabal build-cache HIT";
     # OFFENDING COMMENT

The octothorp introduces a comment, which is a new token in YAML, so the line above it terminates the string.

The YAML parse at this point is waiting for a next item in the sequence introduced by - if …, or the end of the sequence, but what follows the # line is:

   else
   ⋮

which is a scalar.