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
86 changes: 86 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Nightly

on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:

permissions:
contents: write
actions: write

jobs:
nightly:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for new commits since the last nightly
id: check
run: |
LATEST_NIGHTLY=$(git tag -l 'v*-nightly.*' --sort=-v:refname | head -1)
if [ -z "$LATEST_NIGHTLY" ]; then
echo "No previous nightly tag, proceeding"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
elif [ "$(git rev-list "${LATEST_NIGHTLY}..HEAD" --count)" -gt 0 ]; then
echo "New commits since $LATEST_NIGHTLY"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "No new commits since $LATEST_NIGHTLY, skipping"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi

- name: Compute next patch version
if: steps.check.outputs.has_changes == 'true'
id: version
run: |
# The manifest holds the last released version. A nightly must sort
# above it under semver, so tag the next patch: 0.6.0 -> v0.6.1-nightly.<date>.
RELEASED=$(jq -r '.["."]' .release-please-manifest.json)
IFS=. read -r MAJOR MINOR PATCH <<< "$RELEASED"
echo "next=${MAJOR}.${MINOR}.$((PATCH + 1))" >> "$GITHUB_OUTPUT"

- name: Create nightly tag
if: steps.check.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DATE=$(date -u +%Y%m%d)
TAG="v${{ steps.version.outputs.next }}-nightly.${DATE}"
echo "Creating tag: $TAG"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Nightly build $DATE"
git push origin "$TAG"
gh workflow run prerelease.yml --ref "$TAG"

cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete nightly releases older than 7 days
uses: actions/github-script@v7
with:
script: |
const cutoff = new Date();
cutoff.setDate(cutoff.getDate() - 7);
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner, repo: context.repo.repo, per_page: 100,
});
for (const release of releases.data) {
if (!release.tag_name.includes('-nightly.')) continue;
if (new Date(release.created_at) >= cutoff) continue;
console.log(`Deleting old nightly release: ${release.tag_name}`);
await github.rest.repos.deleteRelease({
owner: context.repo.owner, repo: context.repo.repo, release_id: release.id,
});
try {
await github.rest.git.deleteRef({
owner: context.repo.owner, repo: context.repo.repo, ref: `tags/${release.tag_name}`,
});
} catch (e) {
console.log(`Tag ${release.tag_name} already deleted`);
}
}
36 changes: 36 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pre-release

on:
push:
tags:
- 'v*-rc*'
- 'v*-beta*'
- 'v*-alpha*'
- 'v*-nightly*'
workflow_dispatch:

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,31 @@ make build
### Updating

```bash
envctl self update
envctl self update # update to the newest release on your channel
envctl self update --check # show what would be installed
envctl self update -y # skip the confirmation prompt
```

This checks GitHub for the latest release and updates in place. Use `--check` to see if an update is available without installing.
#### Release channels

`self update` follows one of three channels:

| Channel | Serves | Tag shape |
|---|---|---|
| `stable` | Official releases (default) | `v1.3.0` |
| `rc` | Release candidates | `v1.4.0-rc.1` |
| `nightly` | Daily builds from `main` | `v1.3.1-nightly.20260904` |

```bash
envctl self channel # show the current channel
envctl self channel rc # switch (asks for confirmation)
envctl self channel rc -y # switch without prompting
envctl self channel stable # back to releases
```

A newer stable release always wins. On the `rc` channel you are offered `v1.4.0` the moment it ships, even if `v1.4.0-rc.3` is what you have.

The channel is stored in `$XDG_CONFIG_HOME/envctl/config.yaml` (default `~/.config/envctl/config.yaml`), separate from the project's `.envctl.yaml`, so a team never inherits one developer's opt-in.

### Shell Completions

Expand Down Expand Up @@ -133,6 +154,17 @@ source <(envctl completion zsh)

After installing completions, restart your shell or source your profile.

### Cutting a release candidate

Release candidates are manual tags on `main` using the next version and a dotted counter. The dot matters: semver compares `rc.10` and `rc.9` numerically but `rc10` and `rc9` lexically.

```bash
git tag -a v0.9.0-rc.1 -m "v0.9.0-rc.1"
git push origin v0.9.0-rc.1
```

The `Pre-release` workflow builds the archives and publishes a GitHub prerelease. Nightlies need no action: a scheduled workflow tags `v<next patch>-nightly.<date>` whenever `main` has new commits and removes nightlies older than seven days.

## Quick Start

### 1. Initialize Configuration
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ require (
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/charmbracelet/x/exp/golden v0.0.0-20260316093931-f2fb44ab3145
github.com/sentiolabs/go-selfupdate v0.1.1
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/zalando/go-keyring v0.2.6
golang.org/x/mod v0.33.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -59,6 +59,7 @@ require (
github.com/spf13/pflag v1.0.9 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sentiolabs/go-selfupdate v0.1.1 h1:76DV5ZJyldwHtDUWD1AMH145QTNOMB7OXzrfq+RIm3E=
github.com/sentiolabs/go-selfupdate v0.1.1/go.mod h1:EWIEmMHrf3qT8mxGo4GkZSlSNvbCrAdPWDthNrgvCiA=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
Expand Down
50 changes: 50 additions & 0 deletions internal/cmd/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,56 @@ waitLoop:
assert.True(t, os.IsNotExist(statErr), "run dir must be removed after SIGINT; stderr: %s", stderr.String())
}

// TestE2E_RunSecondSIGINTStillWaitsForChild proves run releases the root
// signal handler. With the force exit still armed, the second SIGINT would
// end envctl immediately, skipping the deferred cleanup that removes the run
// directory and its secret files.
func TestE2E_RunSecondSIGINTStillWaitsForChild(t *testing.T) {
configPath, secretsPath := e2eFixture(t, "")
out := t.TempDir()

// The child ignores SIGINT and exits on its own, so envctl can only exit
// zero by waiting for it rather than by being killed.
cmd, _, stderr := envctlCmd(t, secretsPath, []string{"OUT=" + out},
"-c", configPath, "run", "--", "sh", "-c",
`trap "" INT; `+e2eChildScript(`sleep 2; exit 0`))
require.NoError(t, cmd.Start())

require.Eventually(t, func() bool {
_, err := os.Stat(filepath.Join(out, "ready"))
return err == nil
}, 15*time.Second, 20*time.Millisecond, "child never started; stderr: %s", stderr.String())

// Keep signalling until envctl exits. Two calls back to back are not
// enough, because a second instance of the same signal is coalesced away
// while the first is still pending, and the force exit would never see it.
done := make(chan error, 1)
go func() { done <- cmd.Wait() }()

resend := time.NewTicker(100 * time.Millisecond)
defer resend.Stop()
require.NoError(t, cmd.Process.Signal(syscall.SIGINT))

var waitErr error
waitLoop:
for {
select {
case waitErr = <-done:
break waitLoop
case <-resend.C:
_ = cmd.Process.Signal(syscall.SIGINT)
case <-time.After(20 * time.Second):
_ = cmd.Process.Kill()
t.Fatal("envctl never exited")
}
}
require.NoError(t, waitErr,
"envctl must wait for the child instead of exiting on a later signal; stderr: %s", stderr.String())

_, statErr := os.Stat(readMarker(t, out, "dir"))
assert.True(t, os.IsNotExist(statErr), "run dir must be removed; stderr: %s", stderr.String())
}

func TestE2E_EnvSkipsEphemeralAndNeverPrintsContent(t *testing.T) {
configPath, secretsPath := e2eFixture(t, "")
stdout, stderr, code := runEnvctl(t, secretsPath, nil, "-c", configPath, "env")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func runEdit(cmd *cobra.Command, args []string) error {
return errors.New("--item requires --vault")
}

ctx := context.Background()
ctx := commandContext(cmd)

// Load config if available
var cfg *config.Config
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/env.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"os"

"github.com/sentiolabs/envctl/internal/output"
Expand Down Expand Up @@ -34,7 +33,7 @@ func init() {
}

func runEnv(cmd *cobra.Command, args []string) error {
ctx := context.Background()
ctx := commandContext(cmd)

entries, cfg, err := loadAndBuild(ctx, cmd, nil)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package cmd

import (
"context"
"os"

"github.com/sentiolabs/envctl/internal/output"
Expand Down Expand Up @@ -44,7 +43,7 @@ func init() {

// runExport outputs secrets in the requested format.
func runExport(cmd *cobra.Command, args []string) error {
ctx := context.Background()
ctx := commandContext(cmd)

format, err := output.ParseFormat(exportFormat)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {

// runGet retrieves a single secret value by key name from the configured secrets.
func runGet(cmd *cobra.Command, args []string) error {
ctx := context.Background()
ctx := commandContext(cmd)
key := args[0]

// If --secret flag is provided, bypass config
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"os"

"github.com/sentiolabs/envctl/internal/config"
Expand Down Expand Up @@ -34,7 +33,7 @@ func init() {
}

func runList(cmd *cobra.Command, args []string) error {
ctx := context.Background()
ctx := commandContext(cmd)

// Load config
configPath, err := resolveConfigPath()
Expand Down
Loading
Loading