Merge pull request #853 from acozzette:cmake

PiperOrigin-RevId: 480375167
pull/13171/head
Copybara-Service 2 years ago
commit 1f8f8abaf5
  1. 20
      .github/workflows/generate_files.yml
  2. 43
      cmake/push_auto_update.sh

@ -5,16 +5,20 @@ on:
push:
branches:
- main
- '[0-9]+.x'
jobs:
generate:
runs-on: ubuntu-20.04
if: github.repository == 'protocolbuffers/upb'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Merge generated branch with main
run: cd ${{ github.workspace }} && (git checkout generated || git checkout -b generated) && git merge --no-edit main
- name: Rebuild generated CMake files
run: cd ${{ github.workspace }} && bazel test cmake:test_generated_files || bazel-bin/cmake/test_generated_files --fix
- name: Commit and push changes to generated files
run: cd ${{ github.workspace }} && git add -A && (git diff --staged --quiet || git commit -am "Regenerated files") && git push
- uses: actions/checkout@v3
with:
# Note: this token has an expiration date, so if the workflow starts
# failing then you may need to generate a fresh token.
token: ${{ secrets.BOT_ACCESS_TOKEN }}
- 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"
- name: Commit and push update
run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh

@ -0,0 +1,43 @@
#!/bin/bash
# This script updates checked-in generated files (currently CMakeLists.txt,
# descriptor.upb.h, and descriptor.upb.c), 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
cd $(dirname -- "$0")/..
bazel test //cmake:test_generated_files || bazel-bin/cmake/test_generated_files --fix
# 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
Loading…
Cancel
Save