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 4fcbe31..c46c8a4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ **Keeping your sanity in check by validating your `.env` files!** +**Latest release ➜** +
@@ -14,13 +16,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`. + +### 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 @@ -69,14 +81,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 ``` 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/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 } 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") diff --git a/install.sh b/install.sh index 56f0b11..e5c8754 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 @@ -42,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}" @@ -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 @@ -77,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"