Skip to content

Commit d77656c

Browse files
committed
chore: auto-format shell
Make `tox` -e do_format` and `tox -e check_format` enforce formatting of json and shell scripts. Remove unmaintained shell scripts. Update GH Actions. ``` shfmt --list --case-indent --indent=4 --space-redirects -w ``` Using v3.12.0
1 parent 4e3a920 commit d77656c

22 files changed

+677
-1411
lines changed

.github/workflows/ci-check-format.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ defaults:
1313
shell: sh -ex {0}
1414

1515
jobs:
16-
check_format:
16+
check_linters:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
env: [ruff, mypy, pylint, black, isort]
20+
env: [check_format]
2121
name: Check ${{ matrix.env }}
2222
runs-on: ubuntu-latest
2323
env:
@@ -30,6 +30,7 @@ jobs:
3030
run: |
3131
sudo DEBIAN_FRONTEND=noninteractive apt-get -qy update
3232
sudo DEBIAN_FRONTEND=noninteractive apt-get -qy install tox
33+
sudo snap install shfmt
3334
3435
- name: Print version
3536
run: python3 --version
@@ -39,20 +40,12 @@ jobs:
3940
# matrix env: not to be confused w/environment variables or testenv
4041
TOXENV: ${{ matrix.env }}
4142
run: tox
42-
schema-format:
43-
strategy:
44-
fail-fast: false
45-
name: Check json format
46-
runs-on: ubuntu-latest
47-
steps:
48-
- name: Checkout
49-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5043

51-
- name: Test format
44+
- name: Formatting check failed
45+
if: failure()
5246
run: |
53-
tools/check_json_format.sh cloudinit/config/schemas/schema-cloud-config-v1.json
54-
tools/check_json_format.sh cloudinit/config/schemas/schema-network-config-v1.json
55-
tools/check_json_format.sh cloudinit/config/schemas/versions.schema.cloud-config.json
47+
echo "[31mResolve formatting errors with `tox -e do_format` (requires shfmt to format shell).\e[0m"
48+
echo "[31mFor mypy and pylint failures see the warnings above.\e[0m"
5649
5750
doc:
5851
strategy:

Makefile

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,18 @@ distro ?= redhat
99

1010
GENERATOR_F=./systemd/cloud-init-generator
1111
DS_IDENTIFY=./tools/ds-identify
12-
BENCHMARK=./tools/benchmark.sh
1312

1413

1514
all: check
1615

1716
check: test
1817

19-
style-check: lint
20-
21-
lint:
22-
@$(CWD)/tools/run-lint
23-
2418
unittest: clean_pyc
2519
$(PYTHON) -m pytest -v tests/unittests cloudinit
2620

2721
render-template:
2822
$(PYTHON) ./tools/render-template --variant=$(VARIANT) $(FILE) $(subst .tmpl,,$(FILE))
2923

30-
# from systemd-generator(7) regarding generators:
31-
# "We do recommend C code however, since generators are executed
32-
# synchronously and hence delay the entire boot if they are slow."
33-
#
34-
# Our generator is a shell script. Make it easy to measure the
35-
# generator. This should be monitored for performance regressions
36-
benchmark-generator: FILE=$(GENERATOR_F).tmpl
37-
benchmark-generator: VARIANT="benchmark"
38-
benchmark-generator: export ITER=$(NUM_ITER)
39-
benchmark-generator: render-template
40-
$(BENCHMARK) $(GENERATOR_F)
41-
42-
benchmark-ds-identify: export ITER=$(NUM_ITER)
43-
benchmark-ds-identify:
44-
$(BENCHMARK) $(DS_IDENTIFY)
45-
4624
ci-deps-ubuntu:
4725
@$(PYTHON) $(CWD)/tools/read-dependencies --distro ubuntu --test-distro
4826

@@ -103,13 +81,6 @@ deb-src:
10381
doc:
10482
tox -e doc
10583

106-
fmt:
107-
tox -e do_format && tox -e check_format
108-
109-
fmt-tip:
110-
tox -e do_format_tip && tox -e check_format_tip
111-
112-
113-
.PHONY: all check test lint clean rpm srpm deb deb-src clean_pyc
114-
.PHONY: unittest style-check render-template benchmark-generator
84+
.PHONY: all check test clean rpm srpm deb deb-src clean_pyc
85+
.PHONY: unittest render-template
11586
.PHONY: clean_pytest clean_packaging clean_release doc

tools/Z99-cloud-locale-test.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
# (c) 2012, Canonical Group, Ltd.
77
#
88
# This file is part of cloud-init. See LICENSE file for license information.
9-
9+
1010
# Purpose: Detect invalid locale settings and inform the user
1111
# of how to fix them.
1212

1313
locale_warn() {
14-
command -v local >/dev/null && local _local="local" ||
14+
command -v local > /dev/null && local _local="local" ||
1515
typeset _local="typeset"
1616

1717
$_local bad_names="" bad_lcs="" key="" val="" var="" vars="" bad_kv=""
@@ -27,13 +27,14 @@ locale_warn() {
2727
# locale: Cannot set LC_SOMETHING to default locale
2828
while read -r w1 w2 w3 w4 remain; do
2929
case "$w1" in
30-
locale:) bad_names="${bad_names} ${w4}";;
30+
locale:) bad_names="${bad_names} ${w4}" ;;
3131
*)
3232
key=${w1%%=*}
3333
val=${w1#*=}
3434
val=${val#\"}
3535
val=${val%\"}
36-
vars="${vars} $key=$val";;
36+
vars="${vars} $key=$val"
37+
;;
3738
esac
3839
done
3940
for bad in $bad_names; do
@@ -93,7 +94,7 @@ locale_warn() {
9394
printf "_____________________________________________________________________\n\n"
9495

9596
# only show the message once
96-
: > ~/.cloud-locale-test.skip 2>/dev/null || :
97+
: > ~/.cloud-locale-test.skip 2> /dev/null || :
9798
}
9899

99100
[ -f ~/.cloud-locale-test.skip -o -f /var/lib/cloud/instance/locale-check.skip ] ||

tools/Z99-cloudinit-warnings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Purpose: show user warnings on login.
55

66
cloud_init_warnings() {
7-
command -v local >/dev/null && local _local="local" ||
7+
command -v local > /dev/null && local _local="local" ||
88
typeset _local="typeset"
99
$_local warning="" idir="/var/lib/cloud/instance" n=0
1010
$_local warndir="$idir/warnings"
@@ -16,7 +16,7 @@ cloud_init_warnings() {
1616
for warning in "$warndir"/*; do
1717
[ -f "$warning" ] || continue
1818
cat "$warning"
19-
n=$((n+1))
19+
n=$((n + 1))
2020
done
2121
[ $n -eq 0 ] && return 0
2222
echo ""

tools/benchmark.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

tools/build-on-freebsd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
set -eux
1010

11-
fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
11+
fail() {
12+
echo "FAILED:" "$@" 1>&2
13+
exit 1
14+
}
1215

1316
PYTHON="${PYTHON:-python3}"
1417
if [ ! $(which ${PYTHON}) ]; then

tools/build-on-netbsd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/sh
22

3-
fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
3+
fail() {
4+
echo "FAILED:" "$@" 1>&2
5+
exit 1
6+
}
47

58
PYTHON="${PYTHON:-python3}"
69
if [ ! $(which ${PYTHON}) ]; then

tools/build-on-openbsd

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/sh
22

3-
fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
3+
fail() {
4+
echo "FAILED:" "$@" 1>&2
5+
exit 1
6+
}
47

58
PYTHON=${PYTHON:-python3}
6-
if ! command -v ${PYTHON} >/dev/null 2>&1; then
9+
if ! command -v ${PYTHON} > /dev/null 2>&1; then
710
echo "Please install python first."
811
exit 1
912
fi
@@ -27,10 +30,10 @@ pkgs="
2730
wget
2831
"
2932

30-
[ -f $depschecked ] || echo "Installing the following packages: $pkgs"; output=$(pkg_add -zI $pkgs 2>&1)
31-
33+
[ -f $depschecked ] || echo "Installing the following packages: $pkgs"
34+
output=$(pkg_add -zI $pkgs 2>&1)
3235

33-
if echo "$output" | grep -q -e "Can't find" -e "Ambiguous"; then
36+
if echo "$output" | grep -q -e "Can't find" -e "Ambiguous"; then
3437
echo "Failed to find or install one or more packages"
3538
echo "Failed Package(s):"
3639
echo "$output"

tools/check_json_format.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

tools/cloud-init-hotplugd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ PIPE="/run/cloud-init/share/hook-hotplug-cmd"
1414
[ -p $PIPE ] || mkfifo -m700 $PIPE
1515

1616
while true; do
17-
# shellcheck disable=SC2162
18-
if read args < $PIPE; then
19-
# shellcheck disable=SC2086
20-
/usr/bin/cloud-init devel hotplug-hook $args
21-
fi
17+
# shellcheck disable=SC2162
18+
if read args < $PIPE; then
19+
# shellcheck disable=SC2086
20+
/usr/bin/cloud-init devel hotplug-hook $args
21+
fi
2222
done

0 commit comments

Comments
 (0)