-
Notifications
You must be signed in to change notification settings - Fork 384
feat: Adds in skeleton recipe pre-commit hook #3500
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
Open
andguy95
wants to merge
11
commits into
main
Choose a base branch
from
an-feat-skeleton-recipe-commit-hook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5da5196
feat: initial affected files look up + pre-commit hook
andguy95 b559ddb
feat: adds in a command to print all files that a recipe would get af…
andguy95 ada22a5
feat: updates the print to show which recipes depend on the files cha…
andguy95 ac9c24e
feat: adds an additional flag to only show skeleton files affected fo…
andguy95 76ab12a
chore: update the warning message for recipe check
andguy95 051ad0e
chore: update the command to use regenerate instead of update
andguy95 6aaf063
Merge branch 'main' of https://github.com/Shopify/hydrogen into an-fe…
andguy95 79e23de
fix: typescript error in dep graph test
andguy95 da58e27
fix: removes the deleted files from the dependency graph
andguy95 0af4165
fix: PR comments for small fixes and edge cases
andguy95 7de38d4
fix: type error in dependency-graph.ts
andguy95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| npx lint-staged && npm run pre-commit:encrypt | ||
| npx lint-staged && npm run pre-commit:encrypt && bash cookbook/scripts/pre-commit.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
| # Detects skeleton file changes and warns about recipes that may need updating. | ||
| # Always exits 0 — this check is informational only. | ||
| # Bypass: git commit --no-verify | ||
|
|
||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
|
|
||
| # 1. Find staged skeleton files | ||
| STAGED=$(git diff --cached --name-only -- 'templates/skeleton/') | ||
| if [ -z "$STAGED" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 2. Find affected recipes (one name per line) | ||
| AFFECTED=$(cd "$REPO_ROOT/cookbook" && npm run --silent cookbook -- affected-recipes $STAGED 2>/dev/null) | ||
andguy95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if [ -z "$AFFECTED" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 3. Print actionable warning | ||
| echo "" | ||
| echo "⚠️ Skeleton changes detected. The following recipes may need updating:" | ||
| echo "" | ||
| while IFS= read -r recipe; do | ||
| echo " - $recipe" | ||
| echo "" | ||
andguy95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| done <<< "$AFFECTED" | ||
| echo " After committing your skeleton changes, run the following to update affected recipes:" | ||
| while IFS= read -r recipe; do | ||
| echo " cd cookbook && npm run cookbook -- regenerate --recipe $recipe --format github" | ||
| done <<< "$AFFECTED" | ||
| echo "" | ||
| echo " Note: the regenerate command requires a clean working tree — run it after committing." | ||
| echo " To skip this skeleton changes warning: git commit --no-verify" | ||
| echo "" | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import {describe, expect, it, vi, beforeEach} from 'vitest'; | ||
| import {affectedRecipes} from './affected-recipes'; | ||
|
|
||
| vi.mock('../lib/dependency-graph', () => ({getAffectedRecipes: vi.fn()})); | ||
|
|
||
| import {getAffectedRecipes} from '../lib/dependency-graph'; | ||
|
|
||
| const mockGetAffectedRecipes = vi.mocked(getAffectedRecipes); | ||
|
|
||
| // Extract the handler for direct invocation in tests | ||
| const handler = affectedRecipes.handler as (args: { | ||
| files: string[]; | ||
| json: boolean; | ||
| }) => void; | ||
|
|
||
| describe('affected-recipes command handler', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| it('passes the files array to getAffectedRecipes', () => { | ||
| mockGetAffectedRecipes.mockReturnValue([]); | ||
| const files = [ | ||
| 'templates/skeleton/app/root.tsx', | ||
| 'templates/skeleton/app/server.ts', | ||
| ]; | ||
|
|
||
| handler({files, json: false}); | ||
|
|
||
| expect(mockGetAffectedRecipes).toHaveBeenCalledWith(files); | ||
| }); | ||
|
|
||
| it('prints one recipe name per line by default', () => { | ||
| mockGetAffectedRecipes.mockReturnValue(['multipass', 'b2b', 'markets']); | ||
|
|
||
| handler({files: ['templates/skeleton/app/root.tsx'], json: false}); | ||
|
|
||
| expect(console.log).toHaveBeenCalledTimes(3); | ||
| expect(console.log).toHaveBeenNthCalledWith(1, 'multipass'); | ||
| expect(console.log).toHaveBeenNthCalledWith(2, 'b2b'); | ||
| expect(console.log).toHaveBeenNthCalledWith(3, 'markets'); | ||
| }); | ||
|
|
||
| it('prints JSON array when --json flag is set', () => { | ||
| mockGetAffectedRecipes.mockReturnValue(['multipass', 'b2b']); | ||
|
|
||
| handler({files: ['templates/skeleton/app/root.tsx'], json: true}); | ||
|
|
||
| expect(console.log).toHaveBeenCalledTimes(1); | ||
| expect(console.log).toHaveBeenCalledWith( | ||
| JSON.stringify(['multipass', 'b2b']), | ||
| ); | ||
| }); | ||
|
|
||
| it('produces no output when no recipes are affected', () => { | ||
| mockGetAffectedRecipes.mockReturnValue([]); | ||
|
|
||
| handler({files: ['templates/skeleton/app/root.tsx'], json: false}); | ||
andguy95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| expect(console.log).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| import { CommandModule } from 'yargs'; | ||||||
| import { getAffectedRecipes } from '../lib/dependency-graph'; | ||||||
andguy95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| type AffectedRecipesArgs = { | ||||||
| files: string[]; | ||||||
| json: boolean; | ||||||
| }; | ||||||
|
|
||||||
| export const affectedRecipes: CommandModule<{}, AffectedRecipesArgs> = { | ||||||
| command: 'affected-recipes [files..]', | ||||||
| describe: 'List recipes affected by changes to the given skeleton files', | ||||||
| builder: { | ||||||
| files: { | ||||||
| type: 'array', | ||||||
andguy95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| description: 'Repo-relative paths to changed skeleton files', | ||||||
| default: [], | ||||||
| }, | ||||||
| json: { | ||||||
| type: 'boolean', | ||||||
| description: 'Output as JSON array instead of newline-separated names', | ||||||
| default: false, | ||||||
| }, | ||||||
| }, | ||||||
| handler({ files, json }) { | ||||||
| const affected = getAffectedRecipes(files as string[]); | ||||||
|
||||||
| const affected = getAffectedRecipes(files as string[]); | |
| const affected = getAffectedRecipes(files); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| export {affectedRecipes} from './affected-recipes'; | ||
| export {apply} from './apply'; | ||
| export {generate} from './generate'; | ||
| export {regenerate} from './regenerate'; | ||
| export {render} from './render'; | ||
| export {skeletonFiles} from './skeleton-files'; | ||
| export {update} from './update'; | ||
| export {validate} from './validate'; | ||
| export {schema} from './schema'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.