GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: pin npm past the EALLOWGIT regression instead of pinning pre-commit · wayneminwang/action-pre-commit@6b8ef1c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .pre-commit-config.yaml
  • action.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.pre-commit-config.yaml‎

Copy file name to clipboardExpand all lines: .pre-commit-config.yaml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010
- repo: https://github.com/pre-commit/mirrors-eslint
11-
rev: v10.10.0
11+
rev: v10.11.0
1212
hooks:
1313
- id: eslint
1414
- repo: https://github.com/pre-commit/mirrors-prettier
@@ -17,7 +17,7 @@ repos:
1717
- id: prettier
1818
stages: [pre-commit]
1919
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
20-
rev: v9.26.0
20+
rev: v9.27.0
2121
hooks:
2222
- id: commitlint
2323
stages: [commit-msg]
Collapse file

‎action.yaml‎

Copy file name to clipboardExpand all lines: action.yaml
+48-49Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,14 @@ runs:
6363
PRE_COMMIT_BIN=$(command -v pre-commit || true)
6464
echo "PRE_COMMIT_BIN=$PRE_COMMIT_BIN" >> $GITHUB_ENV
6565
66-
# pre-commit 4.6.1 rewrote `language: node` hook installation to run
67-
# `npm install --allow-git=root -g git+file://<hook checkout> <deps>`
68-
# instead of packing a tarball. npm then refuses that git+file://
69-
# package ("npm error code EALLOWGIT") for any node hook that also
70-
# declares additional_dependencies, which covers mirrors-prettier and
71-
# mirrors-eslint. Repos only notice once something invalidates their
72-
# hook cache and forces a rebuild, which then fails lint and blocks
73-
# release pipelines gated on it.
74-
#
75-
# Runner images can pre-bake an affected pre-commit, so check the
76-
# version of whatever is on PATH rather than only whether one exists.
77-
# Drop this pin once upstream ships a working node installer.
78-
PRE_COMMIT_BAD_FROM_VERSION="4.6.1"
79-
PRE_COMMIT_PIN="pre-commit<${PRE_COMMIT_BAD_FROM_VERSION}"
80-
# Default to installing our own, which is also the right answer when no
81-
# pre-commit is present or its version cannot be determined.
82-
PRE_COMMIT_NEEDS_PIN="true"
83-
if [[ -n "$PRE_COMMIT_BIN" ]]; then
84-
PRE_COMMIT_CURRENT_VERSION=$("$PRE_COMMIT_BIN" --version | awk '{print $2}') || PRE_COMMIT_CURRENT_VERSION=""
85-
if [[ ! "$PRE_COMMIT_CURRENT_VERSION" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
86-
echo "::warning::could not read a version from '$PRE_COMMIT_BIN --version'; installing $PRE_COMMIT_PIN"
87-
# Already sorted means current >= the first affected version.
88-
elif printf '%s\n%s\n' "$PRE_COMMIT_BAD_FROM_VERSION" "$PRE_COMMIT_CURRENT_VERSION" | sort -V -C; then
89-
echo "pre-commit $PRE_COMMIT_CURRENT_VERSION at $PRE_COMMIT_BIN is affected; installing $PRE_COMMIT_PIN"
90-
else
91-
PRE_COMMIT_NEEDS_PIN="false"
92-
echo "pre-commit $PRE_COMMIT_CURRENT_VERSION at $PRE_COMMIT_BIN predates the issue; using it as-is"
93-
fi
94-
fi
95-
echo "PRE_COMMIT_PIN=$PRE_COMMIT_PIN" >> $GITHUB_ENV
96-
echo "PRE_COMMIT_NEEDS_PIN=$PRE_COMMIT_NEEDS_PIN" >> $GITHUB_ENV
97-
9866
# Finding python
9967
# This will set an environment variable we can use to conditionally
10068
# install python.
10169
PYTHON_BIN=$(command -v python || true)
10270
echo "PYTHON_BIN=$PYTHON_BIN" >> $GITHUB_ENV
10371
- name: Setup python
104-
# Needed only when we have to install our own pinned pre-commit
105-
if: env.PYTHON_BIN == null && env.PRE_COMMIT_NEEDS_PIN == 'true' && steps.pre-commit-config.outputs.exists != 'false'
72+
# Only run this if we don't already have a pre-commit on the PATH
73+
if: env.PYTHON_BIN == null && env.PRE_COMMIT_BIN == null && steps.pre-commit-config.outputs.exists != 'false'
10674
uses: actions/setup-python@v7
10775
- name: Determine node version
10876
id: node-version
@@ -123,6 +91,49 @@ runs:
12391
uses: actions/setup-node@v7
12492
with:
12593
node-version: ${{ steps.node-version.outputs.version }}
94+
- name: Ensure a verified-safe npm outside $HOME
95+
shell: bash
96+
run: |
97+
# npm 11.9.0-11.12.x has a bug (npm/cli#9189, fixed in 11.13.0 via
98+
# npm/cli#9206/#9237): --allow-git=root incorrectly rejects
99+
# legitimate root-level git installs, breaking every `language:
100+
# node` pre-commit hook with additional_dependencies (mirrors-
101+
# prettier, mirrors-eslint) with EALLOWGIT.
102+
#
103+
# pre-commit only reuses an already-installed node/npm when it
104+
# resolves outside $HOME (pre_commit/lang_base.py::exe_exists). Our
105+
# self-hosted runners install node under $HOME (RUNNER_TOOL_CACHE),
106+
# so without this, pre-commit ignores the npm we just set up and
107+
# downloads its own via nodeenv instead -- whose bundled npm can
108+
# land in the same affected range.
109+
#
110+
# Pinned, not "latest": to bump, re-verify against the new version
111+
# first (see PR description), the same way a hook rev bump gets
112+
# verified. An open range would silently drift back into a broken
113+
# npm the same way this bug shipped in the first place.
114+
PRE_COMMIT_NPM_PIN="[email protected]"
115+
116+
node_bin="$(command -v node || true)"
117+
npm_bin="$(command -v npm || true)"
118+
if [[ -z "$node_bin" || -z "$npm_bin" ]]; then
119+
echo "node/npm not on PATH; leaving pre-commit to manage its own"
120+
exit 0
121+
fi
122+
123+
# Deliberately not named "shims": pre-commit rejects those paths.
124+
dir="${RUNNER_TEMP:-/tmp}/action-pre-commit-node"
125+
if [[ "$dir" == "$HOME"* ]]; then
126+
dir=/tmp/action-pre-commit-node
127+
fi
128+
mkdir -p "$dir"
129+
ln -sf "$node_bin" "$dir/node"
130+
ln -sf "$npm_bin" "$dir/npm"
131+
echo "$dir" >> "$GITHUB_PATH"
132+
export PATH="$dir:$PATH"
133+
134+
npm install -g "$PRE_COMMIT_NPM_PIN"
135+
hash -r
136+
echo "npm pinned to $(npm --version) (was $("$npm_bin" --version))"
126137
- name: Commitlint
127138
# This version needs to be sync'd with the repo HEAD if a major version is cut
128139
if: inputs.disable-commitlint != 'true'
@@ -185,22 +196,10 @@ runs:
185196
AWS_REGION: ${{ inputs.s3-bucket-region }}
186197
cache-name: ${{ github.event.repository.name }}/cache-pre-commit
187198
- name: Install Pre-commit
188-
# Runs when PATH has no pre-commit, or one affected by the node-hook
189-
# install bug described in "Version files".
190-
if: env.PRE_COMMIT_NEEDS_PIN == 'true' && steps.pre-commit-config.outputs.exists != 'false'
191-
env:
192-
RUNNER_TEMP: ${{ runner.temp }}
199+
if: env.PRE_COMMIT_BIN == null && steps.pre-commit-config.outputs.exists != 'false'
193200
run: |
194-
# Install into a dedicated venv and put it first on PATH. A plain
195-
# `pip install` cannot be relied on to shadow a pre-commit pre-baked
196-
# into the runner image (e.g. /usr/local/bin/pre-commit), which can sit
197-
# outside pip's install prefix or need elevated permissions to replace.
198-
python="$(command -v python3 || command -v python)"
199-
venv="$RUNNER_TEMP/action-pre-commit-venv"
200-
"$python" -m venv "$venv"
201-
"$venv/bin/pip" install --quiet "$PRE_COMMIT_PIN"
202-
echo "$venv/bin" >> "$GITHUB_PATH"
203-
echo "installed $("$venv/bin/pre-commit" --version) into $venv"
201+
pip install pre-commit
202+
pip freeze --local
204203
shell: bash
205204
- name: Pre-commit (from PATH)
206205
shell: bash

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.