From 9f89cedd06571859a565a787de8b3e2d5744ec2b Mon Sep 17 00:00:00 2001 From: Yasunori Fujie Date: Thu, 26 Oct 2023 02:26:49 +0900 Subject: [PATCH] Follow the latest plugin-template --- .editorconfig | 8 +- .github/dependabot.yml | 6 + .github/workflows/build.yml | 10 +- .github/workflows/lint.yml | 31 ++-- .github/workflows/release.yml | 6 +- .github/workflows/semantic-pr.yml | 18 +++ .tool-versions | 4 +- lib/utils.bash | 258 +++++++++++++++--------------- scripts/format.bash | 4 + scripts/lint.bash | 9 ++ scripts/shellcheck.bash | 4 - scripts/shfmt.bash | 3 - 12 files changed, 191 insertions(+), 170 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/semantic-pr.yml create mode 100755 scripts/format.bash create mode 100755 scripts/lint.bash delete mode 100755 scripts/shellcheck.bash delete mode 100755 scripts/shfmt.bash diff --git a/.editorconfig b/.editorconfig index 1923d41..16bec6a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,8 +1,12 @@ root = true [*] -indent_style = space -indent_size = 2 +indent_style = tab +end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[*.{md,yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c2eb22..f38c425 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,18 +21,12 @@ jobs: - 4.3 runs-on: ${{ matrix.os }} steps: - - name: Set output - id: vars - run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/} - - name: Install GPG keys - run: gpg --recv-keys 96B047156338B6D4 80CB727A20C79BB2 + run: gpg -v --recv-keys 96B047156338B6D4 80CB727A20C79BB2 - name: asdf_plugin_test - uses: asdf-vm/actions/plugin-test@v1 + uses: asdf-vm/actions/plugin-test@v3 with: command: make --version - gitref: ${{ steps.vars.outputs.short_ref }} - version: ${{ matrix.version }} env: MAKE_PRINT_BUILD_LOG: "yes" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 09420a5..f45659d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,29 +7,18 @@ on: pull_request: jobs: - shellcheck: + lint: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: asdf-vm/actions/install@v3 + - run: scripts/lint.bash - - name: Install asdf dependencies - uses: asdf-vm/actions/install@v1 - - - name: Run ShellCheck - run: scripts/shellcheck.bash - - shellfmt: + actionlint: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install asdf dependencies - uses: asdf-vm/actions/install@v1 - - - name: List file to shfmt - run: shfmt -f . - - - name: Run shfmt - run: scripts/shfmt.bash + - uses: actions/checkout@v4 + - name: Check workflow files + uses: docker://rhysd/actionlint:1.6.23 + with: + args: -color diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a118ee..454ce7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,10 +5,14 @@ on: branches: - main +permissions: + contents: write + pull-requests: write + jobs: release-please: runs-on: ubuntu-latest steps: - - uses: GoogleCloudPlatform/release-please-action@v2 + - uses: GoogleCloudPlatform/release-please-action@v3 with: release-type: simple diff --git a/.github/workflows/semantic-pr.yml b/.github/workflows/semantic-pr.yml new file mode 100644 index 0000000..7b39bf7 --- /dev/null +++ b/.github/workflows/semantic-pr.yml @@ -0,0 +1,18 @@ +name: Lint + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + semantic-pr: + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5.3.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + validateSingleCommit: true diff --git a/.tool-versions b/.tool-versions index b4cac19..3d11f88 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -shellcheck 0.7.1 -shfmt 3.3.0 +shellcheck 0.9.0 +shfmt 3.6.0 diff --git a/lib/utils.bash b/lib/utils.bash index 6b0eda4..d98447c 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -16,159 +16,159 @@ MAKE_BUILD_OPTIONS="${MAKE_BUILD_OPTIONS:---with-guile=no}" current_script_path=${BASH_SOURCE[0]} # shellcheck disable=SC2046 plugin_dir=$( - cd $(dirname "$(dirname "$current_script_path")") - pwd + cd $(dirname "$(dirname "$current_script_path")") + pwd ) fail() { - echo -e "asdf-$TOOL_NAME: $*" - exit 1 + echo -e "asdf-$TOOL_NAME: $*" + exit 1 } curl_opts=(-fsSL) sort_versions() { - sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | - LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' + sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | + LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' } list_gnu_releases() { - while read -r line; do - if [[ "$line" =~ ${GNU_TOOL}-([1-9]+\.[0-9]+(:?\.[0-9]+)*)\.tar\.gz\.sig ]]; then - echo "${BASH_REMATCH[1]}" - fi - done < <(curl "${curl_opts[@]}" ${GNU_FTP}/${GNU_TOOL}/) | uniq + while read -r line; do + if [[ "$line" =~ ${GNU_TOOL}-([1-9]+\.[0-9]+(:?\.[0-9]+)*)\.tar\.gz\.sig ]]; then + echo "${BASH_REMATCH[1]}" + fi + done < <(curl "${curl_opts[@]}" ${GNU_FTP}/${GNU_TOOL}/) | uniq } list_all_versions() { - list_gnu_releases + list_gnu_releases } download_release() { - local version filename url sig_url gnu_keyring gpg_command detail - version="$1" - filename="$2" - - url="${GNU_FTP}/${GNU_TOOL}/${GNU_TOOL}-${version}.tar.gz" - sig_url="${GNU_FTP}/${GNU_TOOL}/${GNU_TOOL}-${version}.tar.gz.sig" - gnu_keyring=$(dirname "$filename")/gnu-keyring.gpg - - gpg_command="$(command -v gpg gpg2 | head -n 1 || :)" - - if [ -z "${gpg_command}" ]; then - fail 'gpg or gpg2 command not found. You must install GnuPG' - fi - - echo "* Downloading $TOOL_NAME release $version..." - curl "${curl_opts[@]}" -o "$filename" "$url" || fail "Could not download $url" - curl "${curl_opts[@]}" -o "$filename.sig" "$sig_url" || fail "Could not download signature $sig_url" - - if [[ "${MAKE_CHECK_SIGNATURES}" == "strict" ]]; then - curl "${curl_opts[@]}" -o "$gnu_keyring" "$GNU_KEYRING" || fail "Could not download gpg key $gnu_keyring" - if ! detail=$(${gpg_command} --keyring "$gnu_keyring" --verify "$filename.sig"); then - fail "Failed to GPG verification:\n$detail" - fi - fi + local version filename url sig_url gnu_keyring gpg_command detail + version="$1" + filename="$2" + + url="${GNU_FTP}/${GNU_TOOL}/${GNU_TOOL}-${version}.tar.gz" + sig_url="${GNU_FTP}/${GNU_TOOL}/${GNU_TOOL}-${version}.tar.gz.sig" + gnu_keyring=$(dirname "$filename")/gnu-keyring.gpg + + gpg_command="$(command -v gpg gpg2 | head -n 1 || :)" + + if [ -z "${gpg_command}" ]; then + fail 'gpg or gpg2 command not found. You must install GnuPG' + fi + + echo "* Downloading $TOOL_NAME release $version..." + curl "${curl_opts[@]}" -o "$filename" "$url" || fail "Could not download $url" + curl "${curl_opts[@]}" -o "$filename.sig" "$sig_url" || fail "Could not download signature $sig_url" + + if [[ "${MAKE_CHECK_SIGNATURES}" == "strict" ]]; then + curl "${curl_opts[@]}" -o "$gnu_keyring" "$GNU_KEYRING" || fail "Could not download gpg key $gnu_keyring" + if ! detail=$(${gpg_command} --keyring "$gnu_keyring" --verify "$filename.sig"); then + fail "Failed to GPG verification:\n$detail" + fi + fi } patch_source() { - local version="$1" - local glibc_version comparable_version - comparable_version=$(echo "$version" | awk -F . '{printf "%2d%02d%02d", $1, $2, $3}') - - case $(uname) in - Linux) - glibc_version=$(ldd --version | grep -oE '2\.[0-9]{2}' | uniq | awk -F. '{printf "%2d%02d", $1, $2}') - - # glibc glob interface patch - # http://gnu-make.2324884.n4.nabble.com/undefined-reference-to-alloca-td18308.html - if [[ 226 -lt $glibc_version && $comparable_version -le 40201 ]]; then - echo "* Patching glob interface of $TOOL_NAME release $version..." - patch -p1 -s <"$plugin_dir/patchers/support-glibc-glob-interface-version2.patch" - fi - - # segmentation fault on make install fix patch - # https://stackoverflow.com/questions/52618055/gnu-make-3-82-on-ubuntu-18-04-segfault-in-glob-call - if [[ $comparable_version -eq 38200 ]]; then - echo "* Patching lstat interface of $TOOL_NAME release $version..." - patch -s <"$plugin_dir/patchers/fix-segmentation-fault-3.82-on-linux.patch" - fi - - ;; - Darwin) ;; - - esac + local version="$1" + local glibc_version comparable_version + comparable_version=$(echo "$version" | awk -F . '{printf "%2d%02d%02d", $1, $2, $3}') + + case $(uname) in + Linux) + glibc_version=$(ldd --version | grep -oE '2\.[0-9]{2}' | uniq | awk -F. '{printf "%2d%02d", $1, $2}') + + # glibc glob interface patch + # http://gnu-make.2324884.n4.nabble.com/undefined-reference-to-alloca-td18308.html + if [[ 226 -lt $glibc_version && $comparable_version -le 40201 ]]; then + echo "* Patching glob interface of $TOOL_NAME release $version..." + patch -p1 -s <"$plugin_dir/patchers/support-glibc-glob-interface-version2.patch" + fi + + # segmentation fault on make install fix patch + # https://stackoverflow.com/questions/52618055/gnu-make-3-82-on-ubuntu-18-04-segfault-in-glob-call + if [[ $comparable_version -eq 38200 ]]; then + echo "* Patching lstat interface of $TOOL_NAME release $version..." + patch -s <"$plugin_dir/patchers/fix-segmentation-fault-3.82-on-linux.patch" + fi + + ;; + Darwin) ;; + + esac } patch_build_sh() { - local version="$1" - local comparable_version - comparable_version=$(echo "$version" | awk -F . '{printf "%2d%02d%02d", $1, $2, $3}') - - if [[ $comparable_version -eq 40000 && ${MAKE_BUILD_OPTIONS} =~ --with-guile=no ]]; then - # shellcheck disable=SC2016 - sed -i.bak -e 's/guile.${OBJEXT}//' build.sh - fi + local version="$1" + local comparable_version + comparable_version=$(echo "$version" | awk -F . '{printf "%2d%02d%02d", $1, $2, $3}') + + if [[ $comparable_version -eq 40000 && ${MAKE_BUILD_OPTIONS} =~ --with-guile=no ]]; then + # shellcheck disable=SC2016 + sed -i.bak -e 's/guile.${OBJEXT}//' build.sh + fi } install_version() { - local install_type="$1" - local version="$2" - local install_path="$3" - local install_log="$ASDF_DOWNLOAD_PATH/install.log" - - if [ "$install_type" != "version" ]; then - fail "asdf-$TOOL_NAME supports release installs only" - fi - - ( - mkdir -p "$install_path" - cd "$ASDF_DOWNLOAD_PATH" - - patch_source "$version" - - echo "* Installing $TOOL_NAME release $version..." - # If the make command is not installed on system old version, may get an error like the following: - # - # config.status: error: Something went wrong bootstrapping makefile fragments - # for automatic dependency tracking. Try re-running configure with the - # '--disable-dependency-tracking' option to at least be able to build - # the package (albeit without support for automatic dependency tracking). - # - # If try to make install in this state, the installation will fail because the - # Makefile of the po directory does not exist. - # - # Will not use make, which is installed on the system, to ensure a reliable build. - # First run configure to generate build.sh. - # Then, configure to use the make generated by build.sh and run configure again. - # At this time, can speed up second time configure by enabling configure caching (-C). - if [[ "${MAKE_PRINT_BUILD_LOG}" == "yes" ]]; then - { - # shellcheck disable=SC2086 - ./configure -C --prefix="$install_path" ${MAKE_BUILD_OPTIONS} - patch_build_sh "$version" - ./build.sh && - PATH=$ASDF_DOWNLOAD_PATH:$PATH ./configure -C --prefix="$install_path" && - ./make install - } 2>&1 | tee "$install_log" - else - { - # shellcheck disable=SC2086 - ./configure -C --prefix="$install_path" ${MAKE_BUILD_OPTIONS} - patch_build_sh "$version" - ./build.sh && - PATH=$ASDF_DOWNLOAD_PATH:$PATH ./configure -C --prefix="$install_path" ${MAKE_BUILD_OPTIONS} && - ./make install - } &>"$install_log" - fi - - local tool_cmd - tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" - test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable." - - echo "$TOOL_NAME $version installation was successful!" - ) || ( - rm -rf "$install_path" - fail "An error ocurred while installing $TOOL_NAME $version. install log is $install_log" - ) + local install_type="$1" + local version="$2" + local install_path="$3" + local install_log="$ASDF_DOWNLOAD_PATH/install.log" + + if [ "$install_type" != "version" ]; then + fail "asdf-$TOOL_NAME supports release installs only" + fi + + ( + mkdir -p "$install_path" + cd "$ASDF_DOWNLOAD_PATH" + + patch_source "$version" + + echo "* Installing $TOOL_NAME release $version..." + # If the make command is not installed on system old version, may get an error like the following: + # + # config.status: error: Something went wrong bootstrapping makefile fragments + # for automatic dependency tracking. Try re-running configure with the + # '--disable-dependency-tracking' option to at least be able to build + # the package (albeit without support for automatic dependency tracking). + # + # If try to make install in this state, the installation will fail because the + # Makefile of the po directory does not exist. + # + # Will not use make, which is installed on the system, to ensure a reliable build. + # First run configure to generate build.sh. + # Then, configure to use the make generated by build.sh and run configure again. + # At this time, can speed up second time configure by enabling configure caching (-C). + if [[ "${MAKE_PRINT_BUILD_LOG}" == "yes" ]]; then + { + # shellcheck disable=SC2086 + ./configure -C --prefix="$install_path" ${MAKE_BUILD_OPTIONS} + patch_build_sh "$version" + ./build.sh && + PATH=$ASDF_DOWNLOAD_PATH:$PATH ./configure -C --prefix="$install_path" && + ./make install + } 2>&1 | tee "$install_log" + else + { + # shellcheck disable=SC2086 + ./configure -C --prefix="$install_path" ${MAKE_BUILD_OPTIONS} + patch_build_sh "$version" + ./build.sh && + PATH=$ASDF_DOWNLOAD_PATH:$PATH ./configure -C --prefix="$install_path" "${MAKE_BUILD_OPTIONS}" && + ./make install + } &>"$install_log" + fi + + local tool_cmd + tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" + test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable." + + echo "$TOOL_NAME $version installation was successful!" + ) || ( + rm -rf "$install_path" + fail "An error ocurred while installing $TOOL_NAME $version. install log is $install_log" + ) } diff --git a/scripts/format.bash b/scripts/format.bash new file mode 100755 index 0000000..1a216ea --- /dev/null +++ b/scripts/format.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +shfmt --language-dialect bash --write \ + ./**/* diff --git a/scripts/lint.bash b/scripts/lint.bash new file mode 100755 index 0000000..b156e8d --- /dev/null +++ b/scripts/lint.bash @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +shellcheck --shell=bash --external-sources \ + bin/* --source-path=lib/ \ + lib/* \ + scripts/* + +shfmt --language-dialect bash --diff \ + ./{bin,lib}/* diff --git a/scripts/shellcheck.bash b/scripts/shellcheck.bash deleted file mode 100755 index 6d28a72..0000000 --- a/scripts/shellcheck.bash +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -exec shellcheck -s bash -x \ - bin/* -P lib/ diff --git a/scripts/shfmt.bash b/scripts/shfmt.bash deleted file mode 100755 index 534f8a6..0000000 --- a/scripts/shfmt.bash +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -exec shfmt -d .