Skip to content

Commit

Permalink
use go mod edit for ensuring settings (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSonOfLars committed Jan 14, 2023
1 parent 838aa12 commit cef226c
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions scripts/ci/ensure-consistent-sample-mod-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ SAMPLES_DIR="samples"
REPO="github.com/PaulSonOfLars/gotgbot" # Current library import path
GO_VERSION="1.15" # Go version we expect our samples to be using
V_MAJOR="v2" # Current major version for the library

# We need to do some bash magic for systems that aren't using gnused
sedCmd="sed"
if [[ "$(uname)" == "Darwin" ]]; then
command -v gsed || (echo "gnu-sed not installed. Please install with 'brew install gnu-sed'" && return 1)
sedCmd="gsed"
fi
V_DUMMY="v2.99.99" # dummy version for the library

for d in "${SAMPLES_DIR}"/*; do
if [ ! -d "${d}" ]; then
# Only check directories.
continue
fi

echo "Checking ${d}"
# Ensure the module has the right name
"${sedCmd}" -i "s:^module .*:module ${REPO}/${d}:g" "${d}/go.mod"
goModFile="${d}/go.mod"
echo "Checking ${goModFile}"

pushd "${d}" >/dev/null

# Ensure the following are correct:
# - module name
# - go version
# - library version (set to a dummy version to avoid needing constant updates)
# - library replace to use the lib in the repo
go mod edit \
-module "${REPO}/${d}" \
-go="${GO_VERSION}" \
-require="${REPO}/${V_MAJOR}@${V_DUMMY}" \
-replace="${REPO}/${V_MAJOR}=../../"

# Ensure the current library version is a dummy version to avoid confusion
"${sedCmd}" -i "s:${REPO}/${V_MAJOR} ${V_MAJOR}.*$:${REPO}/${V_MAJOR} ${V_MAJOR}.99.99:g" "${d}/go.mod"
go mod tidy

# Ensure go version is consistent
"${sedCmd}" -i "s:^go .*:go ${GO_VERSION}:g" "${d}/go.mod"
popd >/dev/null
done

0 comments on commit cef226c

Please sign in to comment.