Skip to content

Commit eefb842

Browse files
authored
Properly detect when already using the current protobuf tag. (#1986)
There were two problems to address - - The shallow checkout github actions do by default didn't have any tags in the submodule, and we weren't fetching them until doing the update. So fetch the tags for the protobuf module upfront so the steps can properly inspect them. - Since protobuf does language specific tags, most of the time a language specific tag will be what was collected for the current checkout, which would still result in all the work being done to then decide nothing was needed. So change things to collect _all_ tags for the current comment, and filter them down to the general protobuf tag instead. This also now errors if anything goes wrong instead of doing lots of work to then not make a PR. Fixes #1904
1 parent bb661fa commit eefb842

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

.github/workflows/update_protobuf.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ jobs:
2525
submodules: true
2626
token: ${{ secrets.GITHUB_TOKEN }}
2727

28+
- name: Fetch tags in protobuf submodule
29+
run: |
30+
# The checkout doesn't fetch the tags in submodules, we'll need them. so
31+
# rather then forcing a full history checkout ('fetch-depth: 0 modules: true')
32+
# of the main and all submodules, just do this one place ourselves.
33+
cd Sources/protobuf/protobuf
34+
git fetch --tags
35+
2836
- name: Update and install dependencies
2937
# This step is run before check_release because we need curl and jq
3038
run: apt-get update && apt-get install -y curl jq
@@ -36,9 +44,27 @@ jobs:
3644
LATEST_TAG=$(curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/latest | jq -r '.tag_name')
3745
echo "Latest protobuf release: $LATEST_TAG"
3846
39-
# Get current protobuf submodule commit
47+
# Get current protobuf submodule tag
48+
#
49+
# It would be nice to just use `git describe --tags --exact-match`, but
50+
# the protobuf repo also cuts langugage specific tags. So odds are one
51+
# of those is "closer" than the main protobuf tag, so look for all tags
52+
# for the current commit and then filter down to the right style.
4053
cd Sources/protobuf/protobuf
41-
CURRENT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "none")
54+
TAG_REGEX='^v[0-9]+\.[0-9]+$'
55+
TAG_MATCHES=$(git tag --points-at HEAD | grep -E "$TAG_REGEX")
56+
if [ -z "$TAG_MATCHES" ]; then
57+
echo "Error: Failed to figure out any current tag."
58+
exit 1
59+
fi
60+
NUM_TAG_MATCHES=$(echo "$TAG_MATCHES" | wc -l)
61+
if [ "$NUM_TAG_MATCHES" -gt 1 ]; then
62+
echo "Error: Found $NUM_TAG_MATCHES lines that could be the current tag:" >&2
63+
echo "$TAG_MATCHES" >&2
64+
exit 1
65+
fi
66+
# At this point, only one match, so good to use it as the current.
67+
CURRENT_TAG="$TAG_MATCHES"
4268
echo "Current protobuf version: $CURRENT_TAG"
4369
cd ../../..
4470
@@ -56,7 +82,6 @@ jobs:
5682
if: steps.check_release.outputs.needs_update == 'true'
5783
run: |
5884
cd Sources/protobuf/protobuf
59-
git fetch --tags
6085
git checkout ${{ steps.check_release.outputs.latest_tag }}
6186
cd ../../..
6287

0 commit comments

Comments
 (0)