diff --git a/.github/workflows/check-file.yml b/.github/workflows/check-file.yml new file mode 100644 index 000000000000..b75b9e34d1f3 --- /dev/null +++ b/.github/workflows/check-file.yml @@ -0,0 +1,28 @@ +name: Files + +on: + merge_group: + pull_request: + +jobs: + check-expired: + name: EXPIRED FILE check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm run check:expired + - run: npm run _diff:fail + + check-filenames: + name: FILENAME check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm run check:filenames + + check-formatting: + name: FILE FORMAT + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm run check:format diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml deleted file mode 100644 index e3227341e0e4..000000000000 --- a/.github/workflows/check-format.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Files - -on: - merge_group: - pull_request: - -jobs: - check-filenames: - name: FILENAME check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: npm run check:filenames - - check-formatting: - name: FILE FORMAT - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Create NPM cache-hash input file - run: | - mkdir -p tmp - jq '{devDependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json - - - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - cache: npm - cache-dependency-path: tmp/package-ci.json - - - name: Install package(s) - run: | - PRETTIER_AT_VERS=@$(npm pkg get devDependencies.prettier | tr -d '^"') - echo "PRETTIER_AT_VERS=$PRETTIER_AT_VERS" | tee -a $GITHUB_ENV - npm install prettier$PRETTIER_AT_VERS --no-save - set -x && npx prettier --version - - - run: npm run check:format diff --git a/.github/workflows/check-spelling.yml b/.github/workflows/check-spelling.yml index 23526674a692..eec394cfd882 100644 --- a/.github/workflows/check-spelling.yml +++ b/.github/workflows/check-spelling.yml @@ -26,16 +26,19 @@ jobs: suggestions: true dict-check: - name: CSPELL:IGNORE check + name: CSPELL page-local word list check runs-on: ubuntu-latest + env: + FIX_CMD: fix:dict steps: - uses: actions/checkout@v4 - - run: npm run fix:dict + - run: npm run ${{ env.FIX_CMD }} - name: Any changed files? run: | CHANGES=`git status --porcelain` if [[ $CHANGES ]]; then - echo "Locally run `npm run fix:dict` and commit the changes:" + echo "Add comment '/fix:${{ env.FIX_CMD }}' to your PR in GitHub," + echo "or locally run 'npm run ${{ env.FIX_CMD }}' and commit the changes:" echo "$CHANGES" exit 1 else diff --git a/package.json b/package.json index 5b7ec69141cc..55a01729eca6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "__check:links": "make --keep-going check-links", "_build": "npm run _hugo -- -e dev --buildDrafts --buildFuture --baseURL \"${DEPLOY_PRIME_URL:-http://localhost}\"", - "__check:format": "npx prettier${PRETTIER_AT_VERS}", + "__check:format": "./scripts/npx-helper.sh prettier", "_check:format:any": "npm run __check:format -- --check --ignore-path ''", "_check:format:ja+zh": "npm run _check:format:nowrap -- content/ja content/zh", "_check:format:nowrap": "npm run _check:format:any -- --prose-wrap preserve", diff --git a/scripts/npx-helper.sh b/scripts/npx-helper.sh new file mode 100755 index 000000000000..57aa7d690ee6 --- /dev/null +++ b/scripts/npx-helper.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Runs the given command with npx, ensuring that the version of the +# command/package as declared in `package.json` is first installed. + +if [ $# -eq 0 ]; then + echo "Usage: $0 [--no-ignore-scripts] [args...]" + exit 1 +fi + +npx_vers_from_pkg_json() { + local npm_i_flags="--no-save" + if [[ "$1" == "--no-ignore-scripts" ]]; then + shift + else + npm_i_flags+=" --ignore-scripts" + fi + local command=$1; shift; + # For now we assume that the package name is the same as the command name. + local package=$command + if ! [[ $package =~ ^[a-zA-Z0-9_-]+$ ]]; then + echo "ERROR: Invalid package name '$package'" + exit 1 + fi + local args=$@ + + local version=$(npm pkg get devDependencies.$package | tr -d '^"') + if [[ $version == "{}" ]]; then + echo "ERROR: Could not determine version of '$package' from package.json" + exit 1 + fi + local pkgAtVers="$package@$version" + + if ! npm ls $pkgAtVers; then + (set -x; npm install $npm_i_flags $pkgAtVers) + fi + set -x && npx $pkgAtVers $args +} + +npx_vers_from_pkg_json $@;