-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
===================================================================== --- New Features ------------------------- - Github Actions integration from 3.7.0 and up! ```yaml # try it out in gh actions - uses: wrynegade/scwrypts@main with: version: v3.7.0 scwrypt: --name hello-world --group scwrypts --type py args: --message "hello from github actions ci <3" ``` --- New Scripts -------------------------- zsh/helm ) smart helm template functions (simply pass a filename) - get-template - update-dependencies --- Changes ------------------------------ - CHECK_ENVIRONMENT now uses proper argument parsing - scwrypts/plugins loaded by setting in config or environment: SCWRYPTS_PLUGIN_ENABLED__plugin=1 - SCWRYPTS__GET_PATH_TO_RELATIVE_ARGUMENT was missed in the v2->v3 refactor and has now been reincluded as SCWRYPTS__GET_REALPATH
- Loading branch information
Showing
21 changed files
with
530 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
name: Update Semver | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
branches-ignore: | ||
- '**' | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
update-semver: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: rickstaa/action-update-semver@v1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- # allow running scwrypts in Github Actions | ||
name: scwrypts | ||
author: yage | ||
description: check requird dependencies and run a scwrypt | ||
|
||
inputs: | ||
scwrypt: | ||
description: "args / identifiers for scwrypts CLI (e.g. '--name <scwrypt-name> --group <group-name> --type <type-name>')" | ||
required: true | ||
|
||
args: | ||
description: "arguments to pass to the scwrypt-to-be-run" | ||
required: false | ||
|
||
version: | ||
description: "scwrypts version; defaults to latest (minimum v3.7.0)" | ||
required: false | ||
|
||
scwrypts-env: | ||
description: "override value for SCWRYPTS_ENV" | ||
required: false | ||
default: "ci.github-actions" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: wrynegade/scwrypts | ||
path: ./scwrypts | ||
ref: ${{ inputs.version }} | ||
|
||
- name: check dependencies | ||
shell: bash | ||
env: | ||
CI: true | ||
SCWRYPTS_PLUGIN_ENABLED__ci: 1 | ||
run: | | ||
[ $CI_SCWRYPTS_READY ] && [[ $CI_SCWRYPTS_READY -eq 1 ]] && echo 'setup completed previously' && exit 0 | ||
echo "updating package dependencies" | ||
{ | ||
sudo apt-get update | ||
sudo apt-get install --yes zsh fzf ripgrep | ||
for D in $($GITHUB_WORKSPACE/scwrypts/scwrypts -n --name check-all-dependencies --group ci --type zsh) | ||
do | ||
echo "--- installing $D ---" | ||
( sudo apt-get install --yes $D; exit 0; ) | ||
done | ||
} > $HOME/.scwrypts.apt-get.log 2>&1 | ||
echo "updating virtual dependencies" | ||
$GITHUB_WORKSPACE/scwrypts/scwrypts -n \ | ||
--name scwrypts/virtualenv/update-all \ | ||
--group scwrypts \ | ||
--type zsh \ | ||
> $HOME/.scwrypts.virtualenv.log 2>&1 | ||
echo "CI_SCWRYPTS_READY=1" >> $GITHUB_ENV | ||
exit 0 | ||
- name: run scwrypt | ||
shell: bash | ||
env: | ||
CI: true | ||
SCWRYPTS_ENV: ${{ inputs.scwrypts-env }} | ||
run: $GITHUB_WORKSPACE/scwrypts/scwrypts ${{inputs.scwrypt}} -- ${{inputs.args}} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#!/bin/zsh |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Kubernetes `kubectl` Helper Plugin | ||
|
||
Leverages a local `redis` application to quickly and easily set an alias `k` for `kubectl --context <some-context> --namespace <some-namespace>`. | ||
Much like scwrypts environments, `k` aliases are *only* shared amongst session with the same `SCWRYPTS_ENV` to prevent accidental cross-contamination. | ||
|
||
|
||
## Getting Started | ||
|
||
Enable the plugin in `~/.config/scwrypts/config.zsh` by adding `SCWRYPTS_PLUGIN_ENABLED__KUBECTL=1`. | ||
Use `k` as your new `kubectl` and checkout `k --help` and `k meta --help`. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/zsh | ||
##################################################################### | ||
DEPENDENCIES+=() | ||
REQUIRED_ENV+=() | ||
##################################################################### | ||
|
||
MAIN() { | ||
cd "$SCWRYPTS_ROOT__scwrypts/" | ||
|
||
DEPENDENCIES+=() | ||
for group in ${SCWRYPTS_GROUPS[@]} | ||
do | ||
[[ $group =~ ^ci$ ]] && continue | ||
|
||
GROUP_HOME="$(eval 'echo $SCWRYPTS_ROOT__'$group)" | ||
[ $GROUP_HOME ] && [ -d "$GROUP_HOME" ] || continue | ||
|
||
STATUS "checking dependencies for $group" | ||
DEPENDENCIES+=($( | ||
for file in $( | ||
{ | ||
cd "$GROUP_HOME" | ||
rg -l '^DEPENDENCIES\+=\($' | ||
rg -l '^DEPENDENCIES\+=\([^)]\+\)' | ||
} | grep -v '\.md$' | grep -v 'check-all-dependencies$') | ||
do | ||
sed -z 's/.*DEPENDENCIES+=(\([^)]*\)).*/\1\n/; s/#.*\n//g; s/\s\+/\n/g' "$GROUP_HOME/$file" | ||
done | ||
)) | ||
done | ||
|
||
DEPENDENCIES=(zsh $(echo $DEPENDENCIES | sed 's/ /\n/g' | sort -u | grep '^[-_a-zA-Z]\+$')) | ||
|
||
STATUS "discovered dependencies: ($DEPENDENCIES)" | ||
echo $DEPENDENCIES | sed 's/ /\n/g' | ||
CHECK_ENVIRONMENT && SUCCESS "all dependencies satisfied" | ||
} | ||
|
||
##################################################################### | ||
MAIN $@ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SCWRYPTS_GROUPS+=(ci) | ||
|
||
export SCWRYPTS_TYPE__ci=zsh | ||
export SCWRYPTS_ROOT__ci="$SCWRYPTS_ROOT__scwrypts/plugins/ci" | ||
export SCWRYPTS_COLOR__ci='\033[0m' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/zsh | ||
DEPENDENCIES+=() | ||
REQUIRED_ENV+=() | ||
|
||
use helm | ||
use scwrypts | ||
|
||
CHECK_ENVIRONMENT | ||
##################################################################### | ||
|
||
MAIN() { | ||
unset USAGE | ||
HELM__TEMPLATE__GET $@ | ||
} | ||
|
||
##################################################################### | ||
MAIN $@ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/zsh | ||
DEPENDENCIES+=() | ||
REQUIRED_ENV+=() | ||
|
||
use helm | ||
use scwrypts | ||
|
||
CHECK_ENVIRONMENT | ||
##################################################################### | ||
|
||
MAIN() { | ||
unset USAGE | ||
HELM__DEPENDENCY__UPDATE $@ | ||
} | ||
|
||
##################################################################### | ||
MAIN $@ |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
##################################################################### | ||
|
||
DEPENDENCIES+=(helm kubeval) | ||
REQUIRED_ENV+=() | ||
|
||
use helm/validate | ||
|
||
##################################################################### | ||
|
||
HELM__DEPENDENCY__UPDATE() { | ||
[ ! $USAGE ] && local USAGE=" | ||
usage: [...options...] | ||
options | ||
-t, --template-filename path to a template/*.yaml file of a helm chart | ||
Auto-detect chart and build dependencies for any file within a helm chart. | ||
" | ||
local TEMPLATE_FILENAME CHART_ROOT VALUES_FILES=() | ||
local COLORIZE=0 RAW=0 DEBUG=0 | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
case $1 in | ||
-t | --template-filename ) TEMPLATE_FILENAME="$(SCWRYPTS__GET_REALPATH "$2")"; shift 1 ;; | ||
|
||
* ) ERROR "unexpected argument '$1'" ;; | ||
esac | ||
shift 1 | ||
done | ||
|
||
HELM__VALIDATE | ||
CHECK_ERRORS || return 1 | ||
|
||
########################################## | ||
|
||
STATUS "updating helm dependencies for '$CHART_ROOT'" \ | ||
&& cd $CHART_ROOT \ | ||
&& helm dependency update \ | ||
&& SUCCESS "helm chart dependencies updated" \ | ||
|| { ERROR "unable to update helm chart dependencies (see above)"; return 1; } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
##################################################################### | ||
|
||
DEPENDENCIES+=() | ||
REQUIRED_ENV+=() | ||
|
||
use helm/dependency | ||
use helm/template | ||
|
||
##################################################################### |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
##################################################################### | ||
|
||
DEPENDENCIES+=(helm kubeval) | ||
REQUIRED_ENV+=() | ||
|
||
use helm/validate | ||
|
||
##################################################################### | ||
|
||
HELM__TEMPLATE__GET() { | ||
[ ! $USAGE ] && local USAGE=" | ||
usage: [...options...] (--) [...helm args...] | ||
options | ||
-t, --template-filename path to a template/*.yaml file of a helm chart | ||
--colorize use 'bat' to colorize output | ||
--raw remove scwrypts-added fluff and only output helm template details | ||
Smart helm-template generator which auto-detects the chart | ||
and sample values for testing and developing helm charts. | ||
" | ||
local HELM_ARGS=() | ||
local TEMPLATE_FILENAME TEMPLATE_NAME CHART_ROOT CHART_NAME VALUES_FILES=() | ||
local COLORIZE=0 RAW=0 DEBUG=0 | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
case $1 in | ||
-t | --template-filename ) TEMPLATE_FILENAME="$(SCWRYPTS__GET_REALPATH "$2")"; shift 1 ;; | ||
|
||
--colorize ) | ||
DEPENDENCIES=(bat) CHECK_ENVIRONMENT || return 1 | ||
COLORIZE=1 | ||
;; | ||
|
||
--raw ) RAW=1 ;; | ||
-- ) shift 1; break ;; | ||
|
||
* ) HELM_ARGS+=($1) ;; | ||
esac | ||
shift 1 | ||
done | ||
|
||
while [[ $# -gt 0 ]]; do HELM_ARGS+=($1); shift 1; done | ||
|
||
HELM__VALIDATE | ||
CHECK_ERRORS || return 1 | ||
|
||
########################################## | ||
|
||
local EXIT_CODE=0 | ||
local TEMPLATE_OUTPUT DEBUG_OUTPUT | ||
[ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] && { | ||
CAPTURE TEMPLATE_OUTPUT DEBUG_OUTPUT helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug | ||
true | ||
} || { | ||
CAPTURE TEMPLATE_OUTPUT DEBUG_OUTPUT helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug --show-only "$(echo $TEMPLATE_FILENAME | sed "s|^$CHART_ROOT/||")" | ||
} | ||
|
||
[ ! $TEMPLATE_OUTPUT ] && EXIT_CODE=1 | ||
|
||
[[ $RAW -eq 1 ]] && { | ||
[ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] || HELM_ARGS+=(--show-only $(echo $TEMPLATE_FILENAME | sed "s|^$CHART_ROOT/||")) | ||
[[ $COLORIZE -eq 1 ]] \ | ||
&& helm template "$CHART_ROOT" ${HELM_ARGS[@]} 2>&1 | bat --language yaml --color always \ | ||
|| helm template "$CHART_ROOT" ${HELM_ARGS[@]} | grep -v '^# Source:.*$' \ | ||
; | ||
|
||
return $EXIT_CODE | ||
} | ||
|
||
[ $TEMPLATE_OUTPUT ] && { | ||
KUBEVAL_RAW=$(echo $TEMPLATE_OUTPUT | kubeval --schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master) | ||
true | ||
} || { | ||
TEMPLATE_OUTPUT="---\nerror: chart or '$(basename $(dirname $TEMPLATE_FILENAME))/$(basename $TEMPLATE_FILENAME)' invalid" | ||
KUBEVAL_RAW="no template output; kubeval skipped" | ||
|
||
[ $USE_CHART_ROOT ] && [[ $USE_CHART_ROOT -eq 1 ]] || { | ||
DEBUG_OUTPUT="$(helm template "$CHART_ROOT" ${HELM_ARGS[@]} --debug 2>&1 >/dev/null)" | ||
} | ||
} | ||
|
||
TEMPLATE_OUTPUT="$TEMPLATE_OUTPUT | ||
--- | ||
debug: | | ||
$(echo $DEBUG_OUTPUT | sed 's/^/ /g') | ||
kubeval: | | ||
$(echo $KUBEVAL_RAW | sed 's/^/ /g') | ||
lint: | | ||
$(helm lint $CHART_ROOT ${HELM_ARGS[@]} 2>&1 | sed 's/^/ /g') | ||
" | ||
|
||
[[ $COLORIZE -eq 1 ]] && { | ||
echo $TEMPLATE_OUTPUT | bat --language yaml --color always | ||
} || { | ||
echo $TEMPLATE_OUTPUT | ||
} | ||
|
||
return $EXIT_CODE | ||
} |
Oops, something went wrong.