Skip to content

Commit d9d31a4

Browse files
committed
[CI] GH check: add expired check, and more
1 parent 2ed2e0a commit d9d31a4

File tree

5 files changed

+75
-43
lines changed

5 files changed

+75
-43
lines changed

.github/workflows/check-file.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Files
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
7+
jobs:
8+
check-expired:
9+
name: EXPIRED FILE check
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- run: npm run check:expired
14+
- run: npm run _diff:fail
15+
16+
check-filenames:
17+
name: FILENAME check
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- run: npm run check:filenames
22+
23+
check-formatting:
24+
name: FILE FORMAT
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- run: npm run check:format

.github/workflows/check-format.yml

-39
This file was deleted.

.github/workflows/check-spelling.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ jobs:
2626
suggestions: true
2727

2828
dict-check:
29-
name: CSPELL:IGNORE check
29+
name: CSPELL page-local word list check
3030
runs-on: ubuntu-latest
31+
env:
32+
FIX_CMD: fix:dict
3133
steps:
3234
- uses: actions/checkout@v4
33-
- run: npm run fix:dict
35+
- run: npm run ${{ env.FIX_CMD }}
3436
- name: Any changed files?
3537
run: |
3638
CHANGES=`git status --porcelain`
3739
if [[ $CHANGES ]]; then
38-
echo "Locally run `npm run fix:dict` and commit the changes:"
40+
echo "Add comment '/fix:${{ env.FIX_CMD }}' to your PR in GitHub,"
41+
echo "or locally run 'npm run ${{ env.FIX_CMD }}' and commit the changes:"
3942
echo "$CHANGES"
4043
exit 1
4144
else

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"__check:links": "make --keep-going check-links",
88
"_build": "npm run _hugo -- -e dev --buildDrafts --buildFuture --baseURL \"${DEPLOY_PRIME_URL:-http://localhost}\"",
9-
"__check:format": "npx prettier${PRETTIER_AT_VERS}",
9+
"__check:format": "./scripts/npx-helper.sh prettier",
1010
"_check:format:any": "npm run __check:format -- --check --ignore-path ''",
1111
"_check:format:ja+zh": "npm run _check:format:nowrap -- content/ja content/zh",
1212
"_check:format:nowrap": "npm run _check:format:any -- --prose-wrap preserve",

scripts/npx-helper.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#
3+
# Runs the given command with npx, ensuring that the version of the
4+
# command/package as declared in `package.json` is first installed.
5+
6+
if [ $# -eq 0 ]; then
7+
echo "Usage: $0 [--no-ignore-scripts] <npm-command-and-package-name> [args...]"
8+
exit 1
9+
fi
10+
11+
npx_vers_from_pkg_json() {
12+
local npm_i_flags="--no-save"
13+
if [[ "$1" == "--no-ignore-scripts" ]]; then
14+
shift
15+
else
16+
npm_i_flags+=" --ignore-scripts"
17+
fi
18+
local command=$1; shift;
19+
# For now we assume that the package name is the same as the command name.
20+
local package=$command
21+
if ! [[ $package =~ ^[a-zA-Z0-9_-]+$ ]]; then
22+
echo "ERROR: Invalid package name '$package'"
23+
exit 1
24+
fi
25+
local args=$@
26+
27+
local version=$(npm pkg get devDependencies.$package | tr -d '^"')
28+
if [[ $version == "{}" ]]; then
29+
echo "ERROR: Could not determine version of '$package' from package.json"
30+
exit 1
31+
fi
32+
local pkgAtVers="$package@$version"
33+
34+
if ! npm ls $pkgAtVers; then
35+
(set -x; npm install $npm_i_flags $pkgAtVers)
36+
fi
37+
set -x && npx $pkgAtVers $args
38+
}
39+
40+
npx_vers_from_pkg_json $@;

0 commit comments

Comments
 (0)