Skip to content

Commit

Permalink
Shellcheck - fix errors and add to CI (#26)
Browse files Browse the repository at this point in the history
Fix shellcheck errors in the existing code
Add shellcheck workflow to GitHub CI
Add the shellcheck workflow to the dependencies of the release workflow
  • Loading branch information
ygalblum committed Nov 30, 2023
1 parent 38f69b0 commit fb014b6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ jobs:
uses: swapdisk/lvm_snapshots/.github/workflows/ansible-lint.yml@main
pylint:
uses: swapdisk/lvm_snapshots/.github/workflows/pylint.yml@main
shellcheck:
uses: swapdisk/lvm_snapshots/.github/workflows/shellcheck.yml@main
prechecks:
needs:
- ansible-lint
- pylint
- shellcheck
runs-on: ubuntu-latest
steps:
- run: >-
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ShellCheck
on:
- push
- pull_request
- workflow_call

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

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
8 changes: 4 additions & 4 deletions roles/bigboot/files/bigboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ parse_flags() {
do
case $i in
-d=*|--device=*)
DEVICE_NAME=(${i#*=})
DEVICE_NAME="(${i#*=})"
;;
-s=*|--size=*)
INCREMENT_BOOT_PARTITION_SIZE=(${i#*=})
INCREMENT_BOOT_PARTITION_SIZE="(${i#*=})"
;;
-b=*|--boot=*)
BOOT_PARTITION_NUMBER=(${i#*=})
BOOT_PARTITION_NUMBER="(${i#*=})"
;;
-p=*|--prefix=*)
PARTITION_PREFIX=(${i#*=})
PARTITION_PREFIX="(${i#*=})"
;;
-h)
print_help
Expand Down
1 change: 1 addition & 0 deletions roles/bigboot/files/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ check(){

install() {
inst_multiple -o /usr/bin/mount /usr/bin/umount /usr/sbin/parted /usr/bin/mktemp /usr/bin/wc /usr/bin/date /usr/bin/sed /usr/bin/awk /usr/bin/basename /usr/sbin/resize2fs /usr/sbin/tune2fs /usr/sbin/partprobe /usr/bin/numfmt /usr/sbin/lvm /usr/bin/lsblk /usr/sbin/e2fsck /usr/sbin/fdisk /usr/bin/findmnt /usr/bin/tail /usr/ /usr/sbin/xfs_growfs /usr/sbin/xfs_db
# shellcheck disable=SC2154
inst_hook pre-mount 99 "$moddir/increase-boot-partition.sh"
inst_binary "$moddir/sfdisk.static" "/usr/sbin/sfdisk"
inst_simple "$moddir/bigboot.sh" "/usr/bin/bigboot.sh"
Expand Down
1 change: 1 addition & 0 deletions roles/shrink_lv/files/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ check(){

install() {
inst_multiple -o /usr/bin/numfmt /usr/bin/findmnt /usr/bin/lsblk /usr/sbin/lvm /usr/bin/awk /usr/bin/sed /usr/bin/mktemp /usr/bin/date /usr/bin/head /usr/sbin/blockdev /usr/sbin/tune2fs /usr/sbin/resize2fs /usr/bin/cut /usr/sbin/fsadm /usr/sbin/fsck.ext4
# shellcheck disable=SC2154
inst_hook pre-mount 99 "$moddir/shrink-start.sh"
inst_simple "$moddir/shrink.sh" "/usr/bin/shrink.sh"
}
9 changes: 5 additions & 4 deletions roles/shrink_lv/files/shrink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ function get_device_name() {
}

function ensure_size_in_bytes() {
local expected_size=$(/usr/bin/numfmt --from iec "$1")
let expected_size=(${expected_size} + $VOLUME_SIZE_ALIGNMENT)/$VOLUME_SIZE_ALIGNMENT*$VOLUME_SIZE_ALIGNMENT
local expected_size
expected_size=$(/usr/bin/numfmt --from iec "$1")
(( expected_size=(expected_size+VOLUME_SIZE_ALIGNMENT)/VOLUME_SIZE_ALIGNMENT*VOLUME_SIZE_ALIGNMENT ))
echo $expected_size
}

Expand Down Expand Up @@ -163,7 +164,7 @@ function parse_flags() {
do
case $i in
-d=*|--device=*)
entries+=(${i#*=})
entries+="(${i#*=})"
;;
-h)
display_help
Expand All @@ -185,7 +186,7 @@ function parse_flags() {

function parse_entry() {
IFS=':'
read -a strarr <<< "$1"
read -ra strarr <<< "$1"

if [[ ${#strarr[@]} != 2 ]]; then
echo "Invalid device entry $1"
Expand Down

0 comments on commit fb014b6

Please sign in to comment.