Skip to content

Commit b98f15e

Browse files
committed
Get tags for tests from original repo as fallback
This extends the init script so it tries harder to get version tags: - As before, locally, "git fetch --all --tags" is always run. (This also fetches other objects, and the developer experience would be undesirably inconsistent if that were only sometimes done.) - On CI, run it if version tags are absent. The criterion followed here and in subsequent steps is that if any existing tag starts with a digit, or with the letter v followed by a digit, we regard version tags to be present. This is to balance the benefit of getting the tags (to make the tests work) against the risk of creating a very confusing situation in clones of forks that publish packages or otherwise use their own separate versioning scheme (especially if those tags later ended up being pushed). - Both locally and on CI, after that, if version tags are absent, try to copy them from the original gitpython-developers/GitPython repo, without copying other tags or adding that repo as a remote. Copy only tags that start with a digit, since v+digit tags aren't currently used in this project (though forks may use them). This is a fallback option and it always displays a warning. If it fails, another message is issued for that. Unexpected failure to access the repo terminates the script with a failing exit status, but the absence of version tags in the fallback remote does not, so CI jobs can continue and reveal which tests fail as a result. On GitHub Actions CI specifically, the Actions syntax for creating a warning annotation on the workflow is used, but the warning is still also written to stderr (as otherwise). GHA workflow annotations don't support multi-line warnings, so the message is adjusted into a single line where needed.
1 parent fc96980 commit b98f15e

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

Diff for: init-tests-after-clone.sh

+34-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22

33
set -eu
44

5+
fallback_repo_for_tags='https://github.com/gitpython-developers/GitPython.git'
6+
57
ci() {
68
# For now, check just these, as a false positive could lead to data loss.
79
test -n "${TRAVIS-}" || test -n "${GITHUB_ACTIONS-}"
810
}
911

12+
no_version_tags() {
13+
test -z "$(git tag -l '[0-9]*' 'v[0-9]*')"
14+
}
15+
16+
warn() {
17+
printf '%s\n' "$@" >&2 # Warn in step output.
18+
19+
if test -n "${GITHUB_ACTIONS-}"; then
20+
printf '::warning ::%s\n' "$*" >&2 # Annotate workflow.
21+
fi
22+
}
23+
1024
if ! ci; then
1125
printf 'This operation will destroy locally modified files. Continue ? [N/y]: ' >&2
1226
read -r answer
@@ -33,11 +47,27 @@ git reset --hard HEAD~1
3347
# Point the master branch where we started, so we test the correct code.
3448
git reset --hard __testing_point__
3549

36-
# Do some setup that CI takes care of but that may not have been done locally.
50+
# The tests need submodules. (On CI, they would already have been checked out.)
3751
if ! ci; then
38-
# The tests need some version tags. Try to get them even in forks.
52+
git submodule update --init --recursive
53+
fi
54+
55+
# The tests need some version tags. Try to get them even in forks. This fetch
56+
# gets other objects too, so for a consistent experience, always do it locally.
57+
if ! ci || no_version_tags; then
3958
git fetch --all --tags
59+
fi
4060

41-
# The tests need submodules, including a submodule with a submodule.
42-
git submodule update --init --recursive
61+
# If we still have no version tags, try to get them from the original repo.
62+
if no_version_tags; then
63+
warn 'No local or remote version tags found. Trying fallback remote:' \
64+
"$fallback_repo_for_tags"
65+
66+
# git fetch supports * but not [], and --no-tags means no *other* tags, so...
67+
printf 'refs/tags/%d*:refs/tags/%d*\n' 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 |
68+
xargs git fetch --no-tags "$fallback_repo_for_tags"
69+
70+
if no_version_tags; then
71+
warn 'No version tags found anywhere. Some tests will fail.'
72+
fi
4373
fi

0 commit comments

Comments
 (0)