Skip to content

Instantly share code, notes, and snippets.

@raulk
Last active March 5, 2019 07:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulk/708debe71b9abd395fc7935ee1215ddd to your computer and use it in GitHub Desktop.
Save raulk/708debe71b9abd395fc7935ee1215ddd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
ignore="(go-libp2p-quic-transport|go-libp2p-tls)" ## regex of modules for whom to bypass automatic gomod migration.
travis_file=$(cat << EOF
os:
- linux
language: go
go:
- 1.11.x
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- \$GOPATH/src/gx
- \$GOPATH/pkg/mod
- \$HOME/.cache/go-build
notifications:
email: false
EOF
)
## do_convert() performs the conversion. It can be called with an optional argument: the module to start with.
do_convert() {
modules=()
for d in $(ls -d */)
do
if [[ "$d" < ${1:-} || $(echo $d | grep -cE $ignore) > 0 ]]; then
echo "skipping $d"
continue
fi
pushd $d > /dev/null
if [[ -z $(git tag -l | grep -E "^v0.0.1") ]]; then
## only convert this module if it hasn't been converted yet.
modules+=($(echo $d | sed 's/.$//')) ## remove trailing slash
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/libp2p/$mod"
go build ./... && go mod tidy && go mod verify
echo "$travis_file" > .travis.yml
libp2p_deps=$(grep -E '\tgithub.com/libp2p/.* v0.0.0' go.mod) || true # guard the non-zero exit value of grep from killing the shell
if [[ -z $libp2p_deps ]]; 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
push=""
read -r -n1 -p "push and tag? [y/n] " push
if [[ "$push" != "y" ]]; then
popd > /dev/null
continue
fi
git push origin
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