-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to centralise golang version update
the script is taking the golang version present in the go.mod file and apply patch on the differents files that contains the golang version. for example Dockerfile and github workflow files.
- Loading branch information
1 parent
2ef6aa3
commit 83b0d6b
Showing
6 changed files
with
105 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,4 @@ tags | |
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode | ||
.idea/ | ||
/bundle/tests/ | ||
*.bak |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPTS_DIR="$(dirname "$0")" | ||
# Provides $OS,$ARCH,$PLATFORM,$ROOT variables | ||
source "$SCRIPTS_DIR/install-common.sh" | ||
|
||
cleanup() { | ||
rm -rf "$WORK_DIR" | ||
} | ||
trap "cleanup" EXIT SIGINT | ||
|
||
INSTALL_PATH=$1 | ||
VERSION=$2 | ||
|
||
BIN_ARCH=$(uname_arch) | ||
OS=$(uname| tr [:upper:] [:lower:]) | ||
if [ "$OS" == "darwin" ]; then | ||
OS="macos" | ||
fi | ||
BINARY="jq-$OS-$BIN_ARCH" | ||
|
||
if [ -z "$VERSION" ]; | ||
then | ||
echo "usage: bin/install-yq.sh <version>" | ||
exit 1 | ||
fi | ||
|
||
cd $WORK_DIR | ||
# https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-arm64 | ||
curl -Lo ${BINARY} https://github.com/jqlang/jq/releases/download/jq-$VERSION/$BINARY | ||
|
||
chmod +x $BINARY | ||
mkdir -p $ROOT/$INSTALL_PATH/ | ||
mv $BINARY $ROOT/$INSTALL_PATH/jq |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPTS_DIR="$(dirname "$0")" | ||
# Provides $OS,$ARCH,$PLAFORM,$ROOT variables | ||
source "$SCRIPTS_DIR/install-common.sh" | ||
JQ="$ROOT/bin/$PLATFORM/jq" | ||
YQ="$ROOT/bin/$PLATFORM/yq" | ||
GOVERSION=$(go mod edit --json | $JQ -r .Go) | ||
|
||
major=`echo $GOVERSION | cut -d. -f1` | ||
minor=`echo $GOVERSION | cut -d. -f2` | ||
revision=`echo $GOVERSION | cut -d. -f3` | ||
|
||
echo "----------------------------------------" | ||
echo "Golang version from go.mod: $GOVERSION" | ||
echo "- major: $major" | ||
echo "- minor: $minor" | ||
echo "- revision: $revision" | ||
echo "----------------------------------------" | ||
|
||
|
||
# update in devcontainer | ||
new_minor_version="$major.$minor" | ||
# use set to update JSON file because JQ doesnt like comments in .json file | ||
dev_container_file=$ROOT/.devcontainer/devcontainer.json | ||
echo "Processing $dev_container_file..." | ||
$SED -E "s|(\"mcr\.microsoft\.com/devcontainers/go:)[^\"]+|\11-$new_minor_version|" $dev_container_file | ||
|
||
# update in Dockerfile | ||
dockerfile_file=$ROOT/Dockerfile | ||
echo "Processing $dockerfile_file..." | ||
$SED -E "s|(FROM golang:)[^ ]+|\1$new_minor_version|" $dockerfile_file | ||
|
||
# update github actions | ||
actions_directory=$ROOT/.github/workflows | ||
for file in "$actions_directory"/*; do | ||
if [[ -f $file ]]; then | ||
if [[ $($YQ .env.GO_VERSION $file) != "null" ]]; then | ||
echo "Processing $file..." | ||
$YQ -i ".env.GO_VERSION = $new_minor_version" $file | ||
fi | ||
fi | ||
done | ||
|
||
# run go mod tidy | ||
go mod tidy |