From 0a0ee083bb61ff73bce80941a09c500ee3a24923 Mon Sep 17 00:00:00 2001 From: Ole Magnus Fon Johnsen Date: Sun, 9 Mar 2025 21:42:52 +0100 Subject: [PATCH 1/6] Use zip on windows --- install.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 56f0b11..c8a8431 100644 --- a/install.sh +++ b/install.sh @@ -32,6 +32,12 @@ if [ "$target" = "unknown" ]; then exit 1 fi +if [ "$extension" == ".zip" ]; then + tool="unzip" +else + tool="tar" +fi + latest_release=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') if [ -z "$latest_release" ]; then @@ -59,14 +65,24 @@ for bin in "${bins[@]}"; do exit 1 fi - if ! command -v tar &>/dev/null; then - echo "Error: 'tar' command is required to extract the binary." - exit 1 + if [ "$tool" == "unzip" ]; then + if ! command -v unzip &>/dev/null; then + echo "Error: 'unzip' command is required to extract the binary." + exit 1 + fi + + echo "Unzipping $bin..." + unzip -o "$archive_path" -d "$bin_dir" + else + if ! command -v tar &>/dev/null; then + echo "Error: 'tar' command is required to extract the binary." + exit 1 + fi + + echo "Extracting $bin..." + tar -xzf "$archive_path" -C "$bin_dir" fi - echo "Extracting $bin..." - tar -xzf "$archive_path" -C "$bin_dir" - if [ ! -f "$exe" ]; then echo "Error: Failed to extract $bin from the archive." exit 1 From 0be222b279c0868bd05f73033da99a9bb8a0eb50 Mon Sep 17 00:00:00 2001 From: jesperkha Date: Sun, 9 Mar 2025 21:49:31 +0100 Subject: [PATCH 2/6] Update README for changes in v1.10.0 --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fcbe31..6f4c148 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,23 @@ ## Install +### CLI app + Copy and run the following command. cenv will be put in `$HOME/.local/bin`. Make sure that the directory is in your `$PATH`. ```sh curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bash ``` -Once installed, you can self-update with `cenv-install`. +Once installed, you can self-update with `cenv upgrade` or the `cenv-install` binary (separate download). + +### Go package + +You can also use cenv as a single-util package. See [the package source](cenv.go). + +```sh +go get github.com/echo-webkom/cenv +``` ## Use From d619c512efe3cec19732b80c0dfbcb75755f61fe Mon Sep 17 00:00:00 2001 From: jesperkha Date: Sun, 9 Mar 2025 21:52:54 +0100 Subject: [PATCH 3/6] Update build instructions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6f4c148..72778d5 100644 --- a/README.md +++ b/README.md @@ -79,14 +79,14 @@ cenv fix ## Building -To build the project, you need to have Go installed. Run the following command to build the project: +To build the project, you need to have Go installed. Run the following command to build the project (make sure the `bin` directory exists): ```sh -go build -o cenv cmd/cenv/main.go +go build -o bin/cenv app/main.go ``` If you want to overwrite the `Version` variable in `main.go` you have add the following flags: ```sh -go build -o bin/cenv -ldflags "-X 'github.com/echo-webkom/cenv/cmd.Version='" main.go +go build -o bin/cenv -ldflags "-X 'github.com/echo-webkom/cenv/cmd.Version='" app/main.go ``` From 146dbee95fbe7567a8b69796dde276528303510e Mon Sep 17 00:00:00 2001 From: jesperkha Date: Sun, 16 Mar 2025 15:32:12 +0100 Subject: [PATCH 4/6] Fix permission issue for fix command --- cenv/cenv.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cenv/cenv.go b/cenv/cenv.go index c396eac..8b1c70d 100644 --- a/cenv/cenv.go +++ b/cenv/cenv.go @@ -2,7 +2,6 @@ package cenv import ( "fmt" - "io/fs" "os" "strings" "time" @@ -93,7 +92,7 @@ func Fix(envPath, schemaPath string) error { file.WriteByte('\n') } - if err := os.WriteFile(envPath, []byte(file.String()), fs.FileMode(os.O_WRONLY)); err != nil { + if err := os.WriteFile(envPath, []byte(file.String()), 0666); err != nil { return err } From f542d7eb085dd61114ed37a3a2f1c94aacdf93df Mon Sep 17 00:00:00 2001 From: jesperkha Date: Sun, 16 Mar 2025 15:45:04 +0100 Subject: [PATCH 5/6] Remove obsolete cenv-install, update workflow to match --- .github/publishing.md | 3 ++- .github/workflows/build.yaml | 9 --------- README.md | 4 +++- cenv-install/main.go | 19 ------------------- cmd/version.go | 8 ++++---- 5 files changed, 9 insertions(+), 34 deletions(-) delete mode 100644 cenv-install/main.go diff --git a/.github/publishing.md b/.github/publishing.md index 5d9ce39..46550fb 100644 --- a/.github/publishing.md +++ b/.github/publishing.md @@ -1,4 +1,4 @@ -# How to publish a new package +# How to publish a new version 1. Tag your commit @@ -12,3 +12,4 @@ git push ``` +1. Create a new release in the repo with the title being the release version (eg. `v.1.5.2`). The workflow will start automatically when the release is created. diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0331d10..9e86f44 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -34,12 +34,3 @@ jobs: binary_name: cenv ldflags: -X 'github.com/echo-webkom/cenv/cmd.Version=${{ github.event.release.tag_name }}' project_path: ./app - - - name: 🚀 Build cenv-install - uses: wangyoucao577/go-release-action@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - binary_name: cenv-install - project_path: ./cenv-install diff --git a/README.md b/README.md index 72778d5..c46c8a4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ **Keeping your sanity in check by validating your `.env` files!** +**Latest release ➜** +
@@ -22,7 +24,7 @@ Copy and run the following command. cenv will be put in `$HOME/.local/bin`. Make curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bash ``` -Once installed, you can self-update with `cenv upgrade` or the `cenv-install` binary (separate download). +Once installed, you can self-update with `cenv upgrade`. ### Go package diff --git a/cenv-install/main.go b/cenv-install/main.go deleted file mode 100644 index 75aa676..0000000 --- a/cenv-install/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" -) - -func main() { - cmd := exec.Command("bash", "-c", "curl -fsSL https://raw.githubusercontent.com/echo-webkom/cenv/refs/heads/main/install.sh | bash") - fmt.Println("Installing latest release...") - - if _, err := cmd.Output(); err != nil { - fmt.Println(err) - return - } - - fmt.Println("Done") -} - diff --git a/cmd/version.go b/cmd/version.go index 8821c00..d198bba 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,6 +6,8 @@ import ( "os" "strings" + "slices" + "github.com/fatih/color" ) @@ -16,10 +18,8 @@ func checkIfLatestVersion() { return } - for _, arg := range os.Args { - if arg == "--skip-version" { - return - } + if slices.Contains(os.Args, "--skip-version") { + return } resp, err := http.Get("https://api.github.com/repos/echo-webkom/cenv/releases/latest") From 8cc80fa6e95ade85c245e95e8495b7d1cf95d76c Mon Sep 17 00:00:00 2001 From: jesperkha Date: Sun, 16 Mar 2025 15:57:07 +0100 Subject: [PATCH 6/6] Remove cenv-install --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index c8a8431..e5c8754 100644 --- a/install.sh +++ b/install.sh @@ -48,7 +48,7 @@ fi bin_dir="$HOME/.local/bin" mkdir -p "$bin_dir" -bins=("cenv" "cenv-install") +bins=("cenv") for bin in "${bins[@]}"; do binary_name="${bin}-${latest_release}-${target}${extension}" @@ -93,4 +93,4 @@ for bin in "${bins[@]}"; do done echo "Installation completed successfully!" -echo "Run 'cenv --help' or 'cenv-install --help' to get started." +echo "Run 'cenv --help' to get started"