-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add npm package diff comments for all PRs
- Loading branch information
1 parent
8f2411f
commit f514d76
Showing
3 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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,33 +1,54 @@ | ||
#!/bin/sh | ||
set -ex | ||
|
||
# Computes the diff of `dist` between a provided base reference (branch, tag, commit SHA) and the current HEAD. | ||
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
# Computes the diff of `packages/govuk-frontend/dist` between a provided base reference (branch, tag, commit SHA) and the current HEAD. | ||
# It outputs the resulting diff in the provided output folder | ||
# | ||
# Usage: `bin/dist-diff.sh <base-reference> <output-folder>` | ||
# Usage: `bin/package-diff.sh <base-reference> <output-folder>` | ||
|
||
# Default the base branch to main to allow running locally quickly | ||
base="${1:-main}" | ||
# And the output folder to the current working directory | ||
output_folder="${2:-`pwd`}" | ||
|
||
rm -Rf .cache/diff/dist | ||
mkdir -p .cache/diff/dist/base | ||
mkdir -p .cache/diff/dist/head | ||
rm -Rf .cache/diff/package | ||
mkdir -p .cache/diff/package | ||
|
||
# Switch to base branch | ||
git checkout $base | ||
|
||
# Build package for base branch | ||
npm install --ignore-scripts --no-save --silent | ||
npm run build:package --ignore-scripts | ||
|
||
# Switch back to original branch | ||
git checkout $CURRENT_BRANCH_NAME | ||
|
||
# Commit build output from base branch | ||
git add --force packages/govuk-frontend/dist/ | ||
git commit -m "Build output for '$base'" --no-verify | ||
|
||
# Build package for original branch | ||
npm install --ignore-scripts --no-save --silent | ||
npm run build:package --ignore-scripts | ||
|
||
# Commit build output from original branch | ||
git add --force packages/govuk-frontend/dist/ | ||
git commit -m "Build output for '$CURRENT_BRANCH_NAME'" --no-verify | ||
|
||
# Diff the minified JS file | ||
git diff \ | ||
$base:dist/govuk-frontend-$(git show $base:dist/VERSION.txt).min.js \ | ||
dist/govuk-frontend-$(cat dist/VERSION.txt).min.js \ | ||
> $output_folder/.cache/diff/dist/js.diff | ||
git diff HEAD^ -- packages/govuk-frontend/dist/govuk/govuk-frontend.min.js \ | ||
> $output_folder/.cache/diff/package/js.diff | ||
|
||
# Diff the minified CSS file | ||
git diff \ | ||
$base:dist/govuk-frontend-$(git show $base:dist/VERSION.txt).min.css \ | ||
dist/govuk-frontend-$(cat dist/VERSION.txt).min.css \ | ||
> $output_folder/.cache/diff/dist/css.diff | ||
# # Diff the minified CSS file | ||
git diff HEAD^ -- packages/govuk-frontend/dist/govuk/govuk-frontend.min.css \ | ||
> $output_folder/.cache/diff/package/css.diff | ||
|
||
# Diff the rest of the files, excluding the sourcemaps and the minified files | ||
# See https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec | ||
git diff -M05 $base -- dist ":(exclude)dist/*.min.*" \ | ||
> $output_folder/.cache/diff/dist/other.diff | ||
git diff -M05 HEAD^ -- packages/govuk-frontend/dist \ | ||
":(exclude)**/*.map" \ | ||
":(exclude)**/*.min.*" \ | ||
> $output_folder/.cache/diff/package/other.diff |