diff --git a/action.yml b/action.yml new file mode 100644 index 000000000..f503825a1 --- /dev/null +++ b/action.yml @@ -0,0 +1,29 @@ +--- + +name: actionlint +description: ":octocat: Static checker for GitHub Actions workflow files" + +#branding: # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#branding +# icon: _ +# color: _ + +inputs: + color: + default: false + description: "Enable colorful output." + +runs: + using: composite + steps: + - name: "Report Invalid Color Input" + if: inputs.color != 'yes' && inputs.color != 'true' && inputs.color != 'no' && inputs.color != 'false' + shell: bash + run: echo ${{ format('::warning::Invalid boolean value for color "{0}"', inputs.color) }} + + - name: "Download Action Lint" + shell: bash + run: ${{ github.action_path }}/scripts/download-actionlint.bash latest ${{ runner.temp }} + + - name: "Run Action Lint" + shell: bash + run: ${{ runner.temp }}/actionlint ${{ (inputs.color == 'yes' || inputs.color == 'true') && '-color' || '' }} diff --git a/docs/usage.md b/docs/usage.md index 5c709c887..f8705be84 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -307,6 +307,21 @@ Go APIs are available. See [the Go API document](api.md) for more details. ## Tools integration +### GitHub Actions + +[actionlint](..) is itself integrated with GitHub Actions. It can be run directly from a simple workflow file. + +```yaml +name: actionlint +on: push +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: rhysd/actionlint@v1.x.y +``` + ### reviewdog [reviewdog][] is an automated review tool for various code hosting services. It officially [supports actionlint][reviewdog-actionlint]. @@ -323,6 +338,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: reviewdog/action-actionlint@v1 + with: + color: true ``` diff --git a/scripts/download-actionlint.bash b/scripts/download-actionlint.bash index babfe69d2..e2d5bc4d1 100755 --- a/scripts/download-actionlint.bash +++ b/scripts/download-actionlint.bash @@ -37,6 +37,29 @@ function usage() { echo ' $ bash download-actionlint.bash 1.6.9 /usr/bin' >&2 } +log() { + if [ "${GITHUB_ACTIONS}" ] + then + echo "::notice::$*" + else + echo "$@" 1>&2 + fi +} + +err() { + if [ "${GITHUB_ACTIONS}" ] + then + echo "::error::$*" + else + echo "$@" 1>&2 + fi +} + +die() { + err "$*" + exit 1 +} + if [[ "$1" == "-h" || "$1" == "--help" ]]; then usage exit @@ -49,7 +72,8 @@ if [ -n "$1" ]; then if [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then version="$1" else - echo "Given version '$1' does not match to regex '^[0-9]+\.[0-9]+\.[0-9]+$' nor equal to 'latest'" >&2 + err "Given version '$1' does not match to regex '^[0-9]+\.[0-9]+\.[0-9]+$' nor equal to 'latest'" + echo >&2 usage exit 1 @@ -62,14 +86,15 @@ if [ -n "$2" ]; then if [ -d "$2" ]; then target_dir="${2%/}" else - echo "Directory '$2' does not exist" >&2 + err "Directory '$2' does not exist" + echo >&2 usage exit 1 fi fi -echo "Start downloading actionlint v${version} to ${target_dir}" +log "Start downloading actionlint v${version} to ${target_dir}" case "$OSTYPE" in linux-*) @@ -89,8 +114,7 @@ case "$OSTYPE" in ext=zip ;; *) - echo "OS '${OSTYPE}' is not supported. Note: If you're using Windows, please ensure bash is used to run this script" >&2 - exit 1 + die "OS '${OSTYPE}' is not supported. Note: If you're using Windows, please ensure bash is used to run this script" ;; esac @@ -102,18 +126,17 @@ case "$machine" in aarch64|arm64) arch=arm64 ;; arm*) arch=armv6 ;; *) - echo "Could not determine arch from machine hardware name '${machine}'" >&2 - exit 1 + die "Could not determine arch from machine hardware name '${machine}'" ;; esac -echo "Detected OS=${os} ext=${ext} arch=${arch}" +log "Detected OS=${os} ext=${ext} arch=${arch}" # https://github.com/rhysd/actionlint/releases/download/v1.0.0/actionlint_1.0.0_linux_386.tar.gz file="actionlint_${version}_${os}_${arch}.${ext}" url="https://github.com/rhysd/actionlint/releases/download/v${version}/${file}" -echo "Downloading ${url} with curl" +log "Downloading ${url} with curl" if [[ "$os" == "windows" ]]; then tempdir="$(mktemp -d actionlint.XXXXXXXXXXXXXXXX)" @@ -126,9 +149,9 @@ else exe="$target_dir/actionlint" fi -echo "Downloaded and unarchived executable: ${exe}" +log "Downloaded and unarchived executable: ${exe}" -echo "Done: $("${exe}" -version)" +log "Done: $("${exe}" -version)" if [ -n "$GITHUB_ACTION" ]; then # On GitHub Actions, set executable path to output