Skip to content

Commit 59254fd

Browse files
committed
ci: pin prettier via npm ci, add .nvmrc, format CUSTOMIZE.md
1 parent a6fa6cd commit 59254fd

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

.github/workflows/prettier.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@ jobs:
1919
uses: actions/checkout@v4
2020
- name: Setup Node.js ⚙️
2121
uses: actions/setup-node@v4
22-
- name: Install Prettier 💾
23-
run: npm install --save-dev --save-exact prettier @shopify/prettier-plugin-liquid
22+
with:
23+
node-version-file: .nvmrc
24+
cache: npm
25+
- name: Install dependencies 💾
26+
# Use `npm ci` so the exact versions from package-lock.json are installed,
27+
# matching what runs locally via the pre-commit hook.
28+
run: npm ci
29+
- name: Show Prettier version 🧾
30+
run: npx --no-install prettier --version
2431
- name: Prettier Check 🔎
2532
id: prettier
26-
run: npx prettier . --check
33+
run: npx --no-install prettier . --check
2734
- name: Create diff 📝
2835
# https://docs.github.com/en/actions/learn-github-actions/expressions#failure
2936
if: ${{ failure() }}
3037
run: |
31-
npx prettier . --write
38+
npx --no-install prettier . --write
3239
git diff -- . ':(exclude)package-lock.json' ':(exclude)package.json' > diff.txt
3340
npm install -g diff2html-cli
3441
diff2html -i file -s side -F diff.html -- diff.txt

.github/workflows/update-tocs.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@ jobs:
4545
4646
- name: Setup Node.js
4747
uses: actions/setup-node@v4
48+
with:
49+
node-version-file: .nvmrc
50+
cache: npm
51+
52+
- name: Install dependencies
53+
if: steps.changed-files.outputs.any_changed == 'true'
54+
# Use `npm ci` so the exact prettier version from package-lock.json is
55+
# installed, matching what runs locally via the pre-commit hook.
56+
# Otherwise differing prettier versions can produce different output,
57+
# causing local pre-commit and this workflow to overwrite each other
58+
# in a push/auto-commit loop.
59+
run: npm ci
4860

4961
- name: Run Prettier on changed files
5062
if: steps.changed-files.outputs.any_changed == 'true'
5163
run: |
52-
npm install --save-dev --save-exact prettier @shopify/prettier-plugin-liquid
64+
npx --no-install prettier --version
5365
for file in ${ALL_CHANGED_FILES}; do
5466
if [[ "$file" == *.md ]]; then
55-
npx prettier --write "$file"
67+
npx --no-install prettier --write "$file"
5668
fi
5769
done
5870

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

.pre-commit-config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ repos:
4141
hooks:
4242
- id: prettier
4343
name: prettier
44-
entry: npx prettier --write
44+
# `--no-install` forces npx to use the local prettier from node_modules
45+
# (pinned in package.json / package-lock.json) instead of silently
46+
# downloading a different version. Run `npm ci` if this errors out.
47+
entry: npx --no-install prettier --write
4548
language: system
4649
files: \.(js|jsx|ts|tsx|css|scss|md|mdx|html|liquid|json|yml|yaml)$
4750
exclude: |
@@ -59,7 +62,7 @@ repos:
5962
# Full repo check on push (matches CI: npx prettier . --check)
6063
- id: prettier-check-all
6164
name: prettier-check-all
62-
entry: npx prettier . --check
65+
entry: npx --no-install prettier . --check
6366
language: system
6467
pass_filenames: false
6568
always_run: true

CUSTOMIZE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Here we will give you some tips on how to customize the website. One important t
6262
- [How it works](#how-it-works)
6363
- [Configuration](#configuration-1)
6464
- [Disable related posts for a specific post](#disable-related-posts-for-a-specific-post)
65-
- [Additional configuration in _config.yml](#additional-configuration-in-_configyml)
65+
- [Additional configuration in \_config.yml](#additional-configuration-in-_configyml)
6666
- [Managing publication display](#managing-publication-display)
6767
- [Adding a Google Calendar](#adding-a-google-calendar)
6868
- [Basic usage](#basic-usage)

0 commit comments

Comments
 (0)