From 55cb2b2be5ccb90d527c4da6e240014551ca0d7e Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 22 May 2025 21:49:48 -0400 Subject: [PATCH 01/11] adding version input, adjusting tests --- .gitea/workflows/test.yaml | 17 +++++++++++++++-- README.md | 9 +++++---- action.yaml | 7 ++++++- install.sh | 9 +++++++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 36301a8..8b10982 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -17,7 +17,6 @@ jobs: shell: bash env: GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4 - GO_INSTALL_ARCH: amd64 run: | chmod +x install.sh ./install.sh @@ -28,4 +27,18 @@ jobs: - name: "check go installed command" shell: bash - run: mctl -v | grep "mctl version v0.3.4" \ No newline at end of file + run: mctl -v | grep "mctl version v0.3.4" + + - name: "remove go" + shell: bash + env: + GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4 + GO_INSTALL_PURGE: yes + GO_INSTALL_VERSION: 1.23.2 + run: | + rm go.mod + ./install.sh + + - name: "check go version" + shell: bash + run: go version | grep "go version go1.23.2 linux/amd64" \ No newline at end of file diff --git a/README.md b/README.md index 60f987b..6ce8a1d 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,16 @@ Use a tagged release to avoid unexpected changes that may come to the master bra ``` #### Go verions -Go version is determined using the go.mod file in the root of working directory. Go files are pulled directly from the go download [site](https://go.dev/dl/) and all go commands are installed using 'go install' after setup. If a Go version is already present the 'purge' input must be set to 'yes' to avoid errors. +The Go version installed is determined by the version specified in the go.mod file. If not mod file is present the 'version' input is used. Go files are pulled directly from the Go download [site](https://go.dev/dl/) and all go commands are installed using 'go install' after setup. If a different version of Go is already installed the 'purge' input must be set to 'yes' to remove it and avoid errors. + #### Inputs Some inputs are available to customize the installation |Input|Required|Values|Default|Description| |---|---|---|---|---| -|arch|no|any arch for Go|amd64|system architecture for golang -|purge|no|yes/no|no|remove any golang files found on system before install +|arch|no|any arch for Go|amd64|system architecture for go +|purge|no|yes/no|no|remove any go files found on system before install |commands|no|any public go repositories|.|links to any commands to be installed using 'go install' - +|version|no|any go version|.|the go version to use if no mod file is present ## Issues This repo is a as brain-dead as I could make it and is intended to be as fast and low-level as possible. Please open an issue for any problems or suggestions. \ No newline at end of file diff --git a/action.yaml b/action.yaml index dbe0be6..2e58758 100644 --- a/action.yaml +++ b/action.yaml @@ -13,6 +13,10 @@ inputs: description: "Optional, any commands to be installed with 'go install', must include version" required: false default: "." + version: + description: "Optional, the Go version to install if no go.mod file is present" + required: false + default: "." runs: using: composite steps: @@ -22,4 +26,5 @@ runs: env: GO_INSTALL_COMMANDS: ${{ inputs.commands }} GO_INSTALL_ARCH: ${{ inputs.arch }} - GO_INSTALL_PURGE: ${{ inputs.purge }} \ No newline at end of file + GO_INSTALL_PURGE: ${{ inputs.purge }} + GO_INSTALL_VERSION: ${{ inputs.version }} \ No newline at end of file diff --git a/install.sh b/install.sh index 20ab819..3895f37 100755 --- a/install.sh +++ b/install.sh @@ -27,8 +27,13 @@ echo "Parsing go version" # -P uses perl syntax DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" if [[ -z "$DL_VERSION_RAW" ]]; then - echo "FATAL: Unable to pull version from go.mod" - exit 1 + #no go.mod file found + DL_VERSION_RAW=$GO_INSTALL_VERSION + #no version input set either + if [[ "$DL_VERSION_RAW" == "." ]]; then + echo "FATAL: No Go version found, set version input if no go.mod file is present" + exit 1 + fi fi echo "Found go version: ${DL_VERSION_RAW}" -- 2.49.1 From 24b6739aa5f65292a9a5b0f12a0f4cff25513da4 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 22 May 2025 21:50:54 -0400 Subject: [PATCH 02/11] adding arch, defaults dont apply to tests --- .gitea/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 8b10982..a9cbfaa 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -17,6 +17,7 @@ jobs: shell: bash env: GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4 + GO_INSTALL_ARCH: amd64 run: | chmod +x install.sh ./install.sh @@ -35,6 +36,7 @@ jobs: GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4 GO_INSTALL_PURGE: yes GO_INSTALL_VERSION: 1.23.2 + GO_INSTALL_ARCH: amd64 run: | rm go.mod ./install.sh -- 2.49.1 From 73b20fd5e1353a07f2ecf08a28e8dd8f780ec324 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 22 May 2025 21:55:30 -0400 Subject: [PATCH 03/11] adjusting version fix --- install.sh | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index 3895f37..6414172 100755 --- a/install.sh +++ b/install.sh @@ -18,6 +18,19 @@ function installCommands { fi } +function fixVersion { + DL_VSPL=( $DL_VERSION_RAW ) + DL_VERSION="${DL_VSPL[1]}" + + #ensure we have patch-level version, if not add 0 for stable releases + # -P uses perl syntax + DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" + if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then + DL_VERSION="$DL_VERSION"".0" + echo "Fixing version number to ${DL_VERSION}" + fi +} + #start script echo "Starting Golang install" @@ -34,20 +47,22 @@ if [[ -z "$DL_VERSION_RAW" ]]; then echo "FATAL: No Go version found, set version input if no go.mod file is present" exit 1 fi +else + fixVersion fi echo "Found go version: ${DL_VERSION_RAW}" DL_ARCH=$GO_INSTALL_ARCH -DL_VSPL=( $DL_VERSION_RAW ) -DL_VERSION="${DL_VSPL[1]}" +# DL_VSPL=( $DL_VERSION_RAW ) +# DL_VERSION="${DL_VSPL[1]}" -#ensure we have patch-level version, if not add 0 for stable releases -# -P uses perl syntax -DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" -if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then - DL_VERSION="$DL_VERSION"".0" - echo "Fixing version number to ${DL_VERSION}" -fi +# #ensure we have patch-level version, if not add 0 for stable releases +# # -P uses perl syntax +# DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" +# if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then +# DL_VERSION="$DL_VERSION"".0" +# echo "Fixing version number to ${DL_VERSION}" +# fi echo "Checking if go is already installed" #check if go is already present before starting install process and delete files if purge input is set -- 2.49.1 From 632f667417da4ab8fd80e04aadece60f80cc93dd Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:24:24 -0400 Subject: [PATCH 04/11] adjusting for version input --- install.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index 6414172..d51f453 100755 --- a/install.sh +++ b/install.sh @@ -32,24 +32,22 @@ function fixVersion { } #start script -echo "Starting Golang install" - -#validate version and architecture echo "Parsing go version" -#looking for go version in go.mod file, only checking up to minor version ignoring patch value to allow for stable versions -# -P uses perl syntax -DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" -if [[ -z "$DL_VERSION_RAW" ]]; then - #no go.mod file found - DL_VERSION_RAW=$GO_INSTALL_VERSION - #no version input set either - if [[ "$DL_VERSION_RAW" == "." ]]; then - echo "FATAL: No Go version found, set version input if no go.mod file is present" - exit 1 +#check install version field first +if [[ -z $GO_INSTALL_VERSION ]]; then + # -P uses perl syntax + DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" + if [[ -z "$DL_VERSION_RAW" ]]; then + echo "FATAL: No Go version found, set version input if no go.mod file is present" + exit 1 + else + fixVersion fi else - fixVersion + DL_VERSION_RAW="$GO_INSTALL_VERSION" fi + + echo "Found go version: ${DL_VERSION_RAW}" DL_ARCH=$GO_INSTALL_ARCH -- 2.49.1 From 229b3116e43fbeadfd3fe3b1709e5fac5ec510ca Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:24:58 -0400 Subject: [PATCH 05/11] [ci] moving to newer runner --- .gitea/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index a9cbfaa..e39763e 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -4,7 +4,7 @@ on: push jobs: test: - runs-on: action + runs-on: wind steps: - uses: actions/checkout@v4 -- 2.49.1 From b25fd78dd5db0d345586f717aab5faddc4388608 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:28:28 -0400 Subject: [PATCH 06/11] breaking tests apart --- .gitea/workflows/test.yaml | 15 +++++++++------ install.sh | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index e39763e..58175aa 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,9 +1,9 @@ -name: "test" -run-name: "test" +name: "tests" +run-name: "tests" on: push jobs: - test: + test-gomod: runs-on: wind steps: - uses: actions/checkout@v4 @@ -30,15 +30,18 @@ jobs: shell: bash run: mctl -v | grep "mctl version v0.3.4" - - name: "remove go" + test-versioninput: + runs-on: wind + steps: + - uses: actions/checkout@v4 + - name: "install go with version input" shell: bash env: GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4 - GO_INSTALL_PURGE: yes GO_INSTALL_VERSION: 1.23.2 GO_INSTALL_ARCH: amd64 run: | - rm go.mod + chmod +x install.sh ./install.sh - name: "check go version" diff --git a/install.sh b/install.sh index d51f453..3a12c54 100755 --- a/install.sh +++ b/install.sh @@ -44,7 +44,7 @@ if [[ -z $GO_INSTALL_VERSION ]]; then fixVersion fi else - DL_VERSION_RAW="$GO_INSTALL_VERSION" + DL_VERSION_RAW=$GO_INSTALL_VERSION fi -- 2.49.1 From b4cb46f3a691884b67794073df6f5547accecef8 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:31:23 -0400 Subject: [PATCH 07/11] fixing improper version passed from input --- install.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 3a12c54..5059345 100755 --- a/install.sh +++ b/install.sh @@ -44,18 +44,16 @@ if [[ -z $GO_INSTALL_VERSION ]]; then fixVersion fi else - DL_VERSION_RAW=$GO_INSTALL_VERSION + DL_VERSION=$GO_INSTALL_VERSION fi -echo "Found go version: ${DL_VERSION_RAW}" +echo "Found go version: ${DL_VERSION}" DL_ARCH=$GO_INSTALL_ARCH -# DL_VSPL=( $DL_VERSION_RAW ) -# DL_VERSION="${DL_VSPL[1]}" -# #ensure we have patch-level version, if not add 0 for stable releases -# # -P uses perl syntax +#ensure we have patch-level version, if not add 0 for stable releases +# -P uses perl syntax # DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" # if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then # DL_VERSION="$DL_VERSION"".0" -- 2.49.1 From 32294399f733d821f2eef57bf68a839ce5a277bb Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:41:22 -0400 Subject: [PATCH 08/11] script update - comments - better logging - proper exiting on error - cleaning up old code --- install.sh | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/install.sh b/install.sh index 5059345..1a002c1 100755 --- a/install.sh +++ b/install.sh @@ -1,15 +1,17 @@ #!/bin/bash -#installs any commands set in the command input value +## +# installs commands using "go install" if any are set in the commands input +## function installCommands { - #if commands input is set pull the input and install them all using 'go install' - if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then # "." is used as a default - #allows for multiple cmds using | + # "." is used as a default, meaning no commands were added + if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then + #splitting into an array allows for multiple cmds using | INPUT_ARR=( $GO_INSTALL_COMMANDS ) for i in "${INPUT_ARR[@]}"; do echo "Installing go command from ${i}" if go install ${i}; then - echo "Command setup for ${i}" + echo "Installed ${i}" else echo "FATAL: Unable to install ${i} with go" exit 1 @@ -18,11 +20,13 @@ function installCommands { fi } +## +# fix version ensures we have a patch level version on our go version string from the go.mod file +## function fixVersion { DL_VSPL=( $DL_VERSION_RAW ) DL_VERSION="${DL_VSPL[1]}" - #ensure we have patch-level version, if not add 0 for stable releases # -P uses perl syntax DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then @@ -31,10 +35,12 @@ function fixVersion { fi } -#start script +#start + echo "Parsing go version" #check install version field first if [[ -z $GO_INSTALL_VERSION ]]; then + echo "No version input found, checking go.mod files" # -P uses perl syntax DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" if [[ -z "$DL_VERSION_RAW" ]]; then @@ -44,31 +50,22 @@ if [[ -z $GO_INSTALL_VERSION ]]; then fixVersion fi else + echo "Version input found" DL_VERSION=$GO_INSTALL_VERSION fi - echo "Found go version: ${DL_VERSION}" DL_ARCH=$GO_INSTALL_ARCH - -#ensure we have patch-level version, if not add 0 for stable releases -# -P uses perl syntax -# DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" -# if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then -# DL_VERSION="$DL_VERSION"".0" -# echo "Fixing version number to ${DL_VERSION}" -# fi - echo "Checking if go is already installed" #check if go is already present before starting install process and delete files if purge input is set -# -v writes string that indicates command or command path to output, prevents command not found error +# -v writes string that indicates command or command path to output, prevents command not found error if go isn't installed GO_CHECK=$(command -v go) if [[ "$GO_CHECK" ]]; then #if the version of go matches the requested version, skip GVC=$(go version) if [[ "$GVC" == "go version go${DL_VERSION} linux/${DL_ARCH}" ]]; then - echo "Go ${DL_VERSION} already installed, skipping!" + echo "Go ${DL_VERSION} already installed, skipping go setup" installCommands exit 0 fi @@ -83,11 +80,11 @@ if [[ "$GO_CHECK" ]]; then fi fi -echo "Ready for install" - +echo "Ready to install" echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}" PATH_FOR_FILES=/usr/local/go PATH_FOR_TAR=/usr/local +#creating our files with proper file perms sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES" #wget @@ -100,12 +97,13 @@ sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES" # - extract from pipe as a file # -C change to GOPATH directory if sudo wget -qO- "https://golang.org/dl/go${DL_VERSION}.linux-${DL_ARCH}.tar.gz" | sudo tar -zxf - -C "$PATH_FOR_TAR"; then - echo "Files downloaded" + echo "Files downloaded successfully" else echo "FATAL: Unable to download and extract files" + exit 1 fi -echo "Setting path for go command" +echo "Adding go to path" export PATH=$PATH:$PATH_FOR_FILES/bin echo "$PATH_FOR_FILES/bin" >> "$GITHUB_PATH" #set action path too -- 2.49.1 From f452a8f09b542e5f2d9285ef0dd6bcd86f4ec72e Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:42:51 -0400 Subject: [PATCH 09/11] [ci] finishing new test - properly checking go command version on second test --- .gitea/workflows/test.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 58175aa..4145ac4 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -46,4 +46,8 @@ jobs: - name: "check go version" shell: bash - run: go version | grep "go version go1.23.2 linux/amd64" \ No newline at end of file + run: go version | grep "go version go1.23.2 linux/amd64" + + - name: "check go installed command" + shell: bash + run: mctl -v | grep "mctl version v0.3.4" \ No newline at end of file -- 2.49.1 From d0bce850e0875f7d85fad33d91d543bc7d20d202 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:45:39 -0400 Subject: [PATCH 10/11] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ce8a1d..6ae6a55 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,17 @@ An extremely simple github action to install golang and golang commands (using " ## Usage -Use a tagged release to avoid unexpected changes that may come to the master branch +Use a tagged release to avoid unexpected changes that may come to the main branch ```yaml name: "install go" - uses: https://code.jakeyoungdev.com/actions/install-go@master + uses: https://code.jakeyoungdev.com/actions/install-go@main with: commands: | code.jakeyoungdev.com/jake/mctl@v0.3.3 ``` #### Go verions -The Go version installed is determined by the version specified in the go.mod file. If not mod file is present the 'version' input is used. Go files are pulled directly from the Go download [site](https://go.dev/dl/) and all go commands are installed using 'go install' after setup. If a different version of Go is already installed the 'purge' input must be set to 'yes' to remove it and avoid errors. +The go version installed is either determined by the version input, or the version found in a go.mod file if the input is not set. Go files are pulled directly from the Go download [site](https://go.dev/dl/) and all go commands are installed using 'go install' after setup. If a different version of Go is already installed the 'purge' input must be set to 'yes' to remove it and avoid errors. #### Inputs Some inputs are available to customize the installation @@ -23,7 +23,7 @@ Some inputs are available to customize the installation |arch|no|any arch for Go|amd64|system architecture for go |purge|no|yes/no|no|remove any go files found on system before install |commands|no|any public go repositories|.|links to any commands to be installed using 'go install' -|version|no|any go version|.|the go version to use if no mod file is present +|version|no|any go version|version in go.mod file|the go version to install ## Issues This repo is a as brain-dead as I could make it and is intended to be as fast and low-level as possible. Please open an issue for any problems or suggestions. \ No newline at end of file -- 2.49.1 From c1d74565a3c8675da6ef96b4fc031b11f7045957 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 May 2026 14:51:09 -0400 Subject: [PATCH 11/11] adjusting defaults for version input --- action.yaml | 1 - install.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 2e58758..90de116 100644 --- a/action.yaml +++ b/action.yaml @@ -16,7 +16,6 @@ inputs: version: description: "Optional, the Go version to install if no go.mod file is present" required: false - default: "." runs: using: composite steps: diff --git a/install.sh b/install.sh index 1a002c1..f6224cf 100755 --- a/install.sh +++ b/install.sh @@ -39,7 +39,7 @@ function fixVersion { echo "Parsing go version" #check install version field first -if [[ -z $GO_INSTALL_VERSION ]]; then +if [[ -z "$GO_INSTALL_VERSION" ]]; then echo "No version input found, checking go.mod files" # -P uses perl syntax DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" -- 2.49.1