diff --git a/.github/workflows/bot-ci-failure.yml b/.github/workflows/bot-ci-failure.yml index e8ba46e1..f3c28b03 100644 --- a/.github/workflows/bot-ci-failure.yml +++ b/.github/workflows/bot-ci-failure.yml @@ -12,7 +12,7 @@ permissions: contents: read concurrency: - group: ci-failure-${{ github.repository }}-${{ github.event.workflow_run.pull_requests[0].number || format('{0}:{1}', github.event.workflow_run.head_repository.full_name, github.event.workflow_run.head_branch) }} + group: ci-failure-${{ github.repository }}-${{ github.event.workflow_run.pull_requests[0].number || format('{0}:{1}', github.event.workflow_run.head_repository.full_name, github.event.workflow_run.head_branch) }} cancel-in-progress: true jobs: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5335eada..9fdff8b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,12 +24,15 @@ jobs: run: | sudo curl -sL -o /bin/hadolint "https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64" sudo chmod +x /bin/hadolint + sudo curl -sL -o /usr/local/bin/shfmt "https://github.com/mvdan/sh/releases/download/v3.13.1/shfmt_v3.13.1_linux_amd64" + sudo chmod +x /usr/local/bin/shfmt echo "127.0.0.1 dashboard.openwisp.org api.openwisp.org" | sudo tee -a /etc/hosts # disable metric collection during builds sed -i 's/METRIC_COLLECTION=True/METRIC_COLLECTION=False/' .env # ERROR: Cannot uninstall urllib3 2.0.7, RECORD file not found. Hint: The package was installed by debian. sudo apt remove python3-urllib3 python3-typing-extensions sudo pip3 install -r requirements-test.txt + sudo npm install -g prettier - name: QA checks run: ./run-qa-checks diff --git a/deploy/auto-install.sh b/deploy/auto-install.sh index f0866163..cb1ea734 100755 --- a/deploy/auto-install.sh +++ b/deploy/auto-install.sh @@ -38,10 +38,10 @@ check_status() { # Returns true if the backup .env exists and contains app secrets has_backup_with_secrets() { - [[ -f "$ENV_BACKUP" ]] && \ - [[ -n "$(get_env "DB_USER" "$ENV_BACKUP")" ]] && \ - [[ -n "$(get_env "DB_PASS" "$ENV_BACKUP")" ]] && \ - [[ -n "$(get_env "DJANGO_SECRET_KEY" "$ENV_BACKUP")" ]] + [[ -f "$ENV_BACKUP" ]] && + [[ -n "$(get_env "DB_USER" "$ENV_BACKUP")" ]] && + [[ -n "$(get_env "DB_PASS" "$ENV_BACKUP")" ]] && + [[ -n "$(get_env "DJANGO_SECRET_KEY" "$ENV_BACKUP")" ]] } error_msg() { diff --git a/docs/developer/instructions.rst b/docs/developer/instructions.rst index 9b2aba0a..faa6aa98 100644 --- a/docs/developer/instructions.rst +++ b/docs/developer/instructions.rst @@ -91,8 +91,9 @@ Run Quality Assurance Checks ---------------------------- We use `shfmt `__ to format shell -scripts and `hadolint `__ to -lint Dockerfiles. +scripts, `hadolint `__ to +lint Dockerfiles, and `prettier `__ to check +formatting of YAML, JSON, CSS, JavaScript, and Markdown files. To format all files, run: diff --git a/images/common/init_command.sh b/images/common/init_command.sh index b5d67895..5ee4a25a 100644 --- a/images/common/init_command.sh +++ b/images/common/init_command.sh @@ -66,7 +66,7 @@ elif [ "$MODULE_NAME" = 'nginx' ]; then # sentinel from the generated nginx.conf. export NGINX_WORKER_RLIMIT_NOFILE="${NGINX_WORKER_RLIMIT_NOFILE:-__UNSET__}" envsubst /etc/nginx/nginx.conf - # Remove incomplete worker_rlimit_nofile directives if env var is unset or empty + # Remove incomplete worker_rlimit_nofile directives if env var is unset or empty sed -i '/__UNSET__/d; /^worker_rlimit_nofile *$/d; /^[[:space:]]*$/d' /etc/nginx/nginx.conf envsubst_create_config /etc/nginx/openwisp.internal.template.conf internal INTERNAL if [ "$SSL_CERT_MODE" = 'Yes' ]; then diff --git a/images/common/openwisp/asgi.py b/images/common/openwisp/asgi.py index 4ad7ea2f..29aa807c 100644 --- a/images/common/openwisp/asgi.py +++ b/images/common/openwisp/asgi.py @@ -23,7 +23,7 @@ routes.extend(get_controller_routes()) if env_bool(os.environ.get("USE_OPENWISP_TOPOLOGY")): - from openwisp_network_topology.routing import ( # noqa: E402 + from openwisp_network_topology.routing import ( websocket_urlpatterns as network_topology_routes, ) diff --git a/images/common/utils.sh b/images/common/utils.sh index d75ecb6b..c2f21ec4 100644 --- a/images/common/utils.sh +++ b/images/common/utils.sh @@ -1,10 +1,10 @@ #!/bin/sh -function init_conf { +init_conf() { default_psql_vars } -function default_psql_vars { +default_psql_vars() { # Set database variable values in default PG # vars to use psql command without passing additional # arguments. @@ -19,7 +19,7 @@ function default_psql_vars { export PGSSLROOTCERT=$DB_SSLROOTCERT } -function start_uwsgi { +start_uwsgi() { # If a user supplies custom uWSGI configuration, then # due to lack of write permissions this command will fail. # Hence, OR (||) operator is used here to continue execution @@ -28,7 +28,7 @@ function start_uwsgi { uwsgi --ini uwsgi.ini } -function create_prod_certs { +create_prod_certs() { if [ ! -f /etc/letsencrypt/live/${DASHBOARD_DOMAIN}/privkey.pem ]; then certbot certonly --standalone --noninteractive --agree-tos \ --rsa-key-size 4096 \ @@ -41,7 +41,7 @@ function create_prod_certs { fi } -function create_dev_certs { +create_dev_certs() { # Ensure required directories exist mkdir -p /etc/letsencrypt/live/${DASHBOARD_DOMAIN}/ mkdir -p /etc/letsencrypt/live/${API_DOMAIN}/ @@ -60,7 +60,7 @@ function create_dev_certs { fi } -function nginx_dev { +nginx_dev() { envsubst_create_config /etc/nginx/openwisp.ssl.template.conf https DOMAIN ssl_http_behaviour create_dev_certs @@ -69,7 +69,7 @@ function nginx_dev { nginx -g 'daemon off;' } -function nginx_prod { +nginx_prod() { create_prod_certs ssl_http_behaviour envsubst_create_config /etc/nginx/openwisp.ssl.template.conf https DOMAIN @@ -77,7 +77,7 @@ function nginx_prod { echo "0 3 * * 7 ${CMD} &>> /etc/nginx/log/crontab.log" | crontab - } -function wait_nginx_services { +wait_nginx_services() { # Wait for nginx to start up and then check # if the openwisp-dashboard is reachable. echo "Waiting for dashboard to become available..." @@ -96,15 +96,15 @@ function wait_nginx_services { set -e # Restore previous error setting. } -function ssl_http_behaviour { - if [ "$NGINX_HTTP_ALLOW" == "True" ]; then +ssl_http_behaviour() { + if [ "$NGINX_HTTP_ALLOW" = "True" ]; then envsubst_create_config /etc/nginx/openwisp.template.conf http DOMAIN else envsubst /etc/nginx/conf.d/openwisp.http.conf fi } -function envsubst_create_config { +envsubst_create_config() { # Creates nginx configurations files for dashboard # and api instances. for application in DASHBOARD API; do @@ -117,7 +117,7 @@ function envsubst_create_config { done } -function postfix_config { +postfix_config() { # This function is used to configure the # postfix instance. @@ -203,7 +203,7 @@ get_redis_value() { echo -en "GET $key\r\n" | nc redis 6379 | awk 'NR==2 {gsub(/\r/, ""); print}' } -function openvpn_preconfig { +openvpn_preconfig() { mkdir -p /dev/net if [ ! -c /dev/net/tun ]; then mknod /dev/net/tun c 10 200 @@ -217,7 +217,7 @@ function openvpn_preconfig { fi } -function openvpn_config { +openvpn_config() { # Fectch UUID and Key of the default VPN only if they # are not already set. The user may override the UUID and Key # by setting them in the environment variables to use deploy @@ -229,28 +229,29 @@ function openvpn_config { fi } -function openvpn_config_checksum { - export OFILE=$(curl --silent --insecure \ - ${API_INTERNAL}/controller/vpn/checksum/$UUID/?key=$KEY) - export NFILE=$(cat checksum) +openvpn_config_checksum() { + OFILE=$(curl --silent --insecure \ + "${API_INTERNAL}/controller/vpn/checksum/${UUID}/?key=${KEY}") + export OFILE + NFILE=$(cat checksum) + export NFILE } -function openvpn_config_download { - curl --silent --retry 10 --retry-delay 5 --retry-max-time 300\ - --insecure --output vpn.tar.gz \ - ${API_INTERNAL}/controller/vpn/download-config/$UUID/?key=$KEY +openvpn_config_download() { + curl --silent --retry 10 --retry-delay 5 --retry-max-time 300 --insecure --output vpn.tar.gz \ + "${API_INTERNAL}/controller/vpn/download-config/${UUID}/?key=${KEY}" curl --silent --insecure --output checksum \ - ${API_INTERNAL}/controller/vpn/checksum/$UUID/?key=$KEY + "${API_INTERNAL}/controller/vpn/checksum/${UUID}/?key=${KEY}" tar xzf vpn.tar.gz - chmod 600 *.pem + chmod 600 ./*.pem } -function crl_download { +crl_download() { curl --silent --insecure --output revoked.crl \ - ${DASHBOARD_INTERNAL}/admin/pki/ca/x509/ca/${CA_UUID}.crl + "${DASHBOARD_INTERNAL}/admin/pki/ca/x509/ca/${CA_UUID}.crl" } -function init_send_network_topology { +init_send_network_topology() { if [ -z "$TOPOLOGY_UUID" ]; then export TOPOLOGY_UUID=$(get_redis_value "default_openvpn_topology_uuid") export TOPOLOGY_KEY=$(get_redis_value "default_openvpn_topology_key") diff --git a/images/openwisp_dashboard/openvpn.json b/images/openwisp_dashboard/openvpn.json index 68787bec..5f949720 100644 --- a/images/openwisp_dashboard/openvpn.json +++ b/images/openwisp_dashboard/openvpn.json @@ -12,14 +12,14 @@ "comp_lzo": "no", "auth": "SHA1", "data_ciphers": [ - { - "cipher": "AES-128-GCM", - "optional": false - }, - { - "cipher": "none", - "optional": false - } + { + "cipher": "AES-128-GCM", + "optional": false + }, + { + "cipher": "none", + "optional": false + } ], "data_ciphers_fallback": "AES-128-GCM", "cipher": "AES-128-GCM", diff --git a/run-qa-checks b/run-qa-checks index 15421f68..1a62be5d 100755 --- a/run-qa-checks +++ b/run-qa-checks @@ -2,19 +2,15 @@ set -e -# will be 1 by default when run through github actions -CI=${CI:-false} - echo '' echo 'Python file QA checks...' -openwisp-qa-check --skip-checkmigrations +openwisp-qa-check --skip-checkmigrations --jslinter --csslinter -if [ "$CI" = "false" ]; then - echo 'Shell scripts QA checks ...' - # check shell scripts formatting - sh_files=$(shfmt -f .) - shfmt -d . -fi +echo '' +echo 'Shell scripts QA checks ...' +# check shell scripts formatting +sh_files=$(shfmt -f .) +shfmt -d . echo '' echo 'Dockerfile QA checks...'