Update auto-generation script to handle well-known types

I went ahead and deleted the update_file_list.sh script, because (a)
there was no good reason for it to be in a separate script and (b) we
now need to handle the well-known types in addition to file_lists.cmake.
With this change, we just invoke the staleness tests from the main
script to update everything.

While I was at it I made a couple small fixes:
- Don't skip the update step just because the previous commit was by
  "Protobuf Team Bot". Copybara commits use this name and we still want
  to do the auto-update step after them.
- Include the CL number in the description if the previous commit came
  from a CL.

PiperOrigin-RevId: 487231324
pull/10924/head
Adam Cozzette 2 years ago committed by Copybara-Service
parent 9b81aaae58
commit f1998d91a8
  1. 8
      .github/workflows/generate_files.yml
  2. 1
      BUILD.bazel
  3. 41
      cmake/push_auto_update.sh
  4. 8
      cmake/update_file_lists.sh
  5. 46
      push_auto_update.sh

@ -1,12 +1,12 @@
name: Generate CMake File Lists name: Auto-generate checked-in files
on: on:
push: push:
branches: branches:
- main - main
- '[0-9]+.x' - '[0-9]+.x'
# The 21.x branch predates support for auto-generation of the CMake file # The 21.x branch predates support for auto-generation, so we make sure
# lists, so we make sure to exclude it. # to exclude it.
- '!21.x' - '!21.x'
jobs: jobs:
@ -26,4 +26,4 @@ jobs:
- name: Configure name and email address in Git - name: Configure name and email address in Git
run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com"
- name: Commit and push update - name: Commit and push update
run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh run: cd ${{ github.workspace }} && ./push_auto_update.sh

@ -551,7 +551,6 @@ pkg_files(
"WORKSPACE", "WORKSPACE",
"cmake/CMakeLists.txt", "cmake/CMakeLists.txt",
"cmake/README.md", "cmake/README.md",
"cmake/update_file_lists.sh",
"generate_descriptor_proto.sh", "generate_descriptor_proto.sh",
"maven_install.json", "maven_install.json",
"//third_party:BUILD.bazel", "//third_party:BUILD.bazel",

@ -1,41 +0,0 @@
#!/bin/bash
# This script updates the CMake file lists (i.e. src/file_lists.cmake), commits
# the resulting change, and pushes it. This does not do anything useful when
# run manually, but should be run by our GitHub action instead.
set -ex
# Exit early if the previous commit was made by the bot. This reduces the risk
# of a bug causing an infinite loop of auto-generated commits.
if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then
echo "Previous commit was authored by bot"
exit 0
fi
$(dirname -- "$0")/update_file_lists.sh
# Try to determine the most recent pull request number.
title=$(git log -1 --pretty='%s')
pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p')
pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p')
pr=""
if [ ! -z "$pr_from_merge" ]; then
pr="$pr_from_merge"
elif [ ! -z "$pr_from_squash" ]; then
pr="$pr_from_squash"
fi
if [ ! -z "$pr" ]; then
commit_message="Auto-generate CMake file lists after PR #$pr"
else
# If we are unable to determine the pull request number, we fall back on this
# default commit message. Typically this should not occur, but could happen
# if a pull request was merged via a rebase.
commit_message="Auto-generate CMake file lists"
fi
git add -A
git diff --staged --quiet || git commit -am "$commit_message"
git push

@ -1,8 +0,0 @@
#!/bin/bash -u
# This script generates file lists from Bazel for CMake.
set -e
bazel build //pkg:gen_src_file_lists
cp -v bazel-bin/pkg/src_file_lists.cmake src/file_lists.cmake

@ -0,0 +1,46 @@
#!/bin/bash
# This script updates src/file_lists.cmake and the checked-in generated code
# for the well-known types, commits the resulting changes, and pushes them.
# This does not do anything useful when run manually, but should be run by our
# GitHub action instead.
set -ex
# Cd to the repo root.
cd $(dirname -- "$0")
previous_commit_title=$(git log -1 --pretty='%s')
# Exit early if the previous commit was auto-generated. This reduces the risk
# of a bug causing an infinite loop of auto-generated commits.
if (echo "$previous_commit_title" | grep -q "^Auto-generate files"); then
echo "Previous commit was auto-generated"
exit 0
fi
# Run the staleness tests and use them to update any stale files.
bazel test //src:cmake_lists_staleness_test || ./bazel-bin/src/cmake_lists_staleness_test --fix
bazel test //src/google/protobuf:well_known_types_staleness_test || ./bazel-bin/src/google/protobuf/well_known_types_staleness_test --fix
# Try to determine the most recent CL or pull request.
pr_from_merge=$(echo "$previous_commit_title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p')
pr_from_squash=$(echo "$previous_commit_title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p')
cl=$(git log -1 --pretty='%b' | sed -n 's/^PiperOrigin-RevId: \([0-9]*\)$/\1/p')
if [ ! -z "$pr_from_merge" ]; then
commit_message="Auto-generate files after PR #$pr_from_merge"
elif [ ! -z "$pr_from_squash" ]; then
commit_message="Auto-generate files after PR #$pr_from_squash"
elif [ ! -z "$cl" ]; then
commit_message="Auto-generate files after cl/$cl"
else
# If we are unable to determine the CL or pull request number, we fall back
# on this default commit message. Typically this should not occur, but could
# happen if a pull request was merged via a rebase.
commit_message="Auto-generate files"
fi
git add -A
git diff --staged --quiet || git commit -am "$commit_message"
git push
Loading…
Cancel
Save