Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 57 additions & 75 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,108 +13,90 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.25.3'

- name: Lint Check
run: go vet ./...

- name: Run tests
run: go test -v ./...

# Create release
create-release:
# Create release and build binaries
release:
needs: test
runs-on: ubuntu-latest
outputs:
RELEASE_URL: ${{ steps.create-release.outputs.upload_url }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags

- name: Get Version
id: get_version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV

- name: Verify latest release tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Latest tag: $latest_tag"
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV
VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"

- name: Check if new release is needed
- name: Check if release exists
id: check_release
run: |
if [ "$LATEST_TAG" = "v$VERSION" ]; then
echo "No new release needed"
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
git fetch --tags
if git rev-parse "v${{ steps.get_version.outputs.VERSION }}" >/dev/null 2>&1; then
echo "RELEASE_EXISTS=true" >> $GITHUB_OUTPUT
echo "Release v${{ steps.get_version.outputs.VERSION }} already exists"
else
echo "SKIP_RELEASE=false" >> $GITHUB_ENV
echo "RELEASE_EXISTS=false" >> $GITHUB_OUTPUT
echo "Creating new release v${{ steps.get_version.outputs.VERSION }}"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV

- name: Create Release
id: create-release
if: env.SKIP_RELEASE != 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
draft: false
prerelease: false

build:
needs: create-release
# Run only if a valid release url has been set
if: ${{ needs.create-release.outputs.RELEASE_URL }} != ''
strategy:
matrix:
os: ['windows', 'linux', 'darwin']
arch: ['amd64', 'arm64']
exclude:
- os: windows
arch: arm64
- os: linux
arch: arm64
- os: darwin
arch: amd64

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
if: steps.check_release.outputs.RELEASE_EXISTS == 'false'
uses: actions/setup-go@v5
with:
go-version: '1.21' # Use the Go version of your choice
go-version: '1.25.3'

- name: Create distribution directory
run: mkdir -p ${{ env.DIST_DIR }}
shell: bash

- name: Build
- name: Build binaries
if: steps.check_release.outputs.RELEASE_EXISTS == 'false'
run: |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
env:
VERSION: ${{ needs.create-release.outputs.VERSION }}
mkdir -p ${{ env.DIST_DIR }}

# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-linux-amd64

# Linux ARM64
GOOS=linux GOARCH=arm64 go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-linux-arm64

# macOS AMD64 (Intel)
GOOS=darwin GOARCH=amd64 go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-darwin-amd64

# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-darwin-arm64

# Windows AMD64
GOOS=windows GOARCH=amd64 go build -o ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-windows-amd64.exe

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Create Release
if: steps.check_release.outputs.RELEASE_EXISTS == 'false'
uses: softprops/action-gh-release@v2
with:
upload_url: ${{ needs.create-release.outputs.RELEASE_URL }}
asset_path: ${{ env.DIST_DIR }}/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
asset_name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
asset_content_type: application/gzip
tag_name: v${{ steps.get_version.outputs.VERSION }}
name: Release v${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: false
files: |
${{ env.DIST_DIR }}/${{ env.APP_NAME }}-linux-amd64
${{ env.DIST_DIR }}/${{ env.APP_NAME }}-linux-arm64
${{ env.DIST_DIR }}/${{ env.APP_NAME }}-darwin-amd64
${{ env.DIST_DIR }}/${{ env.APP_NAME }}-darwin-arm64
${{ env.DIST_DIR }}/${{ env.APP_NAME }}-windows-amd64.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.25.3'

- name: Lint Check
run: go vet ./...
Expand Down
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"go.goroot": "${env:HOME}/.local/share/mise/installs/go/1.25.3",
"go.gopath": "${env:HOME}/go",
"go.toolsGopath": "${env:HOME}/.local/share/mise/installs/go/1.25.3",
"go.alternateTools": {
"go": "${env:HOME}/.local/share/mise/installs/go/1.25.3/bin/go",
"gopls": "${env:HOME}/.local/share/mise/installs/go/1.25.3/bin/gopls",
"dlv": "${env:HOME}/.local/share/mise/installs/go/1.25.3/bin/dlv"
}
}

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.26
0.1.0
29 changes: 24 additions & 5 deletions cli/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ import (
)

type CommandType struct {
Command string `arg:"positional,required"`
FromFile string `arg:"-f"`
Identifier string `arg:"-i"`
Command string `arg:"positional,required" help:"Command to execute: add, get, list, create, remove"`
FromFile string `arg:"-f" help:"Path to environment file"`
Identifier string `arg:"-i" help:"Unique identifier for the environment configuration"`
RestoreAs string `arg:"-r" help:"Filename to restore the environment file as (default: .env)"`
}

func (CommandType) Description() string {
return `Environment Manager - Securely store and manage environment configurations

Commands:
add Add an environment file with headers (requires -f)
get Retrieve and restore an environment configuration (requires -i)
list List all saved environment configurations
create Create environment configuration from a file without headers (requires -f, -i)
remove Remove an environment configuration (requires -i)

Examples:
env-manager add -f .env.local
env-manager create -f secrets.txt -i production -r .env.prod
env-manager get -i production
env-manager list
env-manager remove -i production`
}

func (c *CommandType) validateCommand() {
Expand All @@ -17,10 +36,10 @@ func (c *CommandType) validateCommand() {
}
}

panic("Invalid command. Valid commands are init and get")
panic("Invalid command. Valid commands are add, get, list, remove, and create")
}

var validCommands [4]string = [4]string{"add", "get", "list", "remove"}
var validCommands [5]string = [5]string{"add", "get", "list", "remove", "create"}

func ParseArgs() CommandType {
var cmd CommandType
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/vertefra/env
module github.com/thinktwiceco/env-manager

go 1.21.4
go 1.25.3

require (
github.com/alexflint/go-arg v1.4.3 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
)
require github.com/alexflint/go-arg v1.6.0

require github.com/alexflint/go-scalar v1.2.0 // indirect
17 changes: 9 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/alexflint/go-arg v1.6.0 h1:wPP9TwTPO54fUVQl4nZoxbFfKCcy5E6HBCumj1XVRSo=
github.com/alexflint/go-arg v1.6.0/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Set the GitHub repository
REPO="vertefra/env-manager"
REPO="thinktwiceco/env-manager"

# Get the OS and architecture for the system
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
Expand Down
Loading