Skip to content

Commit c127541

Browse files
authoredOct 25, 2024
Merge pull request #17 from acaloiaro/git-add-optional
Add skip-git-add flag
2 parents ab72c9e + 8bb8563 commit c127541

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed
 

‎.github/workflows/goreleaser.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ jobs:
2727
run: |
2828
git config --global user.email "actions@github.com"
2929
git config --global user.name "Github Actions"
30-
go install git.sr.ht/~jcmuller/semver-bumper@latest
31-
newTag=$(git tag --list 'v*' | semver-bumper --increment minor)
32-
buildDate=$(date --iso-8601=seconds)
33-
sed -i -e "s@BUILD_DATE = \".\+\"@BUILD_DATE = \"${buildDate/v}\"@" main.go
34-
sed -i -e "s@VERSION = \".\+\"@VERSION = \"${newTag/v}\"@" main.go
35-
sed -i -e "s@version = \".\+\"@version = \"${newTag/v}\"@" default.nix
30+
go install github.com/caarlos0/svu@latest
31+
OLD_TAG=$(svu current --strip-prefix)
32+
NEW_TAG=$(svu next --strip-prefix)
33+
[ "$OLD_TAG" == "$NEW_TAG" ] && echo "no version bump" && exit 0
34+
sed -i "s/$OLD_TAG/$NEW_TAG/g" default.nix
35+
sed -i "s/$OLD_TAG/$NEW_TAG/g" main.go
3636
git add default.nix
37-
git add main.go
38-
git commit -m "Bump release version"
39-
git tag $newTag
37+
git add main.go
38+
git commit -m "bump release version" --allow-empty
39+
git tag v$NEW_TAG
4040
git push
41-
git push --tags
41+
git push --tags
4242
- name: Run GoReleaser
4343
uses: goreleaser/goreleaser-action@v4
4444
with:

‎README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://app.gitter.im/#/room/#env-sample-sync-dev:gitter.im)
44

5-
Automatically keep `.env` files in sync with `env.sample`
5+
Automatically keep `env.sample` files in sync with `.env`
66

77
---
88

@@ -202,8 +202,10 @@ It's even possible to provide default/example values for every environment varia
202202
| Name | Description | Example | Default |
203203
| --------------- | --------------------------------------------------- | --------------------------------------------------------- | ----------------------------- |
204204
| `--env-file` | The name of the environment file | `--env-file=.secrets` | `--env-file=.env` |
205+
| `--debug` | Enable debugging | `--debug` | `false` |
206+
| `--skip-git-add` | Skip performing `git add` after syncing | `--skip-git-add` | `false` |
205207
| `--sample-file` | The name of the sample environment file | `--sample-file=secrets.example` | `--sample-file=env.sample` |
206-
| `--example` | Provide examples for specific environment variables | `--example=FOO="Example FOO" --example=BAR="Example BAR"` | `--example=VAR=<VAR>` |
208+
| `--example` | Provide examples for specific environment variables | `--example=FOO="Example FOO" --example=BAR="Example BAR"` | `--example=VAR=<VAR>` |
207209

208210
## Pre-commit Configuration Examples
209211

‎main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (e exampleFlag) Set(value string) (err error) {
4747
var (
4848
examplesFlag = make(exampleFlag)
4949
debugFlag bool
50+
skipGitAddFlag bool
5051
envFileFlag string
51-
logLevel = slog.LevelInfo
5252
sampleFileFlag string
5353
versionFlag bool
5454
)
@@ -57,6 +57,7 @@ func init() {
5757
flag.StringVar(&envFileFlag, "env-file", ".env", "set the path to your env file: ess -env-file=.env_file [sync|install]")
5858
flag.StringVar(&sampleFileFlag, "sample-file", "env.sample", "set the path to your sample file: ess -sample-file=env_var.sample [sync|install]")
5959
flag.BoolVar(&debugFlag, "debug", false, "print debug logs: ess --debug [sync|install]")
60+
flag.BoolVar(&skipGitAddFlag, "skip-git-add", false, "skip doing 'git add' on generated sample file after sync")
6061
flag.Var(examplesFlag, "example", "set example values for samples: ess --example=BAR=\"my bar value\" [sync|install]")
6162
flag.BoolVar(&versionFlag, "version", false, "print the current ess version: ess --version")
6263

@@ -92,6 +93,11 @@ func main() {
9293
switch command {
9394
case "sync":
9495
sync(projectPath)
96+
97+
if skipGitAddFlag {
98+
return
99+
}
100+
95101
cmd := exec.Command("git", "add", filepath.Join(projectPath, sampleFileFlag))
96102
slog.Debug("running git command", "args", cmd.Args)
97103
err := cmd.Run()

0 commit comments

Comments
 (0)