Skip to content

Commit

Permalink
prepare krew integration, publish bin as tar.gz
Browse files Browse the repository at this point in the history
  • Loading branch information
majodev committed Jan 6, 2025
1 parent 12891e9 commit bf30bfc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build-test-publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,25 @@ jobs:
# Update version in script
sed -i "s/VERSION=\".*\"/VERSION=\"${VERSION}\"/" dist/kubectl-envx
chmod +x dist/kubectl-envx
tar -czf dist/kubectl-envx.tar.gz -C dist kubectl-envx
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/kubectl-envx
files: dist/kubectl-envx.zip
name: Release ${{ github.ref_name }}
body: |
## kubectl-envx ${{ github.ref_name }}
Binary: `kubectl-envx`
Archive: `kubectl-envx.tar.gz`
### Installation
```bash
curl -Lo kubectl-envx https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/kubectl-envx
curl -Lo kubectl-envx.tar.gz https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/kubectl-envx.tar.gz
tar xzf kubectl-envx.tar.gz
chmod +x kubectl-envx
sudo mv kubectl-envx /usr/local/bin/
rm kubectl-envx.tar.gz
```
draft: false
prerelease: false
Expand Down
9 changes: 7 additions & 2 deletions kubectl-envx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -Eeo pipefail
VERSION="0.0.0-dev" # release build pinned

usage() {
ORIGIN_SCRIPT=$(basename "$0")
ORIGIN_SCRIPT="kubectl envx" # assert used as kubectl plugin is the primary usecase

echo "Usage: $ORIGIN_SCRIPT <kind/name> [-n|--namespace <namespace>] [-c|--container <container>] [ENV_KEY=ENV_VALUE...] [-- command [args...]]"
echo "Version: $VERSION"
Expand All @@ -23,7 +23,6 @@ usage() {
echo " $ORIGIN_SCRIPT deployment/myapp -n prod -c nginx MY_VAR=value # Combined usage"
echo " $ORIGIN_SCRIPT deployment/myapp -- env # Run command with variables"
echo " $ORIGIN_SCRIPT deployment/myapp -c nginx -- env # Run command with container vars"
exit 1
}

# Initialize variables
Expand All @@ -42,6 +41,10 @@ while [[ $# -gt 0 ]]; do
fi

case $1 in
-h|--help)
usage
exit 0
;;
-n|--namespace)
NAMESPACE="$2"
shift 2
Expand Down Expand Up @@ -69,6 +72,7 @@ while [[ $# -gt 0 ]]; do
*)
echo "Error: Invalid argument '$1'"
usage
exit 1
;;
esac
done
Expand All @@ -77,6 +81,7 @@ done
if [[ -z "$RESOURCE" ]]; then
echo "Error: Resource (kind/name) is required"
usage
exit 1
fi

# Build kubectl arguments array for get commands
Expand Down
10 changes: 10 additions & 0 deletions test/test_main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ kubectl-envx() {
assert_output --partial "Error: Invalid argument 'INVALID'"
}

@test "displays usage on -h and --help" {
run kubectl-envx --help
assert_success
assert_output --partial "Usage:"

run kubectl-envx -h
assert_success
assert_output --partial "Usage:"
}

@test "deployment/noenv: prints ENV (nothing)" {
run kubectl-envx deployment/noenv
assert_success
Expand Down

0 comments on commit bf30bfc

Please sign in to comment.