|
1 | 1 | #!/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 | + */ |
2 | 7 |
|
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 |
6 | 13 |
|
| 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'. |
7 | 19 | yarn attributions:generate |
8 | 20 |
|
9 | | -ATTRIBUTIONS_FILE="./attribution.txt" |
| 21 | +echo "2. Checking for uncommitted changes in ${ATTRIBUTIONS_FILE}..." |
10 | 22 |
|
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). |
12 | 27 | 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. |
16 | 38 | exit 1 |
17 | 39 | fi |
| 40 | + |
| 41 | +echo "Success: The attribution file is up to date." |
0 commit comments