From baf3d6c9a40b0c91ba54ce1f5bf2926dcaed1636 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Wed, 13 Apr 2022 11:51:06 +0900 Subject: [PATCH] Migrate to a composite run based action --- .github/workflows/depup.yml | 2 +- .github/workflows/dockerimage.yml | 14 ----------- Dockerfile | 12 ---------- README.md | 1 - action.yml | 19 +++++++++++++-- entrypoint.sh | 29 ---------------------- package.json | 2 +- script.sh | 40 +++++++++++++++++++++++++++++++ testdata-subproject/package.json | 2 +- 9 files changed, 60 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/dockerimage.yml delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh create mode 100755 script.sh diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index e762643..b0518ef 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -13,7 +13,7 @@ jobs: - uses: haya14busa/action-depup@v1 id: depup with: - file: Dockerfile + file: action.yml version_name: REVIEWDOG_VERSION repo: reviewdog/reviewdog diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml deleted file mode 100644 index d5ab2d2..0000000 --- a/.github/workflows/dockerimage.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Docker Image CI - -on: [push] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag reviewdog-stylelint:$(date +%s) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0a044df..0000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM node:current-alpine - -ENV REVIEWDOG_VERSION=v0.14.0 - -RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} -RUN apk --update add jq git && \ - rm -rf /var/lib/apt/lists/* && \ - rm /var/cache/apk/* - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 2d55d03..dc0b32e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # GitHub Action: Run stylelint with reviewdog -[![Docker Image CI](https://github.com/reviewdog/action-stylelint/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/reviewdog/action-stylelint/actions) [![depup](https://github.com/reviewdog/action-stylelint/workflows/depup/badge.svg)](https://github.com/reviewdog/action-stylelint/actions?query=workflow%3Adepup) [![release](https://github.com/reviewdog/action-stylelint/workflows/release/badge.svg)](https://github.com/reviewdog/action-stylelint/actions?query=workflow%3Arelease) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-stylelint?logo=github&sort=semver)](https://github.com/reviewdog/action-stylelint/releases) diff --git a/action.yml b/action.yml index 05cc506..8afc8a6 100644 --- a/action.yml +++ b/action.yml @@ -38,8 +38,23 @@ inputs: description: "The directory from which to look for and run stylelint. Default: '.'" default: '.' runs: - using: 'docker' - image: 'Dockerfile' + using: 'composite' + steps: + - run: $GITHUB_ACTION_PATH/script.sh + shell: bash + env: + REVIEWDOG_VERSION: v0.14.0 + INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} + INPUT_LEVEL: ${{ inputs.level }} + INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} + INPUT_FILTER_MODE: ${{ inputs.filter_mode }} + INPUT_NAME: ${{ inputs.name }} + INPUT_PACKAGES: ${{ inputs.packages }} + INPUT_REPORTER: ${{ inputs.reporter }} + INPUT_STYLELINT_INPUT: ${{ inputs.stylelint_input }} + INPUT_STYLELINT_CONFIG: ${{ inputs.stylelint_config }} + INPUT_STYLELINT_IGNORE: ${{ inputs.stylelint_ignore }} + INPUT_WORKDIR: ${{ inputs.workdir }} branding: icon: 'alert-triangle' color: 'yellow' diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 696b18e..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -cd "$GITHUB_WORKSPACE" - -export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" - -cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1 - -git config --global --add safe.directory $GITHUB_WORKSPACE - -if [ ! -f "$(npm bin)/stylelint" ]; then - npm install -fi - -if [ -n "${INPUT_PACKAGES}" ]; then - npm install ${INPUT_PACKAGES} -fi - -$(npm bin)/stylelint --version - -if [ "${INPUT_REPORTER}" == 'github-pr-review' ]; then - # Use jq and github-pr-review reporter to format result to include link to rule page. - $(npm bin)/stylelint "${INPUT_STYLELINT_INPUT:-'**/*.css'}" --config="${INPUT_STYLELINT_CONFIG}" --ignore-pattern="${INPUT_STYLELINT_IGNORE}" -f json \ - | jq -r '.[] | {source: .source, warnings:.warnings[]} | "\(.source):\(.warnings.line):\(.warnings.column):\(.warnings.severity): \(.warnings.text) [\(.warnings.rule)](https://stylelint.io/user-guide/rules/\(.warnings.rule))"' \ - | reviewdog -efm="%f:%l:%c:%t%*[^:]: %m" -name="${INPUT_NAME:-stylelint}" -reporter=github-pr-review -level="${INPUT_LEVEL}" -filter-mode="${INPUT_FILTER_MODE}" -fail-on-error="${INPUT_FAIL_ON_ERROR}" -else - $(npm bin)/stylelint "${INPUT_STYLELINT_INPUT:-'**/*.css'}" --config="${INPUT_STYLELINT_CONFIG}" --ignore-pattern="${INPUT_STYLELINT_IGNORE}" \ - | reviewdog -f="stylelint" -name="${INPUT_NAME:-stylelint}" -reporter="${INPUT_REPORTER:-github-pr-check}" -level="${INPUT_LEVEL}" -filter-mode="${INPUT_FILTER_MODE}" -fail-on-error="${INPUT_FAIL_ON_ERROR}" -fi diff --git a/package.json b/package.json index 6eb0fca..cf58f21 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "action-stylelint", "version": "1.0.0", - "description": "[![Docker Image CI](https://github.com/reviewdog/action-stylelint/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/reviewdog/action-stylelint/actions) [![Release](https://img.shields.io/github/release/reviewdog/action-stylelint.svg?maxAge=43200)](https://github.com/reviewdog/action-stylelint/releases)", + "description": "GitHub Action: Run stylelint with reviewdog", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..60f0440 --- /dev/null +++ b/script.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1 + +TEMP_PATH="$(mktemp -d)" +PATH="${TEMP_PATH}:$PATH" +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" + +echo '::group:: Installing reviewdog 🐶 ... https://github.com/reviewdog/reviewdog' +curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 +echo '::endgroup::' + +if [ ! -f "$(npm bin)/stylelint" ]; then + echo '::group:: Running `npm install` to install stylelint ...' + npm install + echo '::endgroup::' +fi + +if [ -n "${INPUT_PACKAGES}" ]; then + echo '::group:: Running `npm install` to install input packages ...' + npm install ${INPUT_PACKAGES} + echo '::endgroup::' +fi + +echo "stylelint version: $($(npm bin)/stylelint --version)" + +echo '::group:: Running stylelint with reviewdog 🐶 ...' +if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then + # Use jq and github-pr-review reporter to format result to include link to rule page. + $(npm bin)/stylelint "${INPUT_STYLELINT_INPUT}" --config="${INPUT_STYLELINT_CONFIG}" --ignore-pattern="${INPUT_STYLELINT_IGNORE}" -f json \ + | jq -r '.[] | {source: .source, warnings:.warnings[]} | "\(.source):\(.warnings.line):\(.warnings.column):\(.warnings.severity): \(.warnings.text) [\(.warnings.rule)](https://stylelint.io/user-guide/rules/\(.warnings.rule))"' \ + | reviewdog -efm="%f:%l:%c:%t%*[^:]: %m" -name="${INPUT_NAME}" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" -filter-mode="${INPUT_FILTER_MODE}" -fail-on-error="${INPUT_FAIL_ON_ERROR}" +else + $(npm bin)/stylelint "${INPUT_STYLELINT_INPUT}" --config="${INPUT_STYLELINT_CONFIG}" --ignore-pattern="${INPUT_STYLELINT_IGNORE}" \ + | reviewdog -f="stylelint" -name="${INPUT_NAME}" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" -filter-mode="${INPUT_FILTER_MODE}" -fail-on-error="${INPUT_FAIL_ON_ERROR}" +fi + +reviewdog_rc=$? +echo '::endgroup::' +exit $reviewdog_rc diff --git a/testdata-subproject/package.json b/testdata-subproject/package.json index 6eb0fca..cf58f21 100644 --- a/testdata-subproject/package.json +++ b/testdata-subproject/package.json @@ -1,7 +1,7 @@ { "name": "action-stylelint", "version": "1.0.0", - "description": "[![Docker Image CI](https://github.com/reviewdog/action-stylelint/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/reviewdog/action-stylelint/actions) [![Release](https://img.shields.io/github/release/reviewdog/action-stylelint.svg?maxAge=43200)](https://github.com/reviewdog/action-stylelint/releases)", + "description": "GitHub Action: Run stylelint with reviewdog", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"