6 Commits

5 changed files with 66 additions and 50 deletions

View File

@@ -21,7 +21,8 @@ If you want, add yourself to the `CONTRIBUTORS` file in your pull request.
For Rust, just use `cargo fmt`. For Python, use For Rust, just use `cargo fmt`. For Python, use
[black](https://github.com/psf/black). I'd rather not spend any effort in [black](https://github.com/psf/black). I'd rather not spend any effort in
configuring the formatters (not possible for black anyway). configuring the formatters (not possible for black anyway). For shell scripts,
use [`shfmt`](https://github.com/mvdan/sh).
## Tooling ## Tooling
@@ -41,6 +42,9 @@ When contributing, consider whether it makes sense to add tests which could
prevent regressions in the future. When fixing bugs, it makes sense to add prevent regressions in the future. When fixing bugs, it makes sense to add
tests that expose the wrong behaviour beforehand. tests that expose the wrong behaviour beforehand.
To also ensure proper formatting and that the linter is happy, use `just check`.
If that succeeds, your code is most likely fine to push!
## Documentation ## Documentation
The documentation lives in `docs` and uses The documentation lives in `docs` and uses

2
Cargo.lock generated
View File

@@ -332,7 +332,7 @@ dependencies = [
[[package]] [[package]]
name = "git-repo-manager" name = "git-repo-manager"
version = "0.7.2" version = "0.7.3"
dependencies = [ dependencies = [
"clap", "clap",
"comfy-table", "comfy-table",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "git-repo-manager" name = "git-repo-manager"
version = "0.7.2" version = "0.7.3"
edition = "2021" edition = "2021"
authors = [ authors = [

View File

@@ -4,8 +4,6 @@ static_target := "x86_64-unknown-linux-musl"
check: fmt-check lint test check: fmt-check lint test
cargo check cargo check
cargo fmt --check
cargo clippy --no-deps -- -Dwarnings
clean: clean:
cargo clean cargo clean
@@ -14,13 +12,16 @@ clean:
fmt: fmt:
cargo fmt cargo fmt
git ls-files | grep '\.py$' | xargs black git ls-files | grep '\.py$' | xargs black
git ls-files | grep '\.sh$' | xargs -L 1 shfmt --indent 4 --write
fmt-check: fmt-check:
cargo fmt --check cargo fmt --check
git ls-files | grep '\.py$' | xargs black --check git ls-files | grep '\.py$' | xargs black --check
git ls-files | grep '\.sh$' | xargs -L 1 shfmt --indent 4 --diff
lint: lint:
cargo clippy --no-deps -- -Dwarnings cargo clippy --no-deps -- -Dwarnings
git ls-files | grep '\.sh$' | xargs -L 1 shellcheck --norc
lint-fix: lint-fix:
cargo clippy --no-deps --fix cargo clippy --no-deps --fix

View File

@@ -8,7 +8,7 @@ usage() {
printf '%s\n' "usage: $0 (master|minor|patch)" >&2 printf '%s\n' "usage: $0 (master|minor|patch)" >&2
} }
if (( $# != 1 )) ; then if (($# != 1)); then
usage usage
exit 1 exit 1
fi fi
@@ -20,48 +20,50 @@ minor="$(printf '%s' "${current_version}" | grep -oP '\.\d+\.' | tr -d '.')"
patch="$(printf '%s' "${current_version}" | grep -oP '\d+$' | tr -d '.')" patch="$(printf '%s' "${current_version}" | grep -oP '\d+$' | tr -d '.')"
case "$1" in case "$1" in
major) major)
(( major++ )) || true ((major++)) || true
minor=0 minor=0
patch=0 patch=0
;; ;;
minor) minor)
(( minor++ )) || true ((minor++)) || true
patch=0 patch=0
;; ;;
patch) patch)
(( patch++ )) || true ((patch++)) || true
;; ;;
*) *)
usage usage
exit 1 exit 1
;; ;;
esac esac
new_version="${major}.${minor}.${patch}" new_version="${major}.${minor}.${patch}"
if ! [[ "${new_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then if ! [[ "${new_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
printf '%s\n' 'Version has to a complete semver' >&2 printf '%s\n' 'Version has to a complete semver' >&2
exit 1 exit 1
fi fi
if [[ $(git rev-parse --abbrev-ref HEAD) != "develop" ]] ; then current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${current_branch}" != "develop" ]]; then
printf '%s\n' 'You need to be on develop' >&2 printf '%s\n' 'You need to be on develop' >&2
exit 1 exit 1
fi fi
if [[ -n "$(git status --porcelain)" ]] ; then gitstatus="$(git status --porcelain)"
if [[ -n "${gitstatus}" ]]; then
printf '%s\n' 'There are uncommitted changes' >&2 printf '%s\n' 'There are uncommitted changes' >&2
exit 1 exit 1
fi fi
if git tag --list "v${new_version}" | grep -q . ; then if git tag --list "v${new_version}" | grep -q .; then
printf 'Tag %s already exists\n' "v${new_version}" >&2 printf 'Tag %s already exists\n' "v${new_version}" >&2
exit 1 exit 1
fi fi
for remote in $(git remote) ; do for remote in $(git remote); do
if git ls-remote --tags "${remote}" | grep -q "refs/tags/v${new_version}$" ; then if git ls-remote --tags "${remote}" | grep -q "refs/tags/v${new_version}$"; then
printf 'Tag %s already exists on %s' "v${new_version}" "${remote}" >&2 printf 'Tag %s already exists on %s' "v${new_version}" "${remote}" >&2
exit 1 exit 1
fi fi
@@ -69,21 +71,22 @@ done
git fetch --all git fetch --all
for remote in $(git remote) ; do for remote in $(git remote); do
for branch in master develop ; do for branch in master develop; do
if ! git diff --quiet "${remote}/${branch}..${branch}" ; then if ! git diff --quiet "${remote}/${branch}..${branch}"; then
printf 'Remote branch %s/%s not up to date, synchronize first!\n' "${remote}" "${branch}" >&2 printf 'Remote branch %s/%s not up to date, synchronize first!\n' "${remote}" "${branch}" >&2
exit 1 exit 1
fi fi
done done
done done
if ! git merge-base --is-ancestor master develop ; then if ! git merge-base --is-ancestor master develop; then
printf '%s\n' 'Develop is not a straight descendant of master, rebase!' >&2 printf '%s\n' 'Develop is not a straight descendant of master, rebase!' >&2
exit 1 exit 1
fi fi
if (( $(git log --oneline master..develop | wc -l) == 0 )) ; then changes="$(git log --oneline master..develop | wc -l)"
if ((changes == 0)); then
printf '%s\n' 'No changes between master and develop?' >&2 printf '%s\n' 'No changes between master and develop?' >&2
exit 1 exit 1
fi fi
@@ -97,28 +100,32 @@ sed -i "0,/^version/{s/^version.*$/version = \"${new_version}\"/}" Cargo.toml
cargo update --package git-repo-manager --precise "${new_version}" cargo update --package git-repo-manager --precise "${new_version}"
diff="$(git diff --numstat)" diff="$(git diff --numstat)"
if (( $(printf '%s\n' "${diff}" | wc -l) != 2 )) ; then if (($(printf '%s\n' "${diff}" | wc -l || true) != 2)); then
printf '%s\n' 'Weird changes detected, bailing' >&2 printf '%s\n' 'Weird changes detected, bailing' >&2
exit 1 exit 1
fi fi
if ! printf '%s\n' "${diff}" | grep -Pq '^1\s+1\s+Cargo.lock$' ; then if ! printf '%s\n' "${diff}" | grep -Pq '^1\s+1\s+Cargo.lock$'; then
printf '%s\n' 'Weird changes detected, bailing' >&2 printf '%s\n' 'Weird changes detected, bailing' >&2
exit 1 exit 1
fi fi
if ! printf '%s\n' "${diff}" | grep -Pq '^1\s+1\s+Cargo.toml$' ; then if ! printf '%s\n' "${diff}" | grep -Pq '^1\s+1\s+Cargo.toml$'; then
printf '%s\n' 'Weird changes detected, bailing' >&2 printf '%s\n' 'Weird changes detected, bailing' >&2
exit 1 exit 1
fi fi
git add Cargo.lock Cargo.toml git add Cargo.lock Cargo.toml
git commit -m "Release v${new_version}" git commit -m "Release v${new_version}"
git switch master 2>/dev/null || { [[ -d "../master" ]] && cd "../master" ; } || { printf '%s\n' 'Could not change to master' >&2 ; exit 1 ; } git switch master 2>/dev/null || { [[ -d "../master" ]] && cd "../master"; } || {
printf '%s\n' 'Could not change to master' >&2
exit 1
}
if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]] ; then current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${current_branch}" != "master" ]]; then
printf '%s\n' 'Looks like branch switching to master did not work' >&2 printf '%s\n' 'Looks like branch switching to master did not work' >&2
exit 1 exit 1
fi fi
@@ -126,23 +133,27 @@ fi
git merge --no-ff --no-edit develop git merge --no-ff --no-edit develop
git tag "v${new_version}" git tag "v${new_version}"
for remote in $(git remote) ; do for remote in $(git remote); do
while ! git push "${remote}" "v${new_version}" master ; do while ! git push "${remote}" "v${new_version}" master; do
: :
done done
done done
git switch develop 2>/dev/null || { [[ -d "../develop" ]] && cd "../develop" ; } || { printf '%s\n' 'Could not change to develop' >&2 ; exit 1 ; } git switch develop 2>/dev/null || { [[ -d "../develop" ]] && cd "../develop"; } || {
printf '%s\n' 'Could not change to develop' >&2
exit 1
}
if [[ $(git rev-parse --abbrev-ref HEAD) != "develop" ]] ; then current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${current_branch}" != "develop" ]]; then
printf '%s\n' 'Looks like branch switching to develop did not work' >&2 printf '%s\n' 'Looks like branch switching to develop did not work' >&2
exit 1 exit 1
fi fi
git merge --ff-only master git merge --ff-only master
for remote in $(git remote) ; do for remote in $(git remote); do
while ! git push "${remote}" develop ; do while ! git push "${remote}" develop; do
: :
done done
done done