yamlgithub-actions

What's wrong with my YAML syntax for an embedded shell script in my GitHub action?


In my GitHub actions workflow, I have the following segment (under jobs/build/steps):

      - name: Install/Select GCC and G++
        run: |
          sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
          echo "CC=/usr/bin/gcc-${{ matrix.gcc }}" >> $GITHUB_ENV
          echo "CXX=/usr/bin/g++-${{ matrix.gcc }}" >> $GITHUB_ENV
          echo "CUDAHOSTCXX=/usr/bin/g++-${{ matrix.gcc }}" >> $GITHUB_ENV

GitHub fails to run this, emitting:

Invalid workflow file

You have an error in your yaml syntax on line 82

Now, I lifted this from another repository in which this same code supposedly works... what' going on?


Solution

  • Here are the relevant lines, starting from 68, some lines skipped:

        steps:
          - uses: actions/checkout@v2
          - name: Install CUDA
            # .. snip ..
    
          - name: Install/Select GCC and G++
            run: |
              sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
              echo "CC=/usr/bin/gcc-${{ matrix.gcc }}" >> $GITHUB_ENV
              echo "CXX=/usr/bin/g++-${{ matrix.gcc }}" >> $GITHUB_ENV
              echo "CUDAHOSTCXX=/usr/bin/g++-${{ matrix.gcc }}" >> $GITHUB_ENV
        - name: CMake configure
    

    steps: is part of a YAML mapping. The next line starts a YAML sequence which is two spaces more indented. Consequentially, that sequence is ended in line 82 with - name: CMake configure. I have no idea why GitHub shows that as line 83; if you copypaste it to an editor, that empty line is not there. Possibly a line ending issue but I am too lazy to fire up a hex editor to find out.

    In any case, on line 82, the YAML parser ended the value of the mapping key steps and thus expects another mapping key or the end of the mapping. However, it finds a sequence item. That's your error.

    You seem to intend the following sequence items to be part of steps:. If so, indent them to the same level as the previous items.