Skip to content

Commit

Permalink
Merge pull request #22 from housni/add-github-actions
Browse files Browse the repository at this point in the history
Add Github Actions
  • Loading branch information
housni committed Nov 24, 2023
2 parents b546a03 + 7b2cec1 commit 6ba7bca
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 68 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Makefile CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: make prepare

- name: Lint test
run: make check.lint

- name: General tests
run: make check.test
62 changes: 2 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ MOUNT_PATH ?= /sheldon
# Default: All scripts ending with '.sh' in the project.
SHELL_SCRIPTS ?= $(shell find ./ -name '*.sh')

# Files to run 'yamllint' against.
YAML_FILES ?= .travis.yml

# Name of test(s) to run.
# Default: null
TEST_NAMES ?=
Expand Down Expand Up @@ -105,7 +102,6 @@ strlen = "$(shell declare some; some=$1; echo $${\#some}; )"
.PHONY: prepare
prepare:
@echo; echo "Sheldon is working. Please wait..."; echo
@$(DOCKER) pull "sdesbure/yamllint" 2>&1 >/dev/null
@$(DOCKER) build --rm -t sheldon ./ 2>&1 >/dev/null
@$(DOCKER) pull "koalaman/shellcheck:stable" 2>&1 >/dev/null

Expand All @@ -122,7 +118,7 @@ prepare:
check: check.lint check.test.unit

# NAME
# check.lint - See target 'check.lint.shellcheck' and 'check.lint.yamllint'.
# check.lint - See target 'check.lint.shellcheck'.
#
# SYNOPSIS
# make [OPTION]... check.lint
Expand All @@ -131,7 +127,7 @@ check: check.lint check.test.unit
# See target 'shellcheck'.
#
.PHONY: check.lint
check.lint: check.lint.shellcheck check.lint.yamllint check.lint.sheldon
check.lint: check.lint.shellcheck check.lint.sheldon

# NAME
# check.lint.shellcheck - Runs 'shellcheck' against shell scripts.
Expand Down Expand Up @@ -223,60 +219,6 @@ check.lint.sheldon:
$(DOCKER_IMG_NAME) \
./bin/check-convention

# NAME
# check.lint.yamllint - Runs 'yamllint' against YAML files.
#
# SYNOPSIS
# make [OPTION]... check.lint.yamllint
#
# DESCRIPTION
# Runs a Docker container using an image with 'yamllint' installed and runs
# it against files in YAML_FILES.
#
# MOUNT_PATH
# Location on the Docker container where Sheldon will be mounted.
# This is the location from which yamllint will run. It's also the
# directory the container will start in and it will be mounted as
# read-only.
#
# See: https://hub.docker.com/r/sdesbure/yamllint/
#
# YAML_FILES
# Files to run 'yamllint' against. These files may be space or
# new-line delimited and must be relative to MOUNT_PATH.
#
# DOCKER
# Docker executable.
# Don't change this unless you know what you're doing.
#
# CURDIR
# Absolute pathname of the current working directory.
# See: https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html
#
# EXAMPLES
# make check.lint.yamllint
# Runs 'yamllint' against files in YAML_FILES.
#
# make MOUNT_PATH="/usr/lib/sheldon/" check.lint.yamllint
# Mounts Sheldon to '/usr/lib/sheldon/' in the Docker container and runs
# 'yamllint' against all files in YAML_FILES.
#
# make YAML_FILES="./foobar.yaml" check.lint.yamllint
# Runs 'yamllint' against only './foobar.yaml'.
#
# make YAML_FILES=$(find ./ -regex '.*\.ya?ml') check.lint.yamllint
# Runs 'yamllint' against all files in './' that end with either ".yml"
# or ".yaml".
#
.PHONY: check.lint.yamllint
check.lint.yamllint: prepare
@$(MAKE) --no-print-directory TARGET_NAME=$@ _output.banner
@$(DOCKER) run \
--rm --mount type=bind,source="$(CURDIR)",target=$(MOUNT_PATH),readonly \
-w "$(MOUNT_PATH)" \
"sdesbure/yamllint" \
yamllint $(YAML_FILES)

# NAME
# check.test - See target 'check.test.unit'.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/sheldon/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ import() {
Sheldon.Core.Libraries.load "${1}"

# If a third param is present, treat it as an alias.
if [[ ! -z "${3+x}" ]]; then
if [[ -n "${3+x}" ]]; then
eval "$3"="$1"
fi
}
Expand Down
6 changes: 3 additions & 3 deletions lib/sheldon/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Run ArrayTest.testFirst
# ./test.sh ArrayTest.testFirst

# shellcheck disable=SC1090
# shellcheck source=/dev/null
. "${0%/*}/../bootstrap.sh"
set +o errtrace

Expand Down Expand Up @@ -71,7 +71,7 @@ for testFile in $allTestFiles; do
# TODO: If function doesn't exist, show error.
# If we have assigned parsedFunc earlier, that means a specific function
# name was passed in as a param, so we only allow that function to run.
if [ ! -z "$parsedFunc" ] && [ "$testFunc" != "$parsedFunc" ]; then
if [ -n "$parsedFunc" ] && [ "$testFunc" != "$parsedFunc" ]; then
continue
fi

Expand All @@ -97,4 +97,4 @@ $Test.summary

# shellcheck disable=SC2086
status=$($Test.status)
exit "$status"
exit "$status"
6 changes: 3 additions & 3 deletions lib/sheldon/tests/ArrayTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ArrayTest.testPop() {
read -ra result <<< "$($Test.array_diff args expected)"
$Test.it 'Should pass if an element is popped off the end of the array.' \
skip 'This has not been implemented.' <<EOF
[ -z $result ]
[ -z ${result[@]} ]
[ "$popped" = 'html' ]
EOF
}
Expand Down Expand Up @@ -128,7 +128,7 @@ ArrayTest.testShift() {
read -ra result <<< "$($Test.array_diff arg1 expected)"
$Test.it 'Should pass if an element shifted.' \
skip 'This has not been implemented.' <<EOF
[ -z "$result" ]
[ -z "${result[@]}" ]
[ "$shifted" = 'var' ]
EOF
}
Expand Down Expand Up @@ -217,4 +217,4 @@ EOF
$Test.it 'Should pass if custom array element overwrote the default one and appended remaining elements.' <<EOF
[ -z "$difference" ]
EOF
}
}
3 changes: 2 additions & 1 deletion lib/sheldon/util/Array.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Sheldon.Util.Array.update() {
for default in "${!__shld_defaults[@]}"; do
if [[ "${__shld_others[$default]+housni}" ]]; then
__shld_defaults["$default"]="${__shld_others["$default"]}"
# shellcheck disable=SC2184
unset __shld_others["$default"]
fi

Expand All @@ -163,4 +164,4 @@ Sheldon.Util.Array.update() {
for others in "${!__shld_others[@]}"; do
__shld_defaults["$others"]="${__shld_others["$others"]}"
done
}
}

0 comments on commit 6ba7bca

Please sign in to comment.