Skip to content

Commit

Permalink
Merge pull request #3177 from craigcomstock/ENT-11156/master
Browse files Browse the repository at this point in the history
ENT-11156: Added shellcheck make target and github action workflow
  • Loading branch information
craigcomstock authored Jan 8, 2024
2 parents 8af8652 + 22d0236 commit b0aa12c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 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
5 changes: 3 additions & 2 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 Expand Up @@ -113,5 +114,5 @@ patch -b page.rb < /tmp/jekyll-0.12.1-cfengine.patch
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install -y nodejs
$(which node) --version
$(which npm) --version
node --version
npm --version
31 changes: 18 additions & 13 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_22
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 @@ -90,34 +92,37 @@ sudo cp -a /var/cfengine/share/NovaBase/masterfiles "$WRKDIR"
sudo chmod -R a+rX "$WRKDIR"/masterfiles

# write current branch into the config.yml
echo "branch: $BRANCH" >> $WRKDIR/documentation/generator/_config.yml
echo "branch: $BRANCH" >> "$WRKDIR"/documentation/generator/_config.yml

# Generate syntax data
./_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

cd $WRKDIR/documentation/generator
cd "$WRKDIR"/documentation/generator
npm run build
8 changes: 4 additions & 4 deletions generator/build/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ true "${PACKAGE_JOB?undefined}"
true "${PACKAGE_UPLOAD_DIRECTORY?undefined}"
true "${PACKAGE_BUILD?undefined}"

c=$(buildah from -v $PWD:/nt docs-revamp-22)
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 docs-revamp-22)
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 b0aa12c

Please sign in to comment.