From 47d4ff3750d731df5af1c73baccfb5c5095c0772 Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Mon, 18 Nov 2024 16:43:07 +0100 Subject: [PATCH] Add linter workflow --- .github/workflows/cd.yaml | 2 +- .github/workflows/ci.yaml | 4 +- .github/workflows/docker_release.yml | 10 +-- .github/workflows/lint.yml | 81 +++++++++++++++++++++++++ .markdownlint.yaml | 7 +++ .yamllint | 6 ++ README.md | 31 +++++++--- minecraft-ftb/data/Dockerfile | 4 +- minecraft-ftb/data/docker-entrypoint.sh | 23 ++++--- 9 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .markdownlint.yaml create mode 100644 .yamllint diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 0001508..ea01e2a 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -1,6 +1,6 @@ name: CD -on: +on: # yamllint disable-line rule:truthy push: tags: - 'v*' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 88e0d8a..69c2f86 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: CI -on: +on: # yamllint disable-line rule:truthy push: branches: - master @@ -16,7 +16,7 @@ env: jobs: build: - name: CI + name: Build runs-on: ubuntu-latest services: diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml index 0829410..c4b3439 100644 --- a/.github/workflows/docker_release.yml +++ b/.github/workflows/docker_release.yml @@ -4,7 +4,7 @@ permissions: contents: read packages: write -on: +on: # yamllint disable-line rule:truthy workflow_call: inputs: registry: @@ -55,8 +55,8 @@ jobs: steps: - name: Prepare run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + platform="${{ matrix.platform }}" + echo "PLATFORM_PAIR=${platform//\//-}" >> "${GITHUB_ENV}" - name: Checkout uses: actions/checkout@v4 @@ -158,5 +158,5 @@ jobs: - name: Create Manifest List and Push working-directory: /tmp/digests run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + docker buildx imagetools create "$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}")" \ + "$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..eb8d070 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,81 @@ +name: CI + +on: # yamllint disable-line rule:truthy + pull_request: + types: [opened, synchronize, reopened] + +jobs: + hadolint: + name: Hadolint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint + uses: reviewdog/action-hadolint@v1 + with: + reporter: github-pr-check + filter_mode: nofilter + reviewdog_flags: '-fail-level=any' + + shellcheck: + name: ShellCheck + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint + uses: reviewdog/action-shellcheck@v1 + with: + reporter: github-pr-check + filter_mode: nofilter + reviewdog_flags: '-fail-level=any' + + markdownlint: + name: MarkdownLint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint + uses: reviewdog/action-markdownlint@v0 + with: + reporter: github-pr-check + filter_mode: nofilter + reviewdog_flags: '-fail-level=any' + + yamllint: + name: YamlLint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint + uses: reviewdog/action-yamllint@v1 + with: + reporter: github-pr-check + filter_mode: nofilter + reviewdog_flags: '-fail-level=any' + + actionlint: + name: ActionLint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Lint + uses: reviewdog/action-actionlint@v1 + with: + reporter: github-pr-check + filter_mode: nofilter + reviewdog_flags: '-fail-level=any' diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..621cc75 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,7 @@ +# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md013.md +MD013: + # Number of characters + line_length: 140 + +# MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md028.md +MD028: false diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..a3a3172 --- /dev/null +++ b/.yamllint @@ -0,0 +1,6 @@ +rules: + # https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_start + document-start: disable + line-length: + max: 140 + allow-non-breakable-words: true diff --git a/README.md b/README.md index a0d18d9..24d8887 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Docker Minecraft FTB -A Docker image developed to launch Minecraft [FTB](https://www.feed-the-beast.com/) Modpack servers as safely, quickly and easily as possible. +A Docker image developed to launch Minecraft [FTB](https://www.feed-the-beast.com/) Modpack servers as safely, quickly and easily as +possible. ## Features @@ -50,13 +51,16 @@ services: ## Notes > [!WARNING] -> The server process does not shut down gracefully, if no TTY is present. Please pass the `--tty`/`-t` switch (Docker) or use `tty: true` (Docker Compose). +> The server process does not shut down gracefully, if no TTY is present. Please pass the `--tty`/`-t` switch (Docker) or use `tty: true` +> (Docker Compose). > [!WARNING] -> It is strongly recommended to set the `stop-timeout` (Docker) / `stop_grace_period` (Docker Compose) to at least `60` seconds to avoid data loss when stopping the container. +> It is strongly recommended to set the `stop-timeout` (Docker) / `stop_grace_period` (Docker Compose) to at least `60` seconds to avoid +> data loss when stopping the container. > [!NOTE] -> It is recommended to pass the `--interactive`/`-i` switch (Docker) or use `stdin_open: true` (Docker Compose) to be able to use the server console after attaching to the container. +> It is recommended to pass the `--interactive`/`-i` switch (Docker) or use `stdin_open: true` (Docker Compose) to be able to use the +> server console after attaching to the container. ## Environment @@ -65,7 +69,9 @@ services: The FTB modpack ID (*required*). > [!NOTE] -> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the [Direwolf20 1.21 modpack](https://www.feed-the-beast.com/modpacks/126-ftb-presents-direwolf20-121) has the ID `126` and the latest version, as of today, is `12599`. +> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the +> [Direwolf20 1.21 modpack](https://www.feed-the-beast.com/modpacks/126-ftb-presents-direwolf20-121) has the ID `126` and the latest +> version, as of today, is `12599`. ### `FTB_MODPACK_VERSION_ID` @@ -80,7 +86,8 @@ Default: Latest version of the configured modpack. Set `1` to automatically agree to the [Mojang EULA](https://account.mojang.com/documents/minecraft_eula). -This option enables unattended installation. Otherwise, an interactive session must be used to accept the EULA after installation, or the `eula.txt` must be edited manually and the container restarted. +This option enables unattended installation. Otherwise, an interactive session must be used to accept the EULA after installation, or the +`eula.txt` must be edited manually and the container restarted. Default: `0`. @@ -88,9 +95,11 @@ Default: `0`. Optional, user-defined JVM arguments. -Use the `-Xms` switch to configure the minimum amount of memory used by the JVM. `-Xms1G` sets the minimum amount of memory to 1 GB. The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes. +Use the `-Xms` switch to configure the minimum amount of memory used by the JVM. `-Xms1G` sets the minimum amount of memory to 1 GB. +The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes. -Use the `-Xmx` switch to configure the maximum amount of memory used by the JVM. `-Xms4G` sets the maximum amount of memory to 4 GB. The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes. +Use the `-Xmx` switch to configure the maximum amount of memory used by the JVM. `-Xms4G` sets the maximum amount of memory to 4 GB. +The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes. To specify multiple arguments, combine them with spaces: `-Xms1G -Xmx4G`. @@ -103,7 +112,8 @@ Default: *none* Set `1` to automatically update the modpack when the container is started. -If `FTB_MODPACK_VERSION_ID` is set, the configured version number is used, otherwise the latest version of the modpack is determined automatically. +If `FTB_MODPACK_VERSION_ID` is set, the configured version number is used, otherwise the latest version of the modpack is determined +automatically. Default: `0` @@ -112,7 +122,8 @@ Default: `0` Set `1` to force a reinstallation of the modpack when the container is started. > [!WARNING] -> This option should only be used in special cases, as constantly reinstalling the modpack significantly slows down the start of the container. +> This option should only be used in special cases, as constantly reinstalling the modpack significantly slows down the start of the +> container. Default: `0` diff --git a/minecraft-ftb/data/Dockerfile b/minecraft-ftb/data/Dockerfile index b67f5e6..e5b0419 100644 --- a/minecraft-ftb/data/Dockerfile +++ b/minecraft-ftb/data/Dockerfile @@ -5,12 +5,13 @@ FROM debian:bookworm-slim ENV FTB_MODPACK_ID=0 ENV FTB_MODPACK_VERSION_ID=0 ENV ACCEPT_MOJANG_EULA=0 -ENV USER_JVM_ARGS= +ENV USER_JVM_ARGS="" ENV AUTO_UPDATE=0 ENV FORCE_REINSTALL=0 # Set up runtime dependencies +# hadolint ignore=DL3008 RUN set -eux; \ apt-get update; \ apt-get install -y --no-install-recommends \ @@ -22,6 +23,7 @@ RUN set -eux; \ # Set up container user +# hadolint ignore=DL3008 RUN set -eux; \ groupadd --gid 99 --system minecraft; \ useradd \ diff --git a/minecraft-ftb/data/docker-entrypoint.sh b/minecraft-ftb/data/docker-entrypoint.sh index e6b369f..988b42f 100755 --- a/minecraft-ftb/data/docker-entrypoint.sh +++ b/minecraft-ftb/data/docker-entrypoint.sh @@ -10,11 +10,11 @@ ansi_g="\e[92m" ansi_r="\e[31m" echoerr() { - echo -e "${ansi_r}ERROR:${ansi_rst} $@" 1>&2; + echo -e "${ansi_r}ERROR:${ansi_rst} $*" 1>&2; } echoinfo() { - echo -e "${ansi_b}INFO:${ansi_rst} $@" + echo -e "${ansi_b}INFO:${ansi_rst} $*" } check_environment() { @@ -51,8 +51,8 @@ fetch_modpack_info() { local response response=$(curl --fail --connect-timeout 30 --max-time 30 --no-progress-meter "https://api.modpacks.ch/public/modpack/$1") || exit $? - if [ -z "${response}" ] || [ $(echo "${response}" | jq -r '.status') != "success" ]; then - echoerr "Failed to fetch modpack info. Please check if the modpack id [${ansi_green}$1${ansi_rst}] is correct." + if [ -z "${response}" ] || [ "$(echo "${response}" | jq -r '.status')" != "success" ]; then + echoerr "Failed to fetch modpack info. Please check if the modpack id [${ansi_g}$1${ansi_rst}] is correct." echoerr "$(echo "${response}" | jq -r '.message')" return 1 fi @@ -63,6 +63,7 @@ fetch_modpack_info() { # $1 = modpack info JSON payload # rt = latest modpack version id query_latest_version_id() { + # shellcheck disable=SC2155 local result=$(echo "$1" | jq -r '[.versions | sort_by(.updated) | reverse | .[] | select(.type == "Release" and .private == false) | .id][0]') if [ -z "${result}" ]; then @@ -77,10 +78,11 @@ query_latest_version_id() { # $2 = modpack version id # rt = modpack version info JSON payload query_version_info() { + # shellcheck disable=SC2155 local result=$(echo "$1" | jq -r ".versions[] | select(.id == $2)") if [ -z "${result}" ]; then - echoerr "Failed to query version info. Please check if the modpack version id [${ansi_green}$2${ansi_rst}] is correct." + echoerr "Failed to query version info. Please check if the modpack version id [${ansi_g}$2${ansi_rst}] is correct." return 1 fi @@ -132,13 +134,13 @@ patch_start_script() { output+="${line}\n" done < start.sh - if [ ! success ]; then + if [ ! "${success}" ]; then echoerr "Failed to patch 'start.sh' script." echoerr "Please open an issue here: https://github.com/flobernd/docker-minecraft-ftb" return 1 fi - printf "${output}" > /var/lib/minecraft/start.sh + printf "%s" "${output}" > /var/lib/minecraft/start.sh } update_user_jvm_args() { @@ -146,7 +148,7 @@ update_user_jvm_args() { exit 0 fi - printf "# Generated by "docker-minecraft-ftb"; DO NOT EDIT.\n\n" > /var/lib/minecraft/user_jvm_args.txt + printf "# Generated by \"docker-minecraft-ftb\"; DO NOT EDIT.\n\n" > /var/lib/minecraft/user_jvm_args.txt printf "%s" "${USER_JVM_ARGS}" | xargs -n 1 printf "%s\n" >> /var/lib/minecraft/user_jvm_args.txt } @@ -171,7 +173,7 @@ if [ "$1" = "/var/lib/minecraft/start.sh" ]; then fi if [ "${local_pack_id}" -ne "${target_pack_id}" ]; then - echoerr "A modpack is already installed, but the modpack id [${ansi_green}${local_pack_id}${ansi_rst}] does not " \ + echoerr "A modpack is already installed, but the modpack id [${ansi_g}${local_pack_id}${ansi_rst}] does not " \ "match the configured modpack id [${ansi_green}${target_pack_id}${ansi_rst}]." exit 1 fi @@ -208,7 +210,8 @@ if [ "$1" = "/var/lib/minecraft/start.sh" ]; then if [ "${local_pack_id}" -eq 0 ] || [ "${FORCE_REINSTALL}" == 1 ]; then echo -e "Installing modpack version '${ansi_b}${target_version_name}${ansi_rst}' [${ansi_g}${target_version_id}${ansi_rst}]" - if [ "${FORCE_REINSTALL}" != 1 ] && [ $(ls -A . | wc -l) -ne 0 ]; then + # shellcheck disable=SC2012 + if [ "${FORCE_REINSTALL}" != 1 ] && [ "$(ls -A . | wc -l)" -ne 0 ]; then echoerr "The destination directory is not empty. Installing the modpack could lead to data loss." echoerr "To continue, set the 'FORCE_REINSTALL' environment variable to '1' and retry." exit 1