Skip to content

Commit

Permalink
Verify version for each command (#43)
Browse files Browse the repository at this point in the history
Thanks to contributions by @sdolenc 

* docker files
* list tools for testing
* test packages
* github actions
* documentation
* ensure expected command count
* output count of individual tools tested
* test: eb rg podman subl brunch grunt gulp heroku netlify sls java brew gor, heroku, mvn, netlify, netlifyctl, php5,  gcloud, hub, coreutils, brunch, code, kotlin, sbt, go, ant, gem, rake, autojump, groovy, aws, perl6, sbt, scala, lein
  • Loading branch information
sdolenc authored Apr 25, 2020
1 parent 31828ec commit 4ccd017
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 13 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI
on: [push, pull_request]

jobs:
shellcheck:
name: shellcheck
runs-on: ubuntu-latest

steps:
- name: Clone Repo
uses: actions/checkout@v2

- name: Run Shellcheck
uses: ludeeus/[email protected]

test:
name: test
runs-on: ubuntu-latest
strategy:
matrix:
container:
- debian # uses debian:buster-20200327-slim which is debian 10.3
- ubuntu16 # uses ubuntu:xenial-20200212 which is ubuntu 16.04

container: sdolenc/testing-has:${{ matrix.container }}

steps:
- name: Clone Repo
uses: actions/checkout@v2

- name: test
run: make test
shell: bash

test_all:
name: test_all
runs-on: ubuntu-latest
strategy:
matrix:
container:
- ubuntu # uses ubuntu:bionic-20200311 which is ubuntu 18.04
- alpine # uses bash:5.0.16 which is alpine 3.11

container: sdolenc/testing-has:${{ matrix.container }}

steps:
- name: Clone Repo
uses: actions/checkout@v2

- name: test_all
run: bats -t ./tests/test_all_packages.bats
shell: bash
17 changes: 14 additions & 3 deletions .hastest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ teardown() {
}

@test "..even if 'has' is missing from directory" {
if [[ -n $GITHUB_ACTION ]] || [[ -n $GITHUB_ACTIONS ]]; then
if grep -iq "ubuntu" /etc/issue; then
skip "todo: this test fails on ubuntu in CI"
fi
fi

INSTALL_DIR="${HAS_TMPDIR}/system_local"
cd "${BATS_TEST_DIRNAME}"
mv has has-been
Expand All @@ -58,11 +64,16 @@ teardown() {

@test "make update runs git fetch" {
cd "${BATS_TEST_DIRNAME}"
skip "make update overwrites my git working tree"
if [[ -z $GITHUB_ACTION ]] && [[ -z $GITHUB_ACTIONS ]]; then
skip "make update overwrites my git working tree"
elif grep -iq "ubuntu" /etc/issue; then
skip "todo: this test fails on ubuntu in CI"
fi

run make update

[ "$status" -eq 0 ]
[ "${lines[*]}" =~ "git fetch --verbose" ]
[ "$(echo "${output}" | grep "git fetch --verbose")" ]
}

@test "works with single command check" {
Expand Down Expand Up @@ -167,7 +178,7 @@ teardown() {

@test "testing hub version is different to git version" {
if ! command -v hub; then
skip "'hub' command not found. This passes for @virgilwashere locally."
skip "'hub' command not found. Installation command can be found at the bottom of ./tests/containers/debian.Dockerfile"
fi
run $has hub git

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,16 @@ On machines that don't even have `has` installed, your project's `.hasrc` is hon

## Adding more tools

The current list of supported packages can be viewed with `bash tests/packages_all.sh`

If the command you wish to include supports any of `-v`, `--version`, `-version`, `version`, `-V` then you can find
corresponding function which can be called to check presence and extract version. However, for many tools version
extraction may not work and you will need to add custom parsing of command's output. The `has` script is commented
to guide developers about what needs to be done to add more tools.

`/tests/test_all_packages.bats` will test every package has supports. This includes newly added commands so please add new packages to
- `alpine.Dockerfile` and `ubuntu.Dockerfile` to install the tool OR
- `packages_alpine_skip.txt` and `packages_ubuntu_skip.txt` to exclude the package from the tests

## Adding Features

Expand Down
23 changes: 13 additions & 10 deletions has
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ readonly BINARY_NAME="has"
readonly VERSION="v1.4.0"

## constants - symbols for success failure
readonly txtreset="$(tput sgr0)"
readonly txtbold="$(tput bold)"
readonly txtblack="$(tput setaf 0)"
readonly txtred="$(tput setaf 1)"
readonly txtgreen="$(tput setaf 2)"
readonly txtyellow="$(tput setaf 3)"
readonly txtblue="$(tput setaf 4)"
readonly txtpurple="$(tput setaf 5)"
readonly txtcyan="$(tput setaf 6)"
readonly txtwhite="$(tput setaf 7)"
if [[ -z $TERM ]]; then
$TERM="xterm"
fi
readonly txtreset="$(tput -T $TERM sgr0)"
readonly txtbold="$(tput -T $TERM bold)"
readonly txtblack="$(tput -T $TERM setaf 0)"
readonly txtred="$(tput -T $TERM setaf 1)"
readonly txtgreen="$(tput -T $TERM setaf 2)"
readonly txtyellow="$(tput -T $TERM setaf 3)"
readonly txtblue="$(tput -T $TERM setaf 4)"
readonly txtpurple="$(tput -T $TERM setaf 5)"
readonly txtcyan="$(tput -T $TERM setaf 6)"
readonly txtwhite="$(tput -T $TERM setaf 7)"
# unicode "✗"
readonly fancyx='\342\234\227'
# unicode "✓"
Expand Down
10 changes: 10 additions & 0 deletions tests/containers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# has containers

Custom containers used for testing https://github.com/kdabir/has

| container image | status |
|------------------------------|--------|
| sdolenc/testing-has:alpine | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/sdolenc/testing-has/alpine) |
| sdolenc/testing-has:ubuntu | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/sdolenc/testing-has/ubuntu) |
| sdolenc/testing-has:debian | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/sdolenc/testing-has/debian) |
| sdolenc/testing-has:ubuntu16 | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/sdolenc/testing-has/ubuntu16) |
141 changes: 141 additions & 0 deletions tests/containers/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
FROM bash:5.0.16

# already contains
# awk
# bash=5.0.16
# bzip2
# grep
# gzip=1.31.1
# sed=4.0
# tar=1.31.1
# unzip=6.00
# wget
# xz
RUN apk add --no-cache \
ack=3.2.0-r0 \
apache2-utils~=2.4 `# ab=2.3` \
apache-ant=1.10.7-r0 `# ant=1.10.7` \
build-base libffi-dev openssl-dev `# required for eb` \
curl=7.67.0-r0 \
bzr=2.7.0-r1 \
docker=19.03.5-r0 \
emacs=26.3-r2 \
file=5.37-r1 \
gcc=9.2.0-r4 \
git~=2.24.3 \
go=1.13.4-r1 \
gradle=5.6.4-r0 \
hugo=0.61.0-r0 \
jq=1.6-r0 \
make=4.2.1-r2 \
maven=3.6.3-r0 `# mvn=3.6.3` \
mercurial=5.3.2-r0 `# hg=5.3.2` \
nano=4.6-r0 \
ncurses=6.1_p20200118-r3 `#tput:todo` \
npm=12.15.0-r1 `# npm=6.13.4 # node=12.15.0` \
openjdk11=11.0.5_p10-r0 `# java=11.0.5` \
perl=5.30.1-r0 ` # perl=30` \
php7=7.3.17-r0 `# php=7.3.17 ` \
postgresql=12.2-r0 `# psql=12.2` \
pv=1.6.6-r1 \
python=2.7.16-r3 \
python3-dev=3.8.2-r0 `#python3=3.8.2` \
R=3.6.2-r0 \
ruby=2.6.6-r2 `# gem=3.0.3` \
ruby-bundler=2.0.2-r1 `# bundle=2.0.2` \
ruby-bigdecimal ruby-json `# required for brew` \
ruby-rake=2.6.6-r2 `# rake=12.3.3` \
subversion=1.12.2-r1 `# svn=1.12.2` \
sudo=1.8.31-r0 \
tree=1.8.0-r0 \
vim~=8.2 \
yarn=1.19.2-r0 \
zip=3.0-r7 \
zsh=5.7.1-r0 && \
\
# required for brew and lein
ln -s $(which bash) /bin/bash && \
\
npm install --global \
brunch@"=3.0.0" \
grunt-cli@"=1.3.2" \
gulp-cli@"=2.2.0" \
heroku@"=7.39.3" \
netlify-cli@"=2.46.0" \
serverless@"=1.67.3" `# sls=1.67.3` && \
\
autojump=22.5.3 && \
curl -L "https://github.com/wting/autojump/archive/release-v${autojump}.tar.gz" | tar xz && \
cd "autojump-release-v${autojump}" && \
SHELL=bash ./install.py && \
cd / && \
ln -s ~/.autojump/bin/autojump /usr/local/bin/autojump && \
\
commit="87b16eb" `# bats=1.2.0` && \
curl -L "https://github.com/bats-core/bats-core/tarball/${commit}" | tar xz && \
"bats-core-bats-core-${commit}/install.sh" /usr/local && \
\
brew=2.2.13 && \
git clone --branch ${brew} https://github.com/Homebrew/brew && \
eval $(brew/bin/brew shellenv) && \
ln -s /brew/bin/brew /usr/local/bin/brew && \
brew --version && \
\
eb=3.18.0-1 && \
curl -L "https://github.com/sdolenc/aws-elastic-beanstalk-cli/archive/${eb}.tar.gz" | tar xz && \
pip3 install ./aws-elastic-beanstalk-cli-${eb} && \
\
gcloud=289.0.0 && \
curl -L "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${gcloud}-linux-x86_64.tar.gz" | tar xz && \
ln -s /google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud && \
\
gor=1.0.0 && \
curl -L "https://github.com/buger/goreplay/releases/download/v${gor}/gor_${gor}_x64.tar.gz" | tar xz --directory /usr/local/bin && \
\
groovy=3.0.3 && \
curl -L "https://dl.bintray.com/groovy/maven/apache-groovy-binary-${groovy}.zip" -o /groovy.zip && \
unzip groovy.zip && rm groovy.zip && \
ln -s "/groovy-3.0.3/bin/groovy" /usr/local/bin/groovy && \
\
pip3 install \
awscli==1.18.43 `# aws=1.18.43` \
httpie==2.1.0 `# http=2.1.0` && \
\
hub=2.14.2 && \
curl -L "https://github.com/github/hub/releases/download/v${hub}/hub-linux-386-${hub}.tgz" | tar xz && \
ln -s "/hub-linux-386-${hub}/bin/hub" /usr/local/bin/hub && \
\
`# javac=11.0.5` && \
ln -s "/usr/lib/jvm/java-11-openjdk/bin/javac" /usr/local/bin/javac && \
\
kotlin=1.3.72 && \
curl -L "https://github.com/JetBrains/kotlin/releases/download/v${kotlin}/kotlin-compiler-${kotlin}.zip" -o /kotlin.zip && \
unzip kotlin.zip && rm kotlin.zip && \
ln -s /kotlinc/bin/kotlin /usr/local/bin/kotlin && \
ln -s /kotlinc/bin/kotlinc /usr/local/bin/kotlinc && \
\
netlifyctl=0.4.0 && \
curl -L "https://github.com/netlify/netlifyctl/releases/download/v${netlifyctl}/netlifyctl-linux-amd64-${netlifyctl}.tar.gz" | tar xz --directory /usr/local/bin && \
\
perl6=2020.02.1-04 && \
curl -L "https://github.com/nxadm/rakudo-pkg/releases/download/v${perl6}/rakudo-pkg-Alpine3.11_${perl6}_x86_64.apk" --output perl6.apk && \
apk add --allow-untrusted perl6.apk && rm perl6.apk && \
ln -s /opt/rakudo-pkg/bin/perl6 /usr/local/bin/perl6 && \
\
rg=12.0.1 && \
curl -L "https://github.com/BurntSushi/ripgrep/releases/download/${rg}/ripgrep-${rg}-x86_64-unknown-linux-musl.tar.gz" | tar xz && \
ln -s "/ripgrep-${rg}-x86_64-unknown-linux-musl/rg" /usr/local/bin/rg && \
\
sbt=1.3.4 && \
curl -L "https://piccolo.link/sbt-${sbt}.tgz" | tar xz && \
ln -s /sbt/bin/sbt /usr/local/bin/sbt && \
sbt --version && sbt --version && \
\
scala=2.12.11 && \
curl -L "https://downloads.lightbend.com/scala/${scala}/scala-${scala}.tgz" | tar xz && \
ln -s "/scala-${scala}/bin/scala" /usr/local/bin/scala && \
\
echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
apk add --no-cache \
leiningen=2.9.1-r0 `# lein=2.9.1` \
podman=1.9.0-r0
33 changes: 33 additions & 0 deletions tests/containers/debian.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM debian:buster-20200327-slim

# already contains
# apt
# apt-get
# bash
# grep
# gzip
# tar
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y -qq \
bc \
pv \
xz-utils \
unar \
make \
curl \
git \
unzip \
xz-utils `#xz` \
unar \
pv \
zip \
sudo \
file \
&& apt-get -y autoremove && apt-get -y clean && rm -rf /var/lib/apt/lists/*; \
\
#bats
commit="87b16eb"; \
curl -L "https://github.com/bats-core/bats-core/tarball/${commit}" | tar xz; \
"bats-core-bats-core-${commit}/install.sh" /usr/local; \
\
#hub
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.2
Loading

0 comments on commit 4ccd017

Please sign in to comment.