mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
build: Converted Makefile and flake package.
This commit is contained in:
28
.github/workflows/go.yml
vendored
28
.github/workflows/go.yml
vendored
@@ -1,28 +0,0 @@
|
|||||||
# This workflow will build a golang project
|
|
||||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
|
||||||
|
|
||||||
name: Go
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "main" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: '1.24.6'
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: go build -v ./...
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: go test -v ./...
|
|
||||||
31
.github/workflows/odin.yml
vendored
Normal file
31
.github/workflows/odin.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: Odin
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libsodium-dev sqlite3 libsqlite3-dev
|
||||||
|
|
||||||
|
- name: Install Odin
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/odin-lang/Odin.git /opt/odin
|
||||||
|
cd /opt/odin
|
||||||
|
./build_odin.sh release
|
||||||
|
echo "/opt/odin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: odin build . -o:speed -out:envr
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: odin test .
|
||||||
2
.github/workflows/release-please.yml
vendored
2
.github/workflows/release-please.yml
vendored
@@ -22,4 +22,4 @@ jobs:
|
|||||||
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
|
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
|
||||||
# this is a built-in strategy in release-please, see "Action Inputs"
|
# this is a built-in strategy in release-please, see "Action Inputs"
|
||||||
# for more options
|
# for more options
|
||||||
release-type: go
|
release-type: odin
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ builds
|
|||||||
envr
|
envr
|
||||||
envr-go
|
envr-go
|
||||||
result
|
result
|
||||||
|
version.odin
|
||||||
|
|||||||
41
Makefile
41
Makefile
@@ -4,7 +4,6 @@
|
|||||||
APP_NAME := envr
|
APP_NAME := envr
|
||||||
VERSION := $(shell grep 'version = ' flake.nix | head -1 | sed 's/.*version = "\(.*\)";/\1/')
|
VERSION := $(shell grep 'version = ' flake.nix | head -1 | sed 's/.*version = "\(.*\)";/\1/')
|
||||||
BUILD_DIR := builds
|
BUILD_DIR := builds
|
||||||
LDFLAGS := -X github.com/sbrow/envr/cmd.version=v$(VERSION) -s -w
|
|
||||||
|
|
||||||
# Binary names
|
# Binary names
|
||||||
LINUX_AMD64_BIN := $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64
|
LINUX_AMD64_BIN := $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64
|
||||||
@@ -20,26 +19,31 @@ all: release clean
|
|||||||
$(BUILD_DIR):
|
$(BUILD_DIR):
|
||||||
@mkdir -p $(BUILD_DIR)
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
|
# Generate version.odin from flake.nix
|
||||||
|
version.odin:
|
||||||
|
@echo 'Generating version.odin (v$(VERSION))...'
|
||||||
|
@printf 'package main\n\nVERSION :: "$(VERSION)"\n' > version.odin
|
||||||
|
|
||||||
# Build Linux AMD64
|
# Build Linux AMD64
|
||||||
$(LINUX_AMD64_BIN): $(BUILD_DIR)
|
$(LINUX_AMD64_BIN): version.odin $(BUILD_DIR)
|
||||||
@echo "Building for Linux AMD64..."
|
@echo "Building for Linux AMD64..."
|
||||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(LINUX_AMD64_BIN) .
|
odin build . -target:linux_amd64 -o:speed -out:$(LINUX_AMD64_BIN)
|
||||||
@echo "Built $(LINUX_AMD64_BIN)"
|
@echo "Built $(LINUX_AMD64_BIN)"
|
||||||
|
|
||||||
# Build Linux ARM64
|
# Build Linux ARM64
|
||||||
$(LINUX_ARM64_BIN): $(BUILD_DIR)
|
$(LINUX_ARM64_BIN): version.odin $(BUILD_DIR)
|
||||||
@echo "Building for Linux ARM64..."
|
@echo "Building for Linux ARM64..."
|
||||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(LINUX_ARM64_BIN) .
|
odin build . -target:linux_arm64 -o:speed -out:$(LINUX_ARM64_BIN)
|
||||||
@echo "Built $(LINUX_ARM64_BIN)"
|
@echo "Built $(LINUX_ARM64_BIN)"
|
||||||
|
|
||||||
# Build Darwin ARM64 (Mac)
|
# Build Darwin ARM64 (Mac)
|
||||||
$(DARWIN_ARM64_BIN): $(BUILD_DIR)
|
$(DARWIN_ARM64_BIN): version.odin $(BUILD_DIR)
|
||||||
@echo "Building for Darwin ARM64..."
|
@echo "Building for Darwin ARM64..."
|
||||||
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(DARWIN_ARM64_BIN) .
|
odin build . -target:darwin_arm64 -o:speed -out:$(DARWIN_ARM64_BIN)
|
||||||
@echo "Built $(DARWIN_ARM64_BIN)"
|
@echo "Built $(DARWIN_ARM64_BIN)"
|
||||||
|
|
||||||
# Build all binaries
|
# Build all binaries
|
||||||
build-linux: $(LINUX_AMD64_BIN) $(LINUX_ARM64_BIN)
|
build-linux: $(LINUX_AMD64_BIN) # $(LINUX_ARM64_BIN)
|
||||||
build-darwin: $(DARWIN_ARM64_BIN)
|
build-darwin: $(DARWIN_ARM64_BIN)
|
||||||
|
|
||||||
# Compress Linux artifacts with gzip
|
# Compress Linux artifacts with gzip
|
||||||
@@ -58,11 +62,12 @@ $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-darwin-arm64.zip: $(DARWIN_ARM64_BIN)
|
|||||||
|
|
||||||
# Compress all artifacts
|
# Compress all artifacts
|
||||||
compress: $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64.tar.gz \
|
compress: $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64.tar.gz \
|
||||||
$(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-arm64.tar.gz \
|
# $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-arm64.tar.gz \
|
||||||
$(BUILD_DIR)/$(APP_NAME)-$(VERSION)-darwin-arm64.zip
|
# $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-darwin-arm64.zip
|
||||||
|
|
||||||
# Build and compress all release artifacts
|
# Build and compress all release artifacts
|
||||||
release: build-linux build-darwin compress
|
# release: build-linux build-darwin compress
|
||||||
|
release: build-linux compress
|
||||||
@echo "Release artifacts created:"
|
@echo "Release artifacts created:"
|
||||||
@ls -la $(BUILD_DIR)/*.tar.gz $(BUILD_DIR)/*.zip 2>/dev/null || echo "No compressed artifacts found"
|
@ls -la $(BUILD_DIR)/*.tar.gz $(BUILD_DIR)/*.zip 2>/dev/null || echo "No compressed artifacts found"
|
||||||
|
|
||||||
@@ -79,14 +84,14 @@ cleanall:
|
|||||||
# Show available targets
|
# Show available targets
|
||||||
help:
|
help:
|
||||||
@echo "Available targets:"
|
@echo "Available targets:"
|
||||||
@echo " all - Build all release artifacts (default)"
|
@echo " all - Build all release artifacts (default)"
|
||||||
@echo " release - Build and compress all release artifacts"
|
@echo " release - Build and compress all release artifacts"
|
||||||
@echo " build-linux - Build Linux binaries only"
|
@echo " build-linux - Build Linux binaries only"
|
||||||
@echo " build-darwin - Build Darwin binaries only"
|
@echo " build-darwin - Build Darwin binaries only"
|
||||||
@echo " compress - Compress all built binaries"
|
@echo " compress - Compress all built binaries"
|
||||||
@echo " clean - Remove binary files only"
|
@echo " clean - Remove binary files only"
|
||||||
@echo " cleanall - Remove entire build directory"
|
@echo " cleanall - Remove entire build directory"
|
||||||
@echo " help - Show this help message"
|
@echo " help - Show this help message"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Release artifacts will be created in $(BUILD_DIR)/"
|
@echo "Release artifacts will be created in $(BUILD_DIR)/"
|
||||||
@echo "Version: $(VERSION)"
|
@echo "Version: $(VERSION)"
|
||||||
|
|||||||
4
TODOS.md
4
TODOS.md
@@ -36,6 +36,8 @@ Note: These todos can wait until all the subcommands have been ported.
|
|||||||
|
|
||||||
35. **prompt.odin:124** — `make([dynamic]bool, len(options))` creates N zero-initialized elements. Works because `false` is the default, but same footgun as original issue 1. Should be `make([dynamic]bool, 0, len(options))`.
|
35. **prompt.odin:124** — `make([dynamic]bool, len(options))` creates N zero-initialized elements. Works because `false` is the default, but same footgun as original issue 1. Should be `make([dynamic]bool, 0, len(options))`.
|
||||||
|
|
||||||
|
39. Lots of memory leaks to fix.
|
||||||
|
|
||||||
## LOW
|
## LOW
|
||||||
|
|
||||||
15. **db.odin:115** — `json.unmarshal_string` error not checked. Malformed JSON silently produces empty/partial data.
|
15. **db.odin:115** — `json.unmarshal_string` error not checked. Malformed JSON silently produces empty/partial data.
|
||||||
@@ -63,3 +65,5 @@ Note: These todos can wait until all the subcommands have been ported.
|
|||||||
27. version --long Odin only prints version; Go also prints commit hash and build date
|
27. version --long Odin only prints version; Go also prints commit hash and build date
|
||||||
|
|
||||||
28. 2 scan tests silently skip Low When fd isn't installed, tests pass without actually testing anything. These should use #assert to be sure that fd is in path.
|
28. 2 scan tests silently skip Low When fd isn't installed, tests pass without actually testing anything. These should use #assert to be sure that fd is in path.
|
||||||
|
|
||||||
|
38. Try to do all encryption / decryption in memory - only read / write encrypted data to disk.
|
||||||
|
|||||||
79
cmd/mod.nu
79
cmd/mod.nu
@@ -1,79 +0,0 @@
|
|||||||
# envr command extern definitions for Nushell
|
|
||||||
# A tool for managing environment files and backups
|
|
||||||
|
|
||||||
export def tracked-paths [] {
|
|
||||||
(
|
|
||||||
^envr list
|
|
||||||
| from json
|
|
||||||
| each {
|
|
||||||
[$in.directory $in.path] | path join
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export def untracked-paths [] {
|
|
||||||
(
|
|
||||||
^envr scan
|
|
||||||
| from json
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Complete shell types for completion command
|
|
||||||
def shells [] {
|
|
||||||
["bash", "zsh", "fish", "powershell"]
|
|
||||||
}
|
|
||||||
|
|
||||||
export extern envr [
|
|
||||||
...args: any
|
|
||||||
--help(-h) # Show help information
|
|
||||||
--toggle(-t) # Help message for toggle
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr backup" [
|
|
||||||
--help(-h) # Show help for backup command
|
|
||||||
path: path@untracked-paths # Path to .env file to backup
|
|
||||||
]
|
|
||||||
#TODO: envr backup path.
|
|
||||||
|
|
||||||
export extern "envr check" [
|
|
||||||
--help(-h) # Show help for check command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr completion" [
|
|
||||||
shell: string@shells # Shell to generate completion for
|
|
||||||
--help(-h) # Show help for completion command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr edit-config" [
|
|
||||||
--help(-h) # Show help for edit-config command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr help" [
|
|
||||||
command?: string # Show help for specific command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr init" [
|
|
||||||
--help(-h) # Show help for init command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr list" [
|
|
||||||
--help(-h) # Show help for list command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr remove" [
|
|
||||||
--help(-h) # Show help for remove command
|
|
||||||
path: path@tracked-paths
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr restore" [
|
|
||||||
--help(-h) # Show help for restore command
|
|
||||||
path: path@tracked-paths
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr scan" [
|
|
||||||
--help(-h) # Show help for scan command
|
|
||||||
]
|
|
||||||
|
|
||||||
export extern "envr sync" [
|
|
||||||
--help(-h) # Show help for sync command
|
|
||||||
]
|
|
||||||
@@ -2,8 +2,6 @@ package main
|
|||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
|
||||||
VERSION :: "0.2.0"
|
|
||||||
|
|
||||||
cmd_version :: proc(cmd: ^Command) {
|
cmd_version :: proc(cmd: ^Command) {
|
||||||
if has_flag(cmd, "long") || has_flag(cmd, "l") {
|
if has_flag(cmd, "long") || has_flag(cmd, "l") {
|
||||||
fmt.printf("envr version %s\n", VERSION)
|
fmt.printf("envr version %s\n", VERSION)
|
||||||
@@ -11,3 +9,4 @@ cmd_version :: proc(cmd: ^Command) {
|
|||||||
fmt.println(VERSION)
|
fmt.println(VERSION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:encoding/json"
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:path/filepath"
|
import "core:path/filepath"
|
||||||
@@ -23,7 +22,7 @@ fixture_db_path :: proc() -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fixture_config :: proc() -> Config {
|
fixture_config :: proc() -> Config {
|
||||||
cfg := Config{
|
cfg := Config {
|
||||||
Keys = make([dynamic]SshKeyPair, 0, 1),
|
Keys = make([dynamic]SshKeyPair, 0, 1),
|
||||||
}
|
}
|
||||||
append(&cfg.Keys, fixture_key())
|
append(&cfg.Keys, fixture_key())
|
||||||
@@ -263,7 +262,11 @@ test_full_db_cycle :: proc(t: ^testing.T) {
|
|||||||
testing.expect(
|
testing.expect(
|
||||||
t,
|
t,
|
||||||
len(plaintext2) == len(original_data),
|
len(plaintext2) == len(original_data),
|
||||||
fmt.tprintf("double round-trip size mismatch: expected %d, got %d", len(original_data), len(plaintext2)),
|
fmt.tprintf(
|
||||||
|
"double round-trip size mismatch: expected %d, got %d",
|
||||||
|
len(original_data),
|
||||||
|
len(plaintext2),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(data_path)
|
os.remove(data_path)
|
||||||
@@ -289,12 +292,7 @@ test_ssh_key_parse_from_fixtures :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i in 0 ..< 32 {
|
for i in 0 ..< 32 {
|
||||||
testing.expectf(
|
testing.expectf(t, priv_kp.Public[i] == pub_key[i], "public key mismatch at byte %d", i)
|
||||||
t,
|
|
||||||
priv_kp.Public[i] == pub_key[i],
|
|
||||||
"public key mismatch at byte %d",
|
|
||||||
i,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x25519_pairs, x_ok := ssh_to_x25519([]SshKeyPair{key})
|
x25519_pairs, x_ok := ssh_to_x25519([]SshKeyPair{key})
|
||||||
@@ -327,3 +325,4 @@ test_config_load_with_fixture_key :: proc(t: ^testing.T) {
|
|||||||
fmt.printf(" private key path was: '%s'\n", key.Private)
|
fmt.printf(" private key path was: '%s'\n", key.Private)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
80
flake.nix
80
flake.nix
@@ -40,7 +40,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
treefmt = {
|
treefmt = {
|
||||||
# Used to find the project root
|
|
||||||
projectRootFile = "flake.nix";
|
projectRootFile = "flake.nix";
|
||||||
settings.global.excludes = [
|
settings.global.excludes = [
|
||||||
".direnv/**"
|
".direnv/**"
|
||||||
@@ -50,68 +49,57 @@
|
|||||||
".env.local"
|
".env.local"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
# Format nix files
|
|
||||||
programs.nixpkgs-fmt.enable = true;
|
programs.nixpkgs-fmt.enable = true;
|
||||||
# programs.deadnix.enable = true;
|
|
||||||
|
|
||||||
# Format go files
|
|
||||||
programs.goimports.enable = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.default = pkgs.buildGoModule rec {
|
packages.default = pkgs.stdenv.mkDerivation rec {
|
||||||
pname = "envr";
|
pname = "envr";
|
||||||
version = "0.2.0";
|
version = "0.2.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
# If the build complains, uncomment this line
|
|
||||||
# vendorHash = "sha256:0000000000000000000000000000000000000000000000000000";
|
|
||||||
vendorHash = "sha256-aC82an6vYifewx4amfXLzk639jz9fF5bD5cF6krY0Ks=";
|
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.installShellFiles ];
|
nativeBuildInputs = [
|
||||||
|
pkgs.unstable.odin
|
||||||
ldflags = [
|
pkgs.pkg-config
|
||||||
"-X github.com/sbrow/envr/cmd.version=v${version}"
|
|
||||||
# "-X github.com/sbrow/envr/cmd.commit=$(git rev-parse HEAD)"
|
|
||||||
# "-X github.com/sbrow/envr/cmd.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
postBuild = ''
|
buildInputs = [
|
||||||
# Generate man pages
|
pkgs.libsodium
|
||||||
$GOPATH/bin/docgen -out ./man -format man
|
pkgs.sqlite
|
||||||
|
];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
make version.odin
|
||||||
|
odin build . -o:speed -out:${pname}
|
||||||
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postInstall = ''
|
installPhase = ''
|
||||||
# Install man pages
|
runHook preInstall
|
||||||
installManPage ./man/*.1
|
install -Dm755 ${pname} $out/bin/${pname}
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell
|
devShells.default = pkgs.mkShell {
|
||||||
{
|
buildInputs = with pkgs; [
|
||||||
buildInputs = with pkgs; [
|
fd
|
||||||
fd
|
nushell
|
||||||
nushell
|
|
||||||
go
|
|
||||||
gopls
|
|
||||||
|
|
||||||
gotools
|
libsodium
|
||||||
cobra-cli
|
sqlite
|
||||||
|
unstable.odin
|
||||||
|
unstable.ols
|
||||||
|
|
||||||
age
|
# Build tools
|
||||||
libsodium
|
zip
|
||||||
sqlite
|
|
||||||
unstable.odin
|
|
||||||
unstable.ols
|
|
||||||
|
|
||||||
# Build tools
|
# IDE
|
||||||
zip
|
unstable.helix
|
||||||
|
typescript-language-server
|
||||||
# IDE
|
vscode-langservers-extracted
|
||||||
unstable.helix
|
];
|
||||||
typescript-language-server
|
};
|
||||||
vscode-langservers-extracted
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user