CircleCI-Public / shellcheck-orb

An orb for ShellCheck, a static analysis tool for shell scripts (https://shellcheck.net) — check all scripts in your repository on every commit
https://circleci.com/developer/orbs/orb/circleci/shellcheck
MIT License
19 stars 26 forks source link

Executor is missing git #9

Closed cfra closed 5 years ago

cfra commented 5 years ago

I have a CircleCI job like the following:

workflows:
  version: 2
  build_ami:
    jobs:
      - shellcheck/check:
          filters:
            tags:
              only:
                - /.*/

This works fine for regular builds on branches. However, when I do a build on top of a tag, the following happens:

Either git or ssh (required by git to clone through SSH) is not installed in the image. Falling back to CircleCI's native git client but the behavior may be different from official git. If this is an issue, please use an image that has official git and ssh installed.
Enumerating objects: 47, done.
Counting objects: 100% (47/47), done.
Compressing objects: 100% (37/37), done.
Total 5007 (delta 13), reused 23 (delta 7), pack-reused 4960
object not found

I think this is not really the best possible behavior.

I am not sure what the best way to address this would be.

One thing I could think of would be the creation of a circleci/shellckeck docker image instead of the upstream koalaman images, and installing git and ssh into this image.

If someone could point me into the right direction for solving this, I would be willing to work on it.

cfra commented 5 years ago

I saw that all circleci/ images are based on official docker images. Therefore, I guess that creating a circleci/shellcheck image is not really a viable option?

Until a better solution is found, I have written a tiny Dockerfile that adds shellcheck to the circleci/buildpack-deps image, which results in an image that is usable for the shellcheck orb, but also has all the necessary tools available to make it work with git tags. https://github.com/cfra/shellcheck-circleci

cfra commented 5 years ago

By now, I have actually discovered an easier solution for this problem: When specifying workflows, pre-steps can be specified for a job.

- shellcheck/check:
    filters:
      tags: 
        only: 
          - /.*/
    pre-steps:
      - run:
          name: "Install git and SSH client"
          command: |
            apk add \ 
                --update \
                --no-progress \
                git \ 
                openssh-client
iynere commented 5 years ago

@cfra the shellcheck job provides the option of using a custom executor, so you should be able to use any docker image to run the job

cfra commented 5 years ago

@iynere Yea, this is exactly why I started https://github.com/cfra/shellcheck-circleci

But using pre-steps to install git and ssh is actually faster during execution and requires less implementation and maintenance effort, so I think it is the better solution.