Skip to content

Commit

Permalink
Merge pull request #589 from okp4/ci/fix-release
Browse files Browse the repository at this point in the history
ci(release): move bump-module script into a separate file
  • Loading branch information
ccamel authored Mar 5, 2024
2 parents 5936cf2 + 0c77f7f commit 37c8459
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
25 changes: 1 addition & 24 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,7 @@ plugins:
numReplacements: 1
- - "@semantic-release/exec"
- prepareCmd: |
major_version=$(cat version | cut -d. -f1)
if [ $major_version -gt 1 ]; then
module_name=$(go mod edit -json | jq -r '.Module.Path')
module_name_unversioned=$(echo ${module_name} | sed -E 's|/v[0-9]+$||')
module_name_versioned="${module_name_unversioned}/v${major_version}"
echo "🔬 major version detected, updating module path to ${module_name_versioned}"
go mod edit -module "${module_name_versioned}"
echo "✅ module name updated to ${module_name_versioned} in go.mod"
if [ "$(uname)" = "Darwin" ]; then
find . -type f -name "*.go" -exec \
sed -i '' "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
else
find . -type f -name "*.go" -exec \
sed -i "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
fi
echo "✅ packages updated to ${module_name_versioned} in source files"
echo "🧹 cleaning up go.sum"
go mod tidy
else
echo "🙅version is not greater than 1, no need to update module path"
fi
./scripts/bump-module.sh
- - "@semantic-release/exec"
- prepareCmd: |
make release-assets
Expand Down
29 changes: 29 additions & 0 deletions scripts/bump-module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -eo pipefail

major_version=$(cut -d. -f1 < version)

if [ "${major_version}" -gt 1 ]; then
module_name=$(go mod edit -json | jq -r '.Module.Path')
module_name_unversioned=$(echo "${module_name}" | sed -E 's|/v[0-9]+$||')
module_name_versioned="${module_name_unversioned}/v${major_version}"
echo "🔬 major version detected, updating module path to ${module_name_versioned}"

go mod edit -module "${module_name_versioned}"
echo "✅ module name updated to ${module_name_versioned} in go.mod"

if [ "$(uname)" = "Darwin" ]; then
find . -type f -name "*.go" -exec \
sed -i '' "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
else
find . -type f -name "*.go" -exec \
sed -i "s|\"${module_name}|\"${module_name_versioned}|g" {} \;
fi
echo "✅ packages updated to ${module_name_versioned} in source files"

echo "🧹 cleaning up go.sum"
go mod tidy
else
echo "🙅version is not greater than 1, no need to update module path"
fi

0 comments on commit 37c8459

Please sign in to comment.