diff --git a/tools/update-oss.sh b/tools/update-oss.sh index 740ea3e..d26a10e 100755 --- a/tools/update-oss.sh +++ b/tools/update-oss.sh @@ -3,14 +3,17 @@ # Usage: update-oss.sh # # Update the version of the tailscale.com module to be in sync with the version -# used by the repo checked out in the specified directory. +# used by the specified repository. # -# Requires: git, go, jq +# Requires: gh, git, go, jq # set -euo pipefail # The repository path to compare to. -repo="${1:?missing repository path}" +repo=tailscale/corp + +# The module to update. +module=tailscale.com cd "$(dirname ${BASH_SOURCE[0]})/.." if ! git diff --quiet ; then @@ -21,14 +24,11 @@ if ! git diff --quiet ; then fi git checkout --quiet main && git pull --rebase --quiet -# The module to update. -module=tailscale.com - -# The branch name to use when making an update. -branch="$USER"/update-oss-version - have="$(go list -f '{{.Version}}' -m "$module" | cut -d- -f3)" -want="$(cd "$repo"; go list -f '{{.Version}}' -m "$module" | cut -d- -f3)" +want="$( + gh api -q '.content|@base64d' repos/"${repo}"/contents/go.mod | + grep -E "\b${module}\b" | cut -d' ' -f2 | cut -d- -f3 +)" if [[ "$have" = "$want" ]] ; then echo "Module $module is up-to-date at commit $have" 1>&2 exit 0 @@ -36,8 +36,5 @@ fi go get "$module"@"$want" go mod tidy -git checkout -b "$branch" -git commit -m "go.mod: update $module to commit $want" go.mod go.sum -git push -u origin "$branch" echo "Module $module updated to commit $want" 1>&2 -echo "Branch $branch created" 1>&2 +echo "(you must commit and push this change to persist it)" 1>&2