Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +31 to 44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: might want to define a script so that this can be reused.

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