Last active
April 15, 2020 20:43
-
-
Save clcollins/c8087bf3d1e637e5e85ccd72043be959 to your computer and use it in GitHub Desktop.
GVM Project Config
This file contains hidden or 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
#!/usr/bin/env bash | |
# The name of the project | |
name='aws-account-operator' | |
# The path to be used in the Go /src/ dir | |
project_source_path="github.com/openshift/${name}" | |
# Set Go version you want to use | |
go_version='1.13.1' | |
# Set (or not) GO111MODULE on | |
GO111MODULE="off" | |
# Set (or not) FORCE_DEV_MODE local | |
FORCE_DEV_MODE="local" | |
# Don't need to change these | |
gvm_base="${HOME}/.gvm" | |
gvm_pkgset="${name}" | |
go_root="${gvm_base}/gos/go${go_version}" | |
go_path_base="${gvm_base}/pkgsets/go${go_version}" | |
gvm_global_path="${go_path_base}/global" | |
source_dir="${go_path_base}/${gvm_pkgset}/src/${project_source_path}" | |
# Install the Go version if it's not already; | |
# and either way, switch to it | |
use_or_install_go_ver() { | |
if ! gvm list | grep ${go_version} | |
then | |
gvm install ${go_version} | |
fi | |
gvm use go${go_version} | |
} | |
# Create the gvm packageset if it's not already; | |
# and switch to it | |
use_or_create_gvm_pkgset() { | |
if ! gvm pkgset list | grep ${gvm_pkgset} | |
then | |
gvm pkgset create ${gvm_pkgset} | |
fi | |
gvm pkgset use ${gvm_pkgset} | |
} | |
# Write out the settings.json file necessary for | |
# vscode to parse GVM Go stuff correctly | |
write_vscode_settings_json() { | |
if [[ ! -f ${source_dir}/.vscode/settings.json ]] | |
then | |
mkdir -p ${source_dir}/.vscode | |
cat << EOF > ${source_dir}/.vscode/settings.json | |
{ | |
"go.goroot": "${go_root}", | |
"go.gopath": "${go_path_base}/${gvm_pkgset}:${gvm_global_path}", | |
} | |
EOF | |
fi | |
} | |
# Creates the path where the project will be | |
use_or_create_source_dir(){ | |
if [[ ! -d $source_dir ]] | |
then | |
mkdir -p $source_dir | |
echo "${source_dir} does not exist; creating" | |
echo "" | |
echo "Hint: git clone https://${project_source_path}.git ${source_dir}" | |
return 1 | |
fi | |
cd $source_dir | |
} | |
# Do the things | |
use_or_install_go_ver | |
use_or_create_gvm_pkgset | |
use_or_create_source_dir || return 0 | |
write_vscode_settings_json | |
export GO111MODULE=$GO111MODULE | |
export FORCE_DEV_MODE=$FORCE_DEV_MODE | |
# Show if GO111MODULE is enabled | |
env |grep --color=never GO111MODULE | |
env |grep --color=never FORCE_DEV_MODE | |
# Start vscode (if you want) | |
code . | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment