-
Notifications
You must be signed in to change notification settings - Fork 11
feat: verify package-lock.json
is UTD (up to date) & audited
#4598
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
mfranzke
wants to merge
42
commits into
main
Choose a base branch
from
feat-verify-package-lock-utd
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 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
41664a4
feat: we'd like to provide a quick check regarding
mfranzke eeeea2d
chore: worth a try
mfranzke cd63f49
Revert "chore: worth a try"
mfranzke 45e3a05
Reapply "chore: worth a try"
mfranzke 9ea15af
refactor: incorrect parameter
mfranzke 5f01b94
refactor: corrected package-lock file
mfranzke 52c9f51
chore: another try
mfranzke 0e558d1
Revert "chore: another try"
mfranzke ae9a456
chore: another try
mfranzke 3e6295f
Revert "chore: another try"
mfranzke 024e42e
Reapply "chore: another try"
mfranzke a8fd3d4
Revert "Reapply "chore: another try""
mfranzke b990c9f
Reapply "Reapply "chore: another try""
mfranzke d0c57f7
refactor: modified this file
mfranzke 8d59270
Revert "Reapply "Reapply "chore: another try"""
mfranzke 21dfc4e
Reapply "Reapply "Reapply "chore: another try"""
mfranzke c8e1a6a
Revert "Reapply "Reapply "Reapply "chore: another try""""
mfranzke db0ebcd
Reapply "Reapply "Reapply "Reapply "chore: another try""""
mfranzke 921422d
chore: another try
mfranzke c02b633
Revert "chore: another try"
mfranzke b79000f
chore: another try
mfranzke 0fb88bb
refactor: another try
mfranzke b729283
refactor: necessary update
mfranzke 2029b99
Merge branch 'main' into feat-verify-package-lock-utd
mfranzke 3439669
refactor: regenerated package lock file
mfranzke dc4b0a2
refactor: generalize this
mfranzke a5499b0
refactor: removed that package again
mfranzke e5e312b
refactor: get rid of the dependency
mfranzke 632641d
Merge branch 'main' into feat-verify-package-lock-utd
mfranzke d73952b
refactor: ensure that npm audit has fixed dependencies
mfranzke 38dae5a
Update pre-push
mfranzke 1c82d8a
refactor: conditionally run based on the package manager
mfranzke 6c0e346
Update .husky/pre-push
mfranzke 49031db
Update .config/.lintstagedrc.js
mfranzke 5018003
Update .husky/pre-push
mfranzke 97efc60
Update .husky/pre-push
mfranzke 595dfbf
Merge branch 'main' into feat-verify-package-lock-utd
michaelmkraus 159f7ea
Merge branch 'main' into feat-verify-package-lock-utd
michaelmkraus 224b4ef
auto update snapshots (#4730)
github-actions[bot] d43638d
Update .husky/pre-push
mfranzke b2acd41
Merge branch 'main' into feat-verify-package-lock-utd
mfranzke 3747b9c
auto update snapshots (#4732)
github-actions[bot] 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
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,78 @@ | ||
# Configuration: Define checks as functions for better maintainability | ||
# Each check function should: | ||
# - Define a PATTERN variable for file matching | ||
# - Define a COMMAND variable for the command to run | ||
# - Define a DESCRIPTION variable for user feedback | ||
|
||
check_npm_files() { | ||
PATTERN='^(package\.json|package-lock\.json)$' | ||
michaelmkraus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
COMMAND='npm install --package-lock-only --ignore-scripts' | ||
DESCRIPTION='package.json or package-lock.json – please run npm install to update dependencies' | ||
} | ||
|
||
check_pnpm_files() { | ||
PATTERN='^(package\.json|pnpm-lock\.yaml)$' | ||
COMMAND='pnpm install --lockfile-only --ignore-scripts' | ||
DESCRIPTION='package.json or pnpm-lock.yaml – please run pnpm install to update dependencies' | ||
} | ||
|
||
# List of all check functions | ||
# Detect the lock file to determine the package manager | ||
if [ -f "pnpm-lock.yaml" ]; then | ||
CHECK_FUNCTIONS=( | ||
"check_pnpm_files" | ||
) | ||
elif [ -f "package-lock.json" ]; then | ||
CHECK_FUNCTIONS=( | ||
"check_npm_files" | ||
) | ||
else | ||
echo "No lock file detected for pnpm or npm. Aborting pre-push checks." | ||
exit 1 | ||
fi | ||
|
||
# Check for changes in specified files before pushing and run corresponding commands | ||
## Get the upstream branch | ||
UPSTREAM=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "") | ||
if [ -z "$UPSTREAM" ]; then | ||
echo "No upstream configured, detecting default branch." | ||
# Try to detect the default branch from origin/HEAD | ||
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@') | ||
if [ -z "$DEFAULT_BRANCH" ]; then | ||
echo "Could not detect default branch, falling back to 'main'." | ||
DEFAULT_BRANCH="main" | ||
michaelmkraus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
UPSTREAM="$DEFAULT_BRANCH" | ||
fi | ||
|
||
## Get the list of files changed between upstream and HEAD | ||
FILES=$(git diff --name-only "$UPSTREAM"..HEAD) | ||
|
||
## Check each pattern and run corresponding command | ||
for check_function in "${CHECK_FUNCTIONS[@]}"; do | ||
# Call the check function to set variables | ||
$check_function | ||
|
||
if echo "$FILES" | grep -qE "$PATTERN"; then | ||
mfranzke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "Detected changes in $DESCRIPTION" | ||
|
||
## Run the corresponding command | ||
$COMMAND | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Command failed: $COMMAND. Aborting push." | ||
exit 1 | ||
fi | ||
|
||
# Check for file modifications after running the command | ||
MODIFIED_FILES=$(git diff --name-only) | ||
if [ -n "$MODIFIED_FILES" ]; then | ||
echo "Detected file modifications after running $COMMAND:" | ||
echo "$MODIFIED_FILES" | ||
echo "Please stage the changes before pushing." | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
|
||
echo "No monitored file changes detected. Skipping checks." |
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.