[CI] GH check: add file-expired check, and more (#6189)

This commit is contained in:
Patrice Chalin 2025-02-03 12:31:02 -05:00 committed by GitHub
parent e22b3ffe88
commit cbf96ed40a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 75 additions and 43 deletions

28
.github/workflows/check-file.yml vendored Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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",

40
scripts/npx-helper.sh Executable file
View File

@ -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] <npm-command-and-package-name> [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 $@;