diff --git a/.github/depup.sh b/.github/depup.sh new file mode 100755 index 0000000..3b93b66 --- /dev/null +++ b/.github/depup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +CURRENT=$(cd "$(dirname "$0")" && pwd) + +set -eu + +# cleanup temporary directory +unset tmpdir +atexit() { + [[ -n ${tmpdir-} ]] && rm -f "$tmpdir" +} +trap atexit EXIT +trap 'rc=$?; trap - EXIT; atexit; exit $?' INT PIPE TERM + +tempdir=$(mktemp -d) + +# sync install.sh with https://github.com/reviewdog/action-setup +curl -sSL https://raw.githubusercontent.com/reviewdog/action-setup/master/install.sh -o "$tempdir/install.sh" +install -m 755 "$tempdir/install.sh" "$CURRENT/../install.sh" diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index 8bc63bd..8091292 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -1,7 +1,7 @@ name: depup on: schedule: - - cron: '14 14 * * *' # Runs at 14:14 UTC every day + - cron: "14 14 * * *" # Runs at 14:14 UTC every day repository_dispatch: types: [depup] workflow_dispatch: @@ -14,6 +14,14 @@ jobs: - uses: reviewdog/action-depup/with-pr@v1 with: file: action.yml - version_name: reviewdog_version + version_name: REVIEWDOG_VERSION repo: reviewdog/reviewdog labels: "bump:minor" + + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: ./.github/depup.sh + - name: commit and create a pull request + uses: shogo82148/actions-commit-and-create-pr@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be3cba5..a08b5ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,7 @@ jobs: wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv sudo cp "shellcheck-${scversion}/shellcheck" /usr/local/bin/ rm -rf "shellcheck-${scversion}/shellcheck" - - run: shellcheck -f diff $(shfmt -f .) | patch -p1 + - run: shellcheck -f diff "$(shfmt -f .)" | patch -p1 - name: suggester / shellcheck uses: ./ with: diff --git a/action.yml b/action.yml index b69fdec..6d473be 100644 --- a/action.yml +++ b/action.yml @@ -1,48 +1,58 @@ -name: 'reviewdog-suggester: Suggest any code changes based on diff with reviewdog' -description: '🐶 Suggest any code changes based on diff through GitHub Multi-line code suggestions' -author: 'haya14busa' +name: "reviewdog-suggester: Suggest any code changes based on diff with reviewdog" +description: "🐶 Suggest any code changes based on diff through GitHub Multi-line code suggestions" +author: "haya14busa" inputs: github_token: - description: 'GITHUB_TOKEN' - default: '${{ github.token }}' + description: "GITHUB_TOKEN" + default: "${{ github.token }}" required: true ### Flags for reviewdog ### tool_name: - description: 'Tool name to use for reviewdog reporter' - default: 'reviewdog-suggester' + description: "Tool name to use for reviewdog reporter" + default: "reviewdog-suggester" required: false level: - description: 'Report level for reviewdog [info,warning,error]' - default: 'warning' + description: "Report level for reviewdog [info,warning,error]" + default: "warning" required: false filter_mode: description: | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. Default is diff_context. GitHub suggestions only support added and diff_context. - default: 'diff_context' + default: "diff_context" required: false fail_on_error: description: | Exit code for reviewdog when errors are found [true,false] Default is `false`. - default: 'false' + default: "false" required: false reviewdog_flags: - description: 'Additional reviewdog flags' - default: '' + description: "Additional reviewdog flags" + default: "" required: false ### Flags for reviewdog suggester ### cleanup: - description: 'Clean up non-committed changes after the action' - default: 'true' + description: "Clean up non-committed changes after the action" + default: "true" required: false runs: - using: 'composite' + using: "composite" steps: - - uses: reviewdog/action-setup@v1 - with: - reviewdog_version: v0.14.2 - - run: $GITHUB_ACTION_PATH/script.sh + - run: | + set -euo pipefail + "$GITHUB_ACTION_PATH/install.sh" + shell: bash + env: + REVIEWDOG_VERSION: v0.14.2 + REVIEWDOG_TEMPDIR: ${{ runner.temp }} + - run: | + set -euo pipefail + "$GITHUB_ACTION_PATH/check-installed.sh" + shell: bash + - run: | + set -euo pipefail + "$GITHUB_ACTION_PATH/script.sh" shell: bash env: # INPUT_ is not available in Composite run steps @@ -57,5 +67,5 @@ runs: # Ref: https://haya14busa.github.io/github-action-brandings/ branding: - icon: 'edit' - color: 'red' + icon: "edit" + color: "red" diff --git a/check-installed.sh b/check-installed.sh new file mode 100755 index 0000000..6699e5a --- /dev/null +++ b/check-installed.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if ! command -v reviewdog >/dev/null 2>&1; then + echo "reviewdog was not installed" + exit 1 +fi +echo "::group::📖 reviewdog -h" +reviewdog -h 2>&1 || true +echo "::endgroup::" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..424e909 --- /dev/null +++ b/install.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euo pipefail + +VERSION="${REVIEWDOG_VERSION:-latest}" + +TEMP="${REVIEWDOG_TEMPDIR}" +if [ -z "${TEMP}" ]; then + if [ -n "${RUNNER_TEMP}" ]; then + TEMP="${RUNNER_TEMP}" + else + TEMP="$(mktemp -d)" + fi +fi + +INSTALL_SCRIPT='https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh' +if [ "${VERSION}" == 'nightly' ] ; then + INSTALL_SCRIPT='https://raw.githubusercontent.com/reviewdog/nightly/master/install.sh' + VERSION='latest' +fi + +mkdir -p "${TEMP}/reviewdog/bin" + +echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog' +curl -sfL "${INSTALL_SCRIPT}" | sh -s -- -b "${TEMP}/reviewdog/bin" "${VERSION}" 2>&1 +echo '::endgroup::' + +echo "${TEMP}/reviewdog/bin" >>"${GITHUB_PATH}"