10 Commits

Author SHA1 Message Date
73b20fd5e1 adjusting version fix
Some checks failed
test / test (push) Failing after 18s
2025-05-22 21:55:30 -04:00
24b6739aa5 adding arch, defaults dont apply to tests
Some checks failed
test / test (push) Failing after 18s
2025-05-22 21:50:54 -04:00
55cb2b2be5 adding version input, adjusting tests
Some checks failed
test / test (push) Failing after 3s
2025-05-22 21:49:48 -04:00
d45fdbf3ca Update README.md
All checks were successful
test / test (push) Successful in 18s
2025-05-23 01:32:32 +00:00
fb7e640162 feature/version-check (#2)
Some checks failed
test / test (push) Has been cancelled
Reviewed-on: #2
2025-05-23 01:31:38 +00:00
2785d64c02 Update README.md
All checks were successful
test / test (push) Successful in 21s
2025-04-20 05:28:17 +00:00
09214e49b9 [config] revert trigger changes
All checks were successful
test / test (push) Successful in 15s
2025-04-04 14:27:53 -04:00
67be40ad0d [config] Workflow trigger updates
All checks were successful
test / test (push) Successful in 15s
2025-04-04 14:25:59 -04:00
8febe20c2a Update README.md
All checks were successful
test / test (push) Successful in 16s
2025-04-04 18:24:32 +00:00
86ce64c8d1 readme update
All checks were successful
test / test (push) Successful in 16s
2025-04-04 14:23:12 -04:00
5 changed files with 97 additions and 49 deletions

View File

@@ -1,13 +1,10 @@
name: "test"
run-name: "test"
on:
push:
branches:
- master
on: push
jobs:
test:
runs-on: [smoketest]
runs-on: action
steps:
- uses: actions/checkout@v4
@@ -19,9 +16,8 @@ jobs:
- name: "run go install script"
shell: bash
env:
GO_INSTALL_COMMANDS: github.com/jake-young-dev/kelp@v0.0.9
GO_INSTALL_COMMANDS: code.jakeyoungdev.com/jake/mctl@v0.3.4
GO_INSTALL_ARCH: amd64
GO_INSTALL_PURGE: no
run: |
chmod +x install.sh
./install.sh
@@ -32,4 +28,19 @@ jobs:
- name: "check go installed command"
shell: bash
run: kelp -v | grep "kelp version v0.0.9"
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
GO_INSTALL_ARCH: amd64
run: |
rm go.mod
./install.sh
- name: "check go version"
shell: bash
run: go version | grep "go version go1.23.2 linux/amd64"

View File

@@ -1,4 +1,5 @@
# install-go
![tests](https://code.jakeyoungdev.com/actions/install-go/actions/workflows/test.yaml/badge.svg?branch=main&event=push) <br />
An extremely simple github action to install golang and golang commands (using "go install") on linux hosts. This provides the ability to install and setup golang without node/typescript which is required when using [actions/setup-go](https://github.com/actions/setup-go).
@@ -9,19 +10,20 @@ Use a tagged release to avoid unexpected changes that may come to the master bra
uses: https://code.jakeyoungdev.com/actions/install-go@master
with:
commands: |
github.com/jake-young-dev/kelp@v0.0.9
code.jakeyoungdev.com/jake/mctl@v0.3.3
```
#### 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.

View File

@@ -1,3 +0,0 @@
Comments are left in code using TODO# to track possible implementation location.
TODO1. check current installed version to see if it matches requested install version, only error if they don't match

View File

@@ -3,7 +3,7 @@ description: "simple and fast install for golang and golang commands on linux wo
inputs:
arch:
description: "Optional, the linux architecture to use when downloading Go files (default: amd64)"
required: true
required: false
default: "amd64"
purge:
description: "Optional, deletes any previously installed go versions (yes|no)"
@@ -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:
@@ -23,3 +27,4 @@ runs:
GO_INSTALL_COMMANDS: ${{ inputs.commands }}
GO_INSTALL_ARCH: ${{ inputs.arch }}
GO_INSTALL_PURGE: ${{ inputs.purge }}
GO_INSTALL_VERSION: ${{ inputs.version }}

View File

@@ -1,19 +1,24 @@
#!/bin/bash
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
echo "FATAL: Unable to pull version from go.mod"
#installs any commands set in the command input value
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 |
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}"
else
echo "FATAL: Unable to install ${i} with go"
exit 1
fi
echo "Found go version: ${DL_VERSION_RAW}"
done
fi
}
DL_ARCH=$GO_INSTALL_ARCH
function fixVersion {
DL_VSPL=( $DL_VERSION_RAW )
DL_VERSION="${DL_VSPL[1]}"
@@ -24,23 +29,64 @@ 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"
#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
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]}"
# #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
GO_CHECK=$(command -v go)
if [[ "$GO_CHECK" ]]; then
#if purge flag is set remove old go files
if [[ "$GO_INSTALL_PURGE" == "yes" ]]; 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!"
installCommands
exit 0
fi
#if the purge flag is not set and version does not match, exit
if [[ "$GO_INSTALL_PURGE" != "yes" ]]; then
echo "FATAL: The wrong version of Go is already installed, set purge to 'yes' if you wish to update installed version"
exit 1
else
echo "Removing old go versions"
sudo rm -r /usr/bin/go
sudo rm -r /usr/bin/gofmt
else
#TODO1: if installed version matches requested version we can consider the job successful
echo "FATAL: Go is already installed, set purge to 'yes' if you wish to update installed version"
exit 1
fi
fi
echo "Ready for install"
echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}"
@@ -82,17 +128,4 @@ GP=$(go env GOPATH)/bin
export PATH=$PATH:$GP
echo "$GP" >> "$GITHUB_PATH"
#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 |
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}"
else
echo "FATAL: Unable to install ${i} with go"
exit 1
fi
done
fi
installCommands