Debian Codegraph @

extra/protobuf/protobuf-24.4/ci/push_auto_update.sh

raw
1 #!/bin/bash
2
3 # This script updates src/file_lists.cmake and the checked-in generated code
4 # for the well-known types, commits the resulting changes, and pushes them.
5 # This does not do anything useful when run manually, but should be run by our
6 # GitHub action instead.
7
8 set -ex
9
10 # Cd to the repo root.
11 cd $(dirname -- "$0")/..
12
13 previous_commit_title=$(git log -1 --pretty='%s')
14
15 # Exit early if the previous commit was auto-generated. This reduces the risk
16 # of a bug causing an infinite loop of auto-generated commits.
17 if (echo "$previous_commit_title" | grep -q "^Auto-generate files"); then
18 echo "Previous commit was auto-generated"
19 exit 0
20 fi
21
22 ./regenerate_stale_files.sh
23
24 # Try to determine the most recent CL or pull request.
25 pr_from_merge=$(echo "$previous_commit_title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p')
26 pr_from_squash=$(echo "$previous_commit_title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p')
27 cl=$(git log -1 --pretty='%b' | sed -n 's/^PiperOrigin-RevId: \([0-9]*\)$/\1/p')
28
29 if [ ! -z "$pr_from_merge" ]; then
30 commit_message="Auto-generate files after PR #$pr_from_merge"
31 elif [ ! -z "$pr_from_squash" ]; then
32 commit_message="Auto-generate files after PR #$pr_from_squash"
33 elif [ ! -z "$cl" ]; then
34 commit_message="Auto-generate files after cl/$cl"
35 else
36 # If we are unable to determine the CL or pull request number, we fall back
37 # on this default commit message. Typically this should not occur, but could
38 # happen if a pull request was merged via a rebase.
39 commit_message="Auto-generate files"
40 fi
41
42 git add -A
43 git diff --staged --quiet || git commit -am "$commit_message"
44 git pull --rebase
45 git push --force-with-lease || echo "Conflicting commit hit, retrying in next job..."