Skip to content

Commit 4dfca9a

Browse files
authored
Update attributions-check.sh
1 parent bba4201 commit 4dfca9a

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

development/attributions-check.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
#!/bin/bash
2+
/**
3+
* @fileoverview Script to verify that the committed 'attribution.txt' file is up-to-date.
4+
* This is achieved by regenerating the attributions and checking for uncommitted changes.
5+
* The script will fail if the committed file is stale.
6+
*/
27

3-
set -e
4-
set -u
5-
set -o pipefail
8+
# Enable strict mode:
9+
# -e: Exit immediately if a command exits with a non-zero status.
10+
# -u: Treat unset variables as an error.
11+
# -o pipefail: The whole pipeline fails if any command in the pipeline fails.
12+
set -euo pipefail
613

14+
ATTRIBUTIONS_FILE="./attribution.txt"
15+
16+
echo "1. Regenerating attribution file..."
17+
# Run the tool that generates the attribution file based on current dependencies.
18+
# If this command fails, the script will exit immediately due to 'set -e'.
719
yarn attributions:generate
820

9-
ATTRIBUTIONS_FILE="./attribution.txt"
21+
echo "2. Checking for uncommitted changes in ${ATTRIBUTIONS_FILE}..."
1022

11-
# check to see if there's changes on the attributions file
23+
# git diff --exit-code returns:
24+
# 0: No differences found (file is up-to-date).
25+
# 1: Differences found (file is stale).
26+
# >1: Error occurred (caught by set -e, but added for clarity).
1227
if ! git diff --exit-code "$ATTRIBUTIONS_FILE"; then
13-
echo "The set of attributions kept in \`attribution.txt\` are out of date."
14-
echo "Run \`yarn attributions:generate\` to regenerate them and commit and push the changes."
15-
echo "If you're looking at a pull request, you can also post the comment \`@metamaskbot update-attributions\` and the file will be automatically regenerated for you."
28+
# If git diff returns 1 (differences found), the 'if !' block executes.
29+
30+
echo "--- ERROR: ATTRIBUTIONS FILE IS STALE ---" >&2
31+
echo "The set of attributions kept in \`${ATTRIBUTIONS_FILE}\` are out of date." >&2
32+
echo "Action Required:" >&2
33+
echo "1. Run \`yarn attributions:generate\` locally." >&2
34+
echo "2. Commit and push the updated file." >&2
35+
echo "If running in a Pull Request, you can also post the comment \`@metamaskbot update-attributions\`." >&2
36+
37+
# Exit with status 1 to fail the check.
1638
exit 1
1739
fi
40+
41+
echo "Success: The attribution file is up to date."

0 commit comments

Comments
 (0)