Skip to content

Commit

Permalink
Merge pull request #3194 from craigcomstock/ENT-11156/3.18
Browse files Browse the repository at this point in the history
ENT-11156: Added shellcheck make target and github action workflow (3.18)
  • Loading branch information
craigcomstock authored Jan 12, 2024
2 parents a3a5af4 + 989af27 commit 3c0def1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Check all shell scripts
on: pull_request

jobs:
shellcheck:
name: Run shellcheck on shell scripts
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
run: sudo apt-get update -y && sudo apt-get install -y shellcheck
- name: Run shellcheck
run: make check
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: check
check:
shellcheck generator/build/*.sh
1 change: 1 addition & 0 deletions generator/build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fi
# so instead of set -x we just echo each command ourselves
set +x
echo "+ source ~/.rvm/scripts/rvm"
# shellcheck disable=SC1090
source ~/.rvm/scripts/rvm

echo "+ rvm_rubygems_version=none rvm install --autolibs=read-only ruby-1.9.3-p551 -C --without-openssl"
Expand Down
27 changes: 16 additions & 11 deletions generator/build/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ set -x
# take ownersip of all files
sudo chown -R jenkins:jenkins .

export WRKDIR=`pwd`
WRKDIR=$(pwd)
export WRKDIR

cd $WRKDIR/documentation/generator
cd "$WRKDIR"/documentation/generator


### download CFEngine ###
Expand All @@ -45,9 +46,9 @@ function fetch_file() {
fi
local success=1 # 1 means False in bash, 0 means True
set +e
for i in `seq 1 $tries`; do
for i in $(seq 1 "$tries"); do
wget "$target" -O "$destination" && success=0 && break
if [ $i -lt $tries ]; then
if [ "$i" -lt "$tries" ]; then
sleep 10s
fi
done
Expand All @@ -62,21 +63,22 @@ test ! -z "$JOB_TO_UPLOAD"
test ! -z "$PACKAGE_UPLOAD_DIRECTORY"
test ! -z "$PACKAGE_BUILD"

BUILDCACHE=http://buildcache.cfengine.com

echo "Waiting for flag file to appear"
for i in `seq 30`; do
wget -O- $FLAG_FILE_URL && break || true
for i in $(seq 30); do
if wget -O- "$FLAG_FILE_URL"; then
break
fi
echo "Waiting 10 sec"
sleep 10
done
# check if flag file is there - if not, script will fail here
wget -O- $FLAG_FILE_URL
wget -O- "$FLAG_FILE_URL"

echo "Detecting version"
HUB_DIR_NAME=PACKAGES_HUB_x86_64_linux_ubuntu_18
HUB_DIR_URL="http://buildcache.cfengine.com/packages/$PACKAGE_JOB/$PACKAGE_UPLOAD_DIRECTORY/$HUB_DIR_NAME/"
HUB_PACKAGE_NAME="$(wget $HUB_DIR_URL -O- | sed '/\.deb/!d;s/.*"\([^"]*\.deb\)".*/\1/')"
HUB_PACKAGE_NAME="$(wget "$HUB_DIR_URL" -O- | sed '/\.deb/!d;s/.*"\([^"]*\.deb\)".*/\1/')"

fetch_file "$HUB_DIR_URL$HUB_PACKAGE_NAME" "cfengine-nova-hub.deb" 12

Expand All @@ -92,25 +94,28 @@ sudo chmod -R a+rX "$WRKDIR"/masterfiles
./_regenerate_json.sh || exit 4

# Preprocess Documentation with custom macros
./_scripts/cfdoc_preprocess.py $BRANCH || exit 5
./_scripts/cfdoc_preprocess.py "$BRANCH" || exit 5

# rvm commands are insane scripts which pollut output
# so instead of set -x we just echo each command ourselves
set +x

# since May 14 2019, we need this to run jekyll. IDK why.
echo "+ source ~/.rvm/scripts/rvm"
# shellcheck disable=SC1090
source ~/.rvm/scripts/rvm
echo "+ rvm --default use 1.9.3-p551"
rvm --default use 1.9.3-p551
echo "+ source ~/.profile"
ls -lah ~
# shellcheck disable=SC1090
test -f ~/.profile && source ~/.profile
echo "+ source ~/.rvm/scripts/rvm"
# shellcheck disable=SC1090
source ~/.rvm/scripts/rvm

export LC_ALL=C.UTF-8

# finally, run actual jekyll
echo "+ bash -x ./_scripts/_run_jekyll.sh $BRANCH || exit 6"
bash -x ./_scripts/_run_jekyll.sh $BRANCH || exit 6
bash -x ./_scripts/_run_jekyll.sh "$BRANCH" || exit 6
8 changes: 4 additions & 4 deletions generator/build/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ true "${PACKAGE_JOB?undefined}"
true "${PACKAGE_UPLOAD_DIRECTORY?undefined}"
true "${PACKAGE_BUILD?undefined}"

c=$(buildah from -v $PWD:/nt docs22)
trap "buildah run $c bash -c 'sudo chown -R root:root /nt; sudo chmod -R a+rwX /nt'; buildah rm $c >/dev/null" EXIT
buildah run $c bash -x documentation/generator/build/main.sh $BRANCH $PACKAGE_JOB $PACKAGE_UPLOAD_DIRECTORY $PACKAGE_BUILD
buildah run $c bash -x documentation/generator/_scripts/_publish.sh $BRANCH
c=$(buildah from -v "$PWD":/nt docs22)
trap 'buildah run "$c" bash -c "sudo chown -R root:root /nt; sudo chmod -R a+rwX /nt"; buildah rm "$c" >/dev/null' EXIT
buildah run "$c" bash -x documentation/generator/build/main.sh "$BRANCH" "$PACKAGE_JOB" "$PACKAGE_UPLOAD_DIRECTORY" "$PACKAGE_BUILD"
buildah run "$c" bash -x documentation/generator/_scripts/_publish.sh "$BRANCH"

0 comments on commit 3c0def1

Please sign in to comment.