|
1 | 1 | #!/bin/bash |
2 | 2 | set -e |
3 | 3 | # This script should be run at the root of the repository. |
4 | | -# This script is used to, when a pull request changes any file in the repo: |
5 | | -# 1. Compare generation configurations in the current branch (with which the |
| 4 | +# This script is used to, when a pull request changes the generation |
| 5 | +# configuration (generation_config.yaml by default): |
| 6 | +# 1. Find whether the last commit in this pull request contains changes to |
| 7 | +# the generation configuration and exit early if it doesn't have such a change |
| 8 | +# since the generation result would be the same. |
| 9 | +# 2. Compare generation configurations in the current branch (with which the |
6 | 10 | # pull request associated) and target branch (into which the pull request is |
7 | 11 | # merged); |
8 | | -# 2. Generate changed libraries using library_generation image; |
9 | | -# 3. Commit the changes to the pull request, if any. |
10 | | -# 4. Edit the PR body with generated pull request description, if applicable. |
| 12 | +# 3. Generate changed libraries using library_generation image; |
| 13 | +# 4. Commit the changes to the pull request, if any. |
| 14 | +# 5. Edit the PR body with generated pull request description, if applicable. |
11 | 15 |
|
12 | 16 | # The following commands need to be installed before running the script: |
13 | 17 | # 1. git |
@@ -63,6 +67,13 @@ message="chore: generate libraries at $(date)" |
63 | 67 |
|
64 | 68 | git checkout "${target_branch}" |
65 | 69 | git checkout "${current_branch}" |
| 70 | +# if the last commit doesn't contain changes to generation configuration, |
| 71 | +# do not generate again as the result will be the same. |
| 72 | +change_of_last_commit="$(git diff-tree --no-commit-id --name-only HEAD~1..HEAD -r)" |
| 73 | +if [[ ! ("${change_of_last_commit}" == *"${generation_config}"*) ]]; then |
| 74 | + echo "The last commit doesn't contain any changes to the generation_config.yaml, skipping the whole generation process." || true |
| 75 | + exit 0 |
| 76 | +fi |
66 | 77 | # copy generation configuration from target branch to current branch. |
67 | 78 | git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}" |
68 | 79 | config_diff=$(diff "${generation_config}" "${baseline_generation_config}" || true) |
|
0 commit comments