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
3 changes: 2 additions & 1 deletion .github/publishing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# How to publish a new package
# How to publish a new version

1. Tag your commit

Expand All @@ -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.
9 changes: 0 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

**Keeping your sanity in check by validating your `.env` files!**

**<a href="https://github.com/echo-webkom/cenv/releases/latest">Latest release ➜</a>**

</div>

<br>
Expand All @@ -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

Expand Down Expand Up @@ -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=<your-version>'" main.go
go build -o bin/cenv -ldflags "-X 'github.com/echo-webkom/cenv/cmd.Version=<your-version>'" app/main.go
```
19 changes: 0 additions & 19 deletions cenv-install/main.go

This file was deleted.

3 changes: 1 addition & 2 deletions cenv/cenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cenv

import (
"fmt"
"io/fs"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"strings"

"slices"

"github.com/fatih/color"
)

Expand All @@ -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")
Expand Down
32 changes: 24 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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
Expand All @@ -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"