[new] Code migration
This commit is contained in:
commit
39ad0a3825
34
.gitea/workflows/test.yaml
Normal file
34
.gitea/workflows/test.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
name: "test"
|
||||
run-name: "test"
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
- "!v*-beta*"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: [smoketest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "setup mock go.mod file"
|
||||
shell: bash
|
||||
run: |
|
||||
echo -e "module code.jakeyoungdev.com/actions/install-go\n\ngo 1.24" > go.mod
|
||||
|
||||
- name: "run go install script"
|
||||
shell: bash
|
||||
env:
|
||||
GO_INSTALL_COMMANDS: github.com/jake-young-dev/kelp@v0.0.9
|
||||
run: |
|
||||
chmod +x install.sh
|
||||
./install.sh amd64 no
|
||||
|
||||
- name: "check go version"
|
||||
shell: bash
|
||||
run: go version | grep "go version go1.24.0 linux/amd64"
|
||||
|
||||
- name: "check go installed command"
|
||||
shell: bash
|
||||
run: kelp -v | grep "kelp version v0.0.9"
|
27
README.md
Normal file
27
README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# install-go
|
||||
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).
|
||||
|
||||
|
||||
## Usage
|
||||
I recommend using a tagged release to avoid unexpected changes that may come to the master branch
|
||||
```yaml
|
||||
name: "install go"
|
||||
uses: https://code.jakeyoungdev.com/actions/install-go@master
|
||||
with:
|
||||
commands: |
|
||||
github.com/jake-young-dev/kelp@v0.0.9
|
||||
```
|
||||
|
||||
#### 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.
|
||||
#### 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
|
||||
|commands|no|any public go repositories|no default|links to any commands to be installed using 'go 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.
|
3
TODO.txt
Normal file
3
TODO.txt
Normal file
@ -0,0 +1,3 @@
|
||||
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
|
25
action.yaml
Normal file
25
action.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
name: "install-go"
|
||||
description: "simple and fast install for golang and golang commands on linux workflows"
|
||||
inputs:
|
||||
arch:
|
||||
description: "Optional, the linux architecture to use when downloading Go files (default: amd64)"
|
||||
required: false
|
||||
default: "amd64"
|
||||
purge:
|
||||
description: "Optional, deletes any previously installed go versions (yes|no)"
|
||||
required: false
|
||||
default: "no"
|
||||
commands:
|
||||
description: "Optional, any commands to be installed with 'go install', must include version"
|
||||
required: false
|
||||
default: "."
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: "run script"
|
||||
run: ${{ github.action_path }}/install.sh
|
||||
shell: bash
|
||||
env:
|
||||
GO_INSTALL_COMMANDS: ${{ inputs.commands }}
|
||||
GO_INSTALL_ARCH: ${{ inputs.arch }}
|
||||
GO_INSTALL_PURGE: ${{ inputs.purge }}
|
98
install.sh
Normal file
98
install.sh
Normal file
@ -0,0 +1,98 @@
|
||||
#!/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"
|
||||
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"
|
||||
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
|
||||
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}"
|
||||
PATH_FOR_FILES=/usr/local/go
|
||||
PATH_FOR_TAR=/usr/local
|
||||
sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES"
|
||||
|
||||
#wget
|
||||
# -q quiets output
|
||||
# O- outputs file data to pipe instead of file
|
||||
#tar
|
||||
# -z use gzip
|
||||
# -x extract files
|
||||
# -f extract from "file"
|
||||
# - 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"
|
||||
else
|
||||
echo "FATAL: Unable to download and extract files"
|
||||
fi
|
||||
|
||||
echo "Setting path for go command"
|
||||
export PATH=$PATH:$PATH_FOR_FILES/bin
|
||||
echo "$PATH_FOR_FILES/bin" >> "$GITHUB_PATH" #set action path too
|
||||
|
||||
#grab go version to test the go command
|
||||
GLOBAL_GO_CMD_VERSION=$(go version)
|
||||
if [[ -z "$GLOBAL_GO_CMD_VERSION" ]]; then
|
||||
echo "FATAL: Failed to register go command"
|
||||
exit 1
|
||||
else
|
||||
echo "Go command setup for ${GLOBAL_GO_CMD_VERSION}"
|
||||
fi
|
||||
|
||||
#adding GOPATH to path to support go commands
|
||||
echo "Setting path to allow for commands installed by go"
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user