Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint the TravisCI YAML file #1812

Closed
seanhamlin opened this issue Jul 18, 2017 · 3 comments
Closed

Lint the TravisCI YAML file #1812

seanhamlin opened this issue Jul 18, 2017 · 3 comments
Labels
Enhancement A feature or feature request

Comments

@seanhamlin
Copy link

seanhamlin commented Jul 18, 2017

TravisCI allows you to lint your .travis.yml file to ensure that it meets it's standards any contains valid YAML and also valid syntax.

Linting the stock BLT supplied .travis.yml yields

specified jdk, but setting is not relevant for php

So it seems that it would be good to have this injected somewhere into the build.

Proposed solution

Add a new BLT validate command for validation of the travisci YAML, and ensure this is invoked when a new PR is pushed. More information on how to do this https://docs.travis-ci.com/user/travis-lint/

@grasmash grasmash added the Enhancement A feature or feature request label Jul 18, 2017
@grasmash
Copy link
Contributor

I would be willing to do this in the travis.yml file itself. However, I do not think that we should add it to the validate commands. That would add a new requirement to BLT to have Ruby and the Travis gem both installed.

grasmash added a commit to grasmash/bolt that referenced this issue Jul 18, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Jul 18, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Jul 18, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Jul 18, 2017
grasmash added a commit to grasmash/bolt that referenced this issue Jul 18, 2017
@grasmash
Copy link
Contributor

It does not appear that you can run the Travis linter on Travis itself. There are some memory allocation issues. I would not like to add the Travis gem as a requirement for local builds, so I'm going to close this issue. Okay feel free to open a pull request introducing the feature if you're able to get it working.

@D41078817
Copy link

In my observation, Travis CI dies without good warning / notice if the .travis.yml file is malformatted. This is a big problem.

So, when I ran across this issue I wanted to comment with the solution I found.

You can lint the .travis.yml file using BLT + custom fileset. For example, you could do this in a pre-commit hook.

Here is how to do this:

  1. Create a custom fileset in blt/src/Filesets.php

    /**
     * Travis YAML files.
     *
     * @fileset(id="files.yaml.travis")
     */
    public function getTravisYaml() {
      $yaml = Finder::create()
        ->files()
        ->name('.travis.yml')
        ->ignoreDotFiles(false)
        ->depth('<1')
        ->in($this->getConfigValue('repo.root'));
      return $yaml;
    }
    
  2. Add the fileset to the blt/blt.yml

    validate:
      yaml:
        filesets:
          - files.yaml.travis
    
  3. Make sure git hooks are installed (everyone making commits on the repo needs to do this)

    blt blt:init:git-hooks
    

Now, when you make a commit you should see something like this:

$ git commit -a -m 'JR-123: Change travis yml'
Executing .git/hooks/pre-commit...
[warning] The tests:phpcs:sniff:files command is disabled.
[warning] The tests:twig:lint:files command is disabled.
>>> tests:yaml:lint:files
Linting YAML files...
Iterating over fileset files.yaml.travis...
Your local code has passed git pre-commit validation.
Executing .git/hooks/commit-msg...
Validating commit message syntax...
[JR-123 3c2ddfa4] JR-123: Change travis yml
 1 files changed, 1 insertions(+), 1 deletions(-)

Note: you'll notice the phpcs and twig lint commands are disabled. That was achieved by having this in the blt.yml:

disable-targets:
  tests:
    phpcs: { sniff: { all: true, files: true } }
    twig: { lint: { all: true, files: true } }

Bonus Note: Customizing Git Hooks

You can completely customize the git hooks by doing the following:

  1. Copy the git hooks to your scripts directory:

    cp -r vendor/acquia/blt/scripts/git-hooks scripts/
    
  2. Tell BLT to use your custom hooks in the blt/blt.yml

    git:
      hooks:
        pre-commit: ${repo.root}/scripts/git-hooks
        commit-msg: ${repo.root}/scripts/git-hooks
    
  3. Change the commit-msg hook reference to blt-robo.php, it's the last line in the file and should be changed to this:

    require __DIR__ . '/../../vendor/acquia/blt/bin/blt-robo.php';
    
  4. Re-install git-hooks (everyone making commits on the repo needs to do this)

    blt blt:init:git-hooks
    

Now, you can customize the git-hooks in your scripts/git-hooks directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A feature or feature request
Projects
None yet
Development

No branches or pull requests

3 participants