Skip to content

Improve scripts and tool configurations #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Oct 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8c4df3c
Add pre-commit hook to run shellcheck
EliahKagan Sep 27, 2023
f3be76f
Force color when running shellcheck in pre-commit
EliahKagan Sep 27, 2023
7dd8add
Suppress SC2086 where word splitting is intended
EliahKagan Sep 27, 2023
21875b5
Don't split and glob the interpreter name
EliahKagan Sep 27, 2023
0920371
Extract suggest_venv out of the else block
EliahKagan Sep 27, 2023
e973f52
Use some handy bash-isms in version check script
EliahKagan Sep 27, 2023
be53823
Have init script treat master unambiguously as a branch
EliahKagan Sep 27, 2023
e604b46
Use 4-space indentation in all shell scripts
EliahKagan Sep 27, 2023
19dfbd8
Make the init script a portable POSIX shell script
EliahKagan Sep 27, 2023
7110bf8
Move extra tag-fetching step into init script
EliahKagan Sep 27, 2023
c7cdaf4
Reduce code duplication in version check script
EliahKagan Sep 27, 2023
f6dbba2
A couple more script tweaks for clarity
EliahKagan Sep 27, 2023
5060c9d
Explain what each step in the init script achieves
EliahKagan Sep 27, 2023
d5479b2
Use set -u in init script
EliahKagan Sep 28, 2023
52f9a68
Make the "all" Makefile target more robust
EliahKagan Sep 28, 2023
b88d07e
Use a single awk instead of two greps and a cut
EliahKagan Sep 28, 2023
d36818c
Add a black check to pre-commit
EliahKagan Sep 28, 2023
4ba5ad1
Fix typo in comment
EliahKagan Sep 28, 2023
5d8ddd9
Use two hooks for black: to check, and format
EliahKagan Sep 28, 2023
a872d9c
Pass --all-files explicitly so it is retained
EliahKagan Oct 3, 2023
9b9de11
Fix the formatting
EliahKagan Oct 3, 2023
5d15063
Add "make lint" to lint without auto-formatting
EliahKagan Sep 28, 2023
6de86a8
Update readme about most of the test/lint tools
EliahKagan Sep 28, 2023
f094909
Add BUILDDIR var to doc/Makefile; have tox use it
EliahKagan Sep 28, 2023
fc96980
Have init script check for GitHub Actions
EliahKagan Sep 28, 2023
b98f15e
Get tags for tests from original repo as fallback
EliahKagan Sep 29, 2023
7cca7d2
Don't print the exact same warning twice
EliahKagan Sep 29, 2023
e4e009d
Reword comment to fix ambiguity
EliahKagan Sep 29, 2023
e16e4c0
Format all YAML files in the same style
EliahKagan Sep 29, 2023
62c024e
Let tox run lint, mypy, and html envs without 3.9
EliahKagan Sep 29, 2023
9e245d0
Update readme: CI jobs not just for "main" branch
EliahKagan Oct 1, 2023
c2472e9
Note that the init script can be run from Git Bash
EliahKagan Oct 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
EliahKagan committed Oct 3, 2023
commit b98f15e46a7d5f343b1303b55bc4dae2d18bd621
38 changes: 34 additions & 4 deletions init-tests-after-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

set -eu

fallback_repo_for_tags='https://github.com/gitpython-developers/GitPython.git'

ci() {
# For now, check just these, as a false positive could lead to data loss.
test -n "${TRAVIS-}" || test -n "${GITHUB_ACTIONS-}"
}

no_version_tags() {
test -z "$(git tag -l '[0-9]*' 'v[0-9]*')"
}

warn() {
printf '%s\n' "$@" >&2 # Warn in step output.

if test -n "${GITHUB_ACTIONS-}"; then
printf '::warning ::%s\n' "$*" >&2 # Annotate workflow.
fi
}

if ! ci; then
printf 'This operation will destroy locally modified files. Continue ? [N/y]: ' >&2
read -r answer
Expand All @@ -33,11 +47,27 @@ git reset --hard HEAD~1
# Point the master branch where we started, so we test the correct code.
git reset --hard __testing_point__

# Do some setup that CI takes care of but that may not have been done locally.
# The tests need submodules. (On CI, they would already have been checked out.)
if ! ci; then
# The tests need some version tags. Try to get them even in forks.
git submodule update --init --recursive
fi

# The tests need some version tags. Try to get them even in forks. This fetch
# gets other objects too, so for a consistent experience, always do it locally.
if ! ci || no_version_tags; then
git fetch --all --tags
fi

# The tests need submodules, including a submodule with a submodule.
git submodule update --init --recursive
# If we still have no version tags, try to get them from the original repo.
if no_version_tags; then
warn 'No local or remote version tags found. Trying fallback remote:' \
"$fallback_repo_for_tags"

# git fetch supports * but not [], and --no-tags means no *other* tags, so...
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 |
xargs git fetch --no-tags "$fallback_repo_for_tags"

if no_version_tags; then
warn 'No version tags found anywhere. Some tests will fail.'
fi
fi