• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8set -ex
9
10# Cd to the repo root.
11cd $(dirname -- "$0")/..
12
13previous_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.
17if (echo "$previous_commit_title" | grep -q "^Auto-generate files"); then
18  echo "Previous commit was auto-generated"
19  exit 0
20fi
21
22export BAZEL=bazelisk
23export USE_BAZEL_VERSION=7.2.1
24
25./regenerate_stale_files.sh
26
27# Try to determine the most recent CL or pull request.
28pr_from_merge=$(echo "$previous_commit_title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p')
29pr_from_squash=$(echo "$previous_commit_title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p')
30cl=$(git log -1 --pretty='%b' | sed -n 's/^PiperOrigin-RevId: \([0-9]*\)$/\1/p')
31
32if [ ! -z "$pr_from_merge" ]; then
33  commit_message="Auto-generate files after PR #$pr_from_merge"
34elif [ ! -z "$pr_from_squash" ]; then
35  commit_message="Auto-generate files after PR #$pr_from_squash"
36elif [ ! -z "$cl" ]; then
37  commit_message="Auto-generate files after cl/$cl"
38else
39  # If we are unable to determine the CL or pull request number, we fall back
40  # on this default commit message. Typically this should not occur, but could
41  # happen if a pull request was merged via a rebase.
42  commit_message="Auto-generate files"
43fi
44
45git add -A
46git diff --staged --quiet || git commit -am "$commit_message"
47git pull --rebase
48git push --force-with-lease || echo "Conflicting commit hit, retrying in next job..."
49