Compare commits
12 Commits
d45fdbf3ca
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ddfd41587 | |||
| c1d74565a3 | |||
| d0bce850e0 | |||
| f452a8f09b | |||
| 32294399f7 | |||
| b4cb46f3a6 | |||
| b25fd78dd5 | |||
| 229b3116e4 | |||
| 632f667417 | |||
| 73b20fd5e1 | |||
| 24b6739aa5 | |||
| 55cb2b2be5 |
@@ -1,10 +1,10 @@
|
|||||||
name: "test"
|
name: "tests"
|
||||||
run-name: "test"
|
run-name: "tests"
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-gomod:
|
||||||
runs-on: action
|
runs-on: wind
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -29,3 +29,25 @@ jobs:
|
|||||||
- name: "check go installed command"
|
- name: "check go installed command"
|
||||||
shell: bash
|
shell: bash
|
||||||
run: mctl -v | grep "mctl version v0.3.4"
|
run: mctl -v | grep "mctl version v0.3.4"
|
||||||
|
|
||||||
|
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_VERSION: 1.23.2
|
||||||
|
GO_INSTALL_ARCH: amd64
|
||||||
|
run: |
|
||||||
|
chmod +x install.sh
|
||||||
|
./install.sh
|
||||||
|
|
||||||
|
- name: "check go version"
|
||||||
|
shell: bash
|
||||||
|
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"
|
||||||
13
README.md
13
README.md
@@ -4,25 +4,26 @@ An extremely simple github action to install golang and golang commands (using "
|
|||||||
|
|
||||||
|
|
||||||
## Usage
|
## 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
|
```yaml
|
||||||
name: "install go"
|
name: "install go"
|
||||||
uses: https://code.jakeyoungdev.com/actions/install-go@master
|
uses: https://code.jakeyoungdev.com/actions/install-go@main
|
||||||
with:
|
with:
|
||||||
commands: |
|
commands: |
|
||||||
code.jakeyoungdev.com/jake/mctl@v0.3.3
|
code.jakeyoungdev.com/jake/mctl@v0.3.3
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Go verions
|
#### 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 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
|
#### Inputs
|
||||||
Some inputs are available to customize the installation
|
Some inputs are available to customize the installation
|
||||||
|Input|Required|Values|Default|Description|
|
|Input|Required|Values|Default|Description|
|
||||||
|---|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
|arch|no|any arch for Go|amd64|system architecture for golang
|
|arch|no|any arch for Go|amd64|system architecture for go
|
||||||
|purge|no|yes/no|no|remove any golang files found on system before install
|
|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'
|
|commands|no|any public go repositories|.|links to any commands to be installed using 'go install'
|
||||||
|
|version|no|any go version|version in go.mod file|the go version to install
|
||||||
|
|
||||||
## Issues
|
## 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.
|
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.
|
||||||
@@ -13,6 +13,9 @@ inputs:
|
|||||||
description: "Optional, any commands to be installed with 'go install', must include version"
|
description: "Optional, any commands to be installed with 'go install', must include version"
|
||||||
required: false
|
required: false
|
||||||
default: "."
|
default: "."
|
||||||
|
version:
|
||||||
|
description: "Optional, the Go version to install if no go.mod file is present"
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
@@ -23,3 +26,4 @@ runs:
|
|||||||
GO_INSTALL_COMMANDS: ${{ inputs.commands }}
|
GO_INSTALL_COMMANDS: ${{ inputs.commands }}
|
||||||
GO_INSTALL_ARCH: ${{ inputs.arch }}
|
GO_INSTALL_ARCH: ${{ inputs.arch }}
|
||||||
GO_INSTALL_PURGE: ${{ inputs.purge }}
|
GO_INSTALL_PURGE: ${{ inputs.purge }}
|
||||||
|
GO_INSTALL_VERSION: ${{ inputs.version }}
|
||||||
78
install.sh
78
install.sh
@@ -1,15 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/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 {
|
function installCommands {
|
||||||
#if commands input is set pull the input and install them all using 'go install'
|
# "." is used as a default, meaning no commands were added
|
||||||
if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then # "." is used as a default
|
if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then
|
||||||
#allows for multiple cmds using |
|
#splitting into an array allows for multiple cmds using |
|
||||||
INPUT_ARR=( $GO_INSTALL_COMMANDS )
|
INPUT_ARR=( $GO_INSTALL_COMMANDS )
|
||||||
for i in "${INPUT_ARR[@]}"; do
|
for i in "${INPUT_ARR[@]}"; do
|
||||||
echo "Installing go command from ${i}"
|
echo "Installing go command from ${i}"
|
||||||
if go install ${i}; then
|
if go install ${i}; then
|
||||||
echo "Command setup for ${i}"
|
echo "Installed ${i}"
|
||||||
else
|
else
|
||||||
echo "FATAL: Unable to install ${i} with go"
|
echo "FATAL: Unable to install ${i} with go"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -18,41 +20,52 @@ function installCommands {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#start script
|
##
|
||||||
echo "Starting Golang install"
|
# 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]}"
|
||||||
|
|
||||||
#validate version and architecture
|
# -P uses perl syntax
|
||||||
echo "Parsing go version"
|
DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)"
|
||||||
#looking for go version in go.mod file, only checking up to minor version ignoring patch value to allow for stable versions
|
if [[ -z "$DL_VERSION_PAD_CHECK" ]]; 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: Unable to pull version from go.mod"
|
|
||||||
exit 1
|
|
||||||
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"
|
DL_VERSION="$DL_VERSION"".0"
|
||||||
echo "Fixing version number to ${DL_VERSION}"
|
echo "Fixing version number to ${DL_VERSION}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#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
|
||||||
|
echo "FATAL: No Go version found, set version input if no go.mod file is present"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
fixVersion
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Version input found"
|
||||||
|
DL_VERSION=$GO_INSTALL_VERSION
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Found go version: ${DL_VERSION}"
|
||||||
|
|
||||||
|
DL_ARCH=$GO_INSTALL_ARCH
|
||||||
echo "Checking if go is already installed"
|
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
|
#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)
|
GO_CHECK=$(command -v go)
|
||||||
if [[ "$GO_CHECK" ]]; then
|
if [[ "$GO_CHECK" ]]; then
|
||||||
#if the version of go matches the requested version, skip
|
#if the version of go matches the requested version, skip
|
||||||
GVC=$(go version)
|
GVC=$(go version)
|
||||||
if [[ "$GVC" == "go version go${DL_VERSION} linux/${DL_ARCH}" ]]; then
|
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
|
installCommands
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -67,11 +80,11 @@ if [[ "$GO_CHECK" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Ready for install"
|
echo "Ready to install"
|
||||||
|
|
||||||
echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}"
|
echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}"
|
||||||
PATH_FOR_FILES=/usr/local/go
|
PATH_FOR_FILES=/usr/local/go
|
||||||
PATH_FOR_TAR=/usr/local
|
PATH_FOR_TAR=/usr/local
|
||||||
|
#creating our files with proper file perms
|
||||||
sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES"
|
sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES"
|
||||||
|
|
||||||
#wget
|
#wget
|
||||||
@@ -84,12 +97,13 @@ sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES"
|
|||||||
# - extract from pipe as a file
|
# - extract from pipe as a file
|
||||||
# -C change to GOPATH directory
|
# -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
|
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
|
else
|
||||||
echo "FATAL: Unable to download and extract files"
|
echo "FATAL: Unable to download and extract files"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Setting path for go command"
|
echo "Adding go to path"
|
||||||
export PATH=$PATH:$PATH_FOR_FILES/bin
|
export PATH=$PATH:$PATH_FOR_FILES/bin
|
||||||
echo "$PATH_FOR_FILES/bin" >> "$GITHUB_PATH" #set action path too
|
echo "$PATH_FOR_FILES/bin" >> "$GITHUB_PATH" #set action path too
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user