Skip to content

Commit

Permalink
[CI] GH check: add file-expired check, and more (#6189)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin authored Feb 3, 2025
1 parent e22b3ff commit cbf96ed
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 43 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/check-file.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 0 additions & 39 deletions .github/workflows/check-format.yml

This file was deleted.

9 changes: 6 additions & 3 deletions .github/workflows/check-spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions scripts/npx-helper.sh
Original file line number Diff line number Diff line change
@@ -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 $@;

0 comments on commit cbf96ed

Please sign in to comment.