Created
March 2, 2019 17:32
-
-
Save Kubuxu/875652a03944d5db1cd13a57fb48fe69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
travis_file=$(cat travis.example.yml) | |
## do_convert() performs the conversion. It can be called with an optional argument: the module to start with. | |
do_convert() { | |
modules=() | |
for d in $(find . -maxdepth 1 -mindepth 1 -type d | sort) | |
do | |
if [[ "$d" < ${1:-} ]]; then | |
echo "skipping $d" | |
continue | |
fi | |
pushd "$d" > /dev/null | |
if ! git tag -l | grep -q -E "^v0.0.1"; then | |
## only convert this module if it hasn't been converted yet. | |
modules+=("$(basename "./$d")") | |
fi | |
popd > /dev/null | |
done | |
for mod in "${modules[@]}" | |
do | |
echo "" | |
echo "**********************************************" | |
echo " Processing: $mod" | |
echo "**********************************************" | |
echo "" | |
pushd "$mod" > /dev/null | |
git checkout master | |
git reset --hard | |
git pull --rebase origin master | |
git branch -D gomod || true | |
git checkout -b gomod | |
rm -rf go.mod go.sum | |
GO111MODULE=on go mod init "github.com/ipfs/$mod" | |
go build ./... | |
go mod tidy | |
go mod verify | |
echo "$travis_file" > .travis.yml | |
if ! grep -q -E '\sgithub.com/(ipfs|libp2p).* v0.0.0' go.mod; then | |
echo "" | |
echo "------------------------------------------------------------" | |
echo " module $mod looks ready; branching, committing and tagging." | |
echo "------------------------------------------------------------" | |
echo "" | |
git add go.mod .travis.yml || true # go.sum might not exist if the module imports nothing | |
if [[ -f go.sum ]]; then | |
git add go.sum | |
fi | |
git commit -m "add gomod support // tag v0.0.1." | |
git --no-pager log --oneline -n 10 | |
push="" | |
read -r -n1 -p "push and tag? [y/n] " push | |
if [[ "$push" != "y" ]]; then | |
popd > /dev/null | |
continue | |
fi | |
git push origin gomod | |
hub pull-request --no-edit | |
git tag "v0.0.1" || true | |
git push origin "refs/tags/v0.0.1" | |
fi | |
popd > /dev/null | |
done | |
} | |
do_convert "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment