From ecd339278d767b9ff174964df4a75deb3e2788b0 Mon Sep 17 00:00:00 2001 From: nl6720 <nl6720@gmail.com> Date: Thu, 16 Jul 2020 14:40:27 +0300 Subject: [PATCH 1/3] Add check target to Makefile Makefile: Move shellcheck commands from .gitlab-ci.yml. .gitlab-ci.yml: Run `make check`. Prevent partial upgrades, i.e. use '-Syu'. Prevent reinstalling already installed packages by using pacman's '--needed' option. Don't force-download the package database. --- .gitlab-ci.yml | 14 ++------------ Makefile | 11 ++++++++++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 74ecdd32..e69ab5e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,19 +3,9 @@ default: image: archlinux/base before_script: - - pacman --noconfirm -Syy - - pacman --noconfirm -S base-devel shellcheck + - pacman --noconfirm -Syu --needed base-devel shellcheck lint: stage: build script: - - shellcheck -s bash - archiso/mkarchiso - configs/{baseline,releng}/build.sh - configs/releng/airootfs/root/.automated_script.sh - configs/releng/airootfs/usr/local/bin/choose-mirror - scripts/run_archiso.sh - archiso/initcpio/install/* - - shellcheck -s dash - archiso/initcpio/hooks/* - archiso/initcpio/script/* + - make check diff --git a/Makefile b/Makefile index 6b479f92..3ee8a6a6 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,15 @@ DOC_DIR=$(DESTDIR)/usr/share/doc/archiso all: +check: + shellcheck -s bash archiso/mkarchiso \ + scripts/run_archiso.sh \ + $(INSTALL_FILES) \ + $(wildcard configs/*/build.sh) \ + configs/releng/airootfs/root/.automated_script.sh \ + configs/releng/airootfs/usr/local/bin/choose-mirror + shellcheck -s dash $(HOOKS_FILES) $(SCRIPT_FILES) + install: install-program install-initcpio install-examples install-doc install-program: @@ -32,4 +41,4 @@ install-doc: install -d $(DOC_DIR) install -m 644 -t $(DOC_DIR) $(DOC_FILES) -.PHONY: install install-program install-initcpio install-examples install-doc +.PHONY: check install install-program install-initcpio install-examples install-doc -- GitLab From 2993b80816be1b06f7bb57b500a47989ac3af0e9 Mon Sep 17 00:00:00 2001 From: nl6720 <nl6720@gmail.com> Date: Thu, 16 Jul 2020 15:22:55 +0300 Subject: [PATCH 2/3] Add GitHub Actions workflow .github/workflows/lint.yml: Run `make check`. --- .github/workflows/lint.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..4e778e84 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ '*' ] + pull_request: + branches: [ master ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + lint: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: shellcheck + run: make check -- GitLab From b40fb2ae53427e0fb14514e7929c02246ac298f0 Mon Sep 17 00:00:00 2001 From: nl6720 <nl6720@gmail.com> Date: Thu, 16 Jul 2020 15:49:23 +0300 Subject: [PATCH 3/3] Separate custom comments from shellcheck comments Having a shellcheck directive and custom comments in the same line can trigger SC1107 on old versions of shellcheck. --- archiso/initcpio/hooks/archiso | 15 ++++++++++----- archiso/initcpio/hooks/archiso_loop_mnt | 9 ++++++--- archiso/initcpio/hooks/archiso_pxe_common | 9 ++++++--- archiso/initcpio/hooks/archiso_pxe_http | 15 ++++++++++----- archiso/initcpio/hooks/archiso_pxe_nbd | 3 ++- archiso/initcpio/hooks/archiso_pxe_nfs | 6 ++++-- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/archiso/initcpio/hooks/archiso b/archiso/initcpio/hooks/archiso index 44abb886..7f2f9a7e 100644 --- a/archiso/initcpio/hooks/archiso +++ b/archiso/initcpio/hooks/archiso @@ -63,7 +63,8 @@ _mnt_sfs() { local img_fullname="${img##*/}" local sfs_dev - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${copytoram}" = "y" ]; then msg -n ":: Copying squashfs image to RAM..." if ! cp -- "${img}" "/run/archiso/copytoram/${img_fullname}" ; then @@ -129,10 +130,12 @@ run_hook() { [ -z "${copytoram_size}" ] && copytoram_size="75%" [ -z "${archisobasedir}" ] && archisobasedir="arch" [ -z "${dm_snap_prefix}" ] && dm_snap_prefix="arch" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() [ -z "${archisodevice}" ] && archisodevice="/dev/disk/by-label/${archisolabel}" [ -z "${cow_spacesize}" ] && cow_spacesize="256M" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${cow_label}" ]; then cow_device="/dev/disk/by-label/${cow_label}" [ -z "${cow_persistent}" ] && cow_persistent="P" @@ -163,7 +166,8 @@ archiso_mount_handler() { fi fi - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${checksum}" = "y" ]; then if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sha512" ]; then msg -n ":: Self-test requested, please wait..." @@ -180,7 +184,8 @@ archiso_mount_handler() { fi fi - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${verify}" = "y" ]; then if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs.sig" ]; then msg -n ":: Signature verification requested, please wait..." diff --git a/archiso/initcpio/hooks/archiso_loop_mnt b/archiso/initcpio/hooks/archiso_loop_mnt index c32a544f..2c607f50 100644 --- a/archiso/initcpio/hooks/archiso_loop_mnt +++ b/archiso/initcpio/hooks/archiso_loop_mnt @@ -1,10 +1,12 @@ #!/bin/ash run_hook () { - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() [ -n "${img_label}" ] && img_dev="/dev/disk/by-label/${img_label}" [ -z "${img_flags}" ] && img_flags="defaults" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${img_dev}" ] && [ -n "${img_loop}" ]; then export mount_handler="archiso_loop_mount_handler" fi @@ -17,7 +19,8 @@ archiso_loop_mount_handler () { msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}" _mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r" "${img_flags}" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${copytoram}" != "y" ]; then readlink -f "${img_dev}" >> /run/archiso/used_block_devices fi diff --git a/archiso/initcpio/hooks/archiso_pxe_common b/archiso/initcpio/hooks/archiso_pxe_common index e31903e9..bf8e8838 100644 --- a/archiso/initcpio/hooks/archiso_pxe_common +++ b/archiso/initcpio/hooks/archiso_pxe_common @@ -11,7 +11,8 @@ run_hook () { if [ -n "${ip}" ]; then if [ -n "${BOOTIF}" ]; then bootif_mac="${BOOTIF#01-}" - # shellcheck disable=SC2169 # ash supports bash-like string replacment + # shellcheck disable=SC2169 + # ash supports bash-like string replacment bootif_mac="${bootif_mac//-/:}" for i in /sys/class/net/*/address; do read -r net_mac < "${i}" @@ -36,7 +37,8 @@ run_hook () { launch_interactive_shell fi - # shellcheck disable=SC1090 # ipconfig generates these files + # shellcheck disable=SC1090 + # ipconfig generates these files . /tmp/net-*.conf export pxeserver="${ROOTSERVER}" @@ -60,7 +62,8 @@ run_latehook () { if [ -n "${ip}" ]; then [ -z "${copy_resolvconf}" ] && copy_resolvconf="y" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${copytoram}" = "y" ]; then if [ -n "${bootif_dev}" ]; then ip addr flush dev "${bootif_dev}" diff --git a/archiso/initcpio/hooks/archiso_pxe_http b/archiso/initcpio/hooks/archiso_pxe_http index 5e55356d..bf2f5f40 100644 --- a/archiso/initcpio/hooks/archiso_pxe_http +++ b/archiso/initcpio/hooks/archiso_pxe_http @@ -1,7 +1,8 @@ #!/bin/ash run_hook() { - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${ip}" ] && [ -n "${archiso_http_srv}" ]; then # booting with http is always copy-to-ram, so set here to make sure @@ -24,7 +25,8 @@ _curl_get() { local _dst="${2}" msg ":: Downloading '${_url}'" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if ! curl -L -f -o "/run/archiso/httpspace/${archisobasedir}${_dst}/${_url##*/}" --create-dirs "${_url}"; then echo "ERROR: Downloading '${_url}'" echo " Falling back to interactive prompt" @@ -40,14 +42,17 @@ archiso_pxe_http_mount_handler () { mkdir -p "/run/archiso/httpspace" mount -t tmpfs -o size="${archiso_http_spc}",mode=0755 httpspace "/run/archiso/httpspace" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs" "/${arch}" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${checksum}" = "y" ]; then _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sha512" "/${arch}" fi - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ "${verify}" = "y" ]; then _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs.sig" "/${arch}" fi diff --git a/archiso/initcpio/hooks/archiso_pxe_nbd b/archiso/initcpio/hooks/archiso_pxe_nbd index ce93080c..4ccbcbf4 100644 --- a/archiso/initcpio/hooks/archiso_pxe_nbd +++ b/archiso/initcpio/hooks/archiso_pxe_nbd @@ -1,7 +1,8 @@ #!/bin/ash run_earlyhook() { - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${ip}" ] && [ -n "${archiso_nbd_srv}" ]; then # Module autoloading like with loop devices does not work, doing manually... modprobe nbd 2> /dev/null diff --git a/archiso/initcpio/hooks/archiso_pxe_nfs b/archiso/initcpio/hooks/archiso_pxe_nfs index 406541b3..be1e4c35 100644 --- a/archiso/initcpio/hooks/archiso_pxe_nfs +++ b/archiso/initcpio/hooks/archiso_pxe_nfs @@ -1,7 +1,8 @@ #!/bin/ash run_hook() { - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${ip}" ] && [ -n "${archiso_nfs_srv}" ]; then archiso_nfs_srv=$(eval echo "${archiso_nfs_srv}") @@ -15,7 +16,8 @@ archiso_nfs_mount_handler() { newroot="${1}" mkdir -p "/run/archiso/bootmnt" msg ":: Mounting '${archiso_nfs_srv}'" - # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() + # shellcheck disable=SC2154 + # defined via initcpio's parse_cmdline() if [ -n "${archiso_nfs_opt}" ]; then nfsmount -o "${archiso_nfs_opt}" "${archiso_nfs_srv}" "/run/archiso/bootmnt" mount_status=$? -- GitLab