diff --git a/.changeset/rare-colts-hang.md b/.changeset/rare-colts-hang.md new file mode 100644 index 00000000000..7fe05cfa53e --- /dev/null +++ b/.changeset/rare-colts-hang.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Added `actionlint` for linting project's Github Actions diff --git a/lint-staged.config.cjs b/lint-staged.config.cjs index fdf9bf6baa2..c529f70ffee 100644 --- a/lint-staged.config.cjs +++ b/lint-staged.config.cjs @@ -4,6 +4,8 @@ const config = { "*.{js,jsx,ts,tsx,mjs,cjs}": ["eslint --cache --fix", "prettier --write"], "*.{json,css,md,yml,yaml}": ["prettier --write"], + ".github/workflows/*.{yml,yaml}": ["actionlint"], + ".github/actions/**/action.yml": ["actionlint"], "package.json": "sort-package-json", }; diff --git a/package.json b/package.json index 388e2907c49..3b563428a30 100644 --- a/package.json +++ b/package.json @@ -38,9 +38,10 @@ "knip": "knip --reporter markdown", "knip:fix": "knip --fix --allow-remove-files", "lint": "pnpm run /^lint:.*$/", + "lint:actionlint": "actionlint .github/workflows/*.yml .github/workflows/*.yaml .github/actions/*/action.yml .github/actions/*/*/action.yml || true", "lint:eslint": "cross-env NODE_OPTIONS=--max-old-space-size=8192 eslint \"{src,playwright}/**/*.@(tsx|ts|jsx|js)\" --fix", "lint:prettier": "prettier --ignore-unknown --write .", - "prepare": "is-ci || husky install", + "prepare": "is-ci || husky install && bash scripts/install-actionlint.bash", "preview": "vite preview", "release": "node scripts/release.cjs", "release:cleanup": "./scripts/release-cleanup.sh", diff --git a/scripts/install-actionlint.bash b/scripts/install-actionlint.bash new file mode 100755 index 00000000000..bab6aee01be --- /dev/null +++ b/scripts/install-actionlint.bash @@ -0,0 +1,48 @@ +#!/bin/bash +# Downloads actionlint binary into node_modules/.bin/ so it's available +# for pnpm scripts and lint-staged without requiring Go or brew. +# Based on https://github.com/rhysd/actionlint/blob/main/scripts/download-actionlint.bash + +set -euo pipefail + +VERSION="1.7.10" +TARGET_DIR="$(cd "$(dirname "$0")/../node_modules/.bin" && pwd)" +BINARY="$TARGET_DIR/actionlint" + +if [ -x "$BINARY" ] && "$BINARY" -version 2>/dev/null | grep -q "$VERSION"; then + echo "actionlint v${VERSION} already installed" + exit 0 +fi + +case "$OSTYPE" in + linux*) os=linux; ext=tar.gz ;; + darwin*) os=darwin; ext=tar.gz ;; + msys|cygwin|win32) os=windows; ext=zip ;; + *) echo "Unsupported OS: $OSTYPE" >&2; exit 1 ;; +esac + +machine="$(uname -m)" +case "$machine" in + x86_64) arch=amd64 ;; + i?86) arch=386 ;; + aarch64|arm64) arch=arm64 ;; + arm*) arch=armv6 ;; + *) echo "Unsupported arch: $machine" >&2; exit 1 ;; +esac + +file="actionlint_${VERSION}_${os}_${arch}.${ext}" +url="https://github.com/rhysd/actionlint/releases/download/v${VERSION}/${file}" + +echo "Downloading actionlint v${VERSION} (${os}/${arch})..." +mkdir -p "$TARGET_DIR" + +if [ "$os" = "windows" ]; then + tmpdir="$(mktemp -d)" + curl -sSL -o "$tmpdir/tmp.zip" "$url" + unzip -o "$tmpdir/tmp.zip" actionlint.exe -d "$TARGET_DIR" + rm -rf "$tmpdir" +else + curl -sSL "$url" | tar xz -C "$TARGET_DIR" actionlint +fi + +echo "Installed: $("$BINARY" -version)"