version: 2.1

executors:
  gcc:
    parameters:
      version:
        type: string
    docker:
      - image: gcc:<< parameters.version >>

jobs:
  lint:
    docker:
      - image: koalaman/shellcheck-alpine:stable
    steps:
      - checkout
      - run:
          name: ShellCheck version
          command: shellcheck --version
      - run:
          name: Run ShellCheck
          command: shellcheck --exclude=SC2016,SC2209 -- ./*.sh
  build:
    parameters:
      version:
        type: string
      file:
        type: string
    executor:
      name: gcc
      version: << parameters.version >>
    steps:
      - checkout
      - run:
          name: Compiler version
          command: cc --version
      - run:
          name: << parameters.file >> (gcc:<< parameters.version >>)
          command: ./<< parameters.file >>

workflows:
  lints:
    jobs:
      - lint
      - build:
          requires:
            - lint
          matrix:
            parameters:
              version:
                - "10"
                - "9"
                - "8"
                - "7"
              file:
                - git_install.sh
                - libevent_install.sh
                - openssh_install.sh
                # - ruby_install.sh # It takes long time for compiling and is rarely used
                - tmux_install.sh
                - vim_install.sh

version: 2.1

executors:
  buildrunner:
    parameters:
      version:
        type: string
    docker:
      - image: buildpack-deps:<< parameters.version >>

jobs:
  lint:
    docker:
      - image: koalaman/shellcheck-alpine:stable
    steps:
      - checkout
      - run:
          name: ShellCheck version
          command: shellcheck --version
      - run:
          name: Run ShellCheck
          command: shellcheck --exclude=SC2016,SC2209 -- ./*.sh
  build:
    parameters:
      version:
        type: string
      file:
        type: string
    executor:
      name: buildrunner
      version: << parameters.version >>
    steps:
      - checkout
      - run:
          name: Compiler version
          command: cc --version
      - run:
          name: << parameters.file >> (<< parameters.version >>)
          command: ./<< parameters.file >>

workflows:
  lints:
    jobs:
      - lint
      - build:
          requires:
            - lint
          matrix:
            parameters:
              version:
                - 20.04
                - 18.04
              file:
                - git_install.sh
                - libevent_install.sh
                - openssh_install.sh
                # - ruby_install.sh # It takes long time for compiling and is rarely used
                - tmux_install.sh
                - vim_install.sh

Use buildpack-deps image to build applications
Use buildpack-deps image to build applications
