1#!/bin/bash 2 3# Protocol Buffers - Google's data interchange format 4# Copyright 2023 Google LLC. All rights reserved. 5# https://developers.google.com/protocol-buffers/ 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are 9# met: 10# 11# * Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# * Redistributions in binary form must reproduce the above 14# copyright notice, this list of conditions and the following disclaimer 15# in the documentation and/or other materials provided with the 16# distribution. 17# * Neither the name of Google LLC nor the names of its 18# contributors may be used to endorse or promote products derived from 19# this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 33# This script updates checked-in generated files (currently CMakeLists.txt, 34# descriptor.upb.h, and descriptor.upb.c), commits the resulting change, and 35# pushes it. This does not do anything useful when run manually, but should be 36# run by our GitHub action instead. 37 38set -ex 39 40# Exit early if the previous commit was made by the bot. This reduces the risk 41# of a bug causing an infinite loop of auto-generated commits. 42if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then 43 echo "Previous commit was authored by bot" 44 exit 0 45fi 46 47cd $(dirname -- "$0")/.. 48bazel test //cmake:test_generated_files || bazel-bin/cmake/test_generated_files --fix 49 50# Try to determine the most recent pull request number. 51title=$(git log -1 --pretty='%s') 52pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') 53pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') 54 55pr_number="" 56if [ ! -z "$pr_from_merge" ]; then 57 pr_number="$pr_from_merge" 58elif [ ! -z "$pr_from_squash" ]; then 59 pr_number="$pr_from_squash" 60fi 61 62if [ ! -z "$pr_number" ]; then 63 commit_message="Auto-generate CMake file lists after PR #$pr_number" 64else 65 # If we are unable to determine the pull request number, we fall back on this 66 # default commit message. Typically this should not occur, but could happen 67 # if a pull request was merged via a rebase. 68 commit_message="Auto-generate CMake file lists" 69fi 70 71git add -A 72git diff --staged --quiet || git commit -am "$commit_message" 73git push 74