Skip to content

Commit ba37050

Browse files
feat: implement strict flag
* Implements a strict flag for v2 * Prints out errors for failing keys or JSON path elements * Adds Commit Lint to the builds * Adds GitVersion.yaml for Conventional Commit style bumps
1 parent 4c31e5a commit ba37050

17 files changed

Lines changed: 242 additions & 55 deletions

File tree

.eirctl/.gitkeep

Whitespace-only changes.

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text eol=lf
2+
*.jpg binary
3+
*.jpeg binary
4+
*.png binary
5+
*.gif binary

.github/workflows/build.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ permissions:
1414

1515
jobs:
1616
set-version:
17-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-24.04
1818
container:
19-
image: mcr.microsoft.com/dotnet/sdk:6.0
19+
image: mcr.microsoft.com/dotnet/sdk:10.0
2020
outputs:
2121
semVer: ${{ steps.gitversion.outputs.semVer }}
2222
steps:
@@ -29,10 +29,12 @@ jobs:
2929
git config --global --add safe.directory "$GITHUB_WORKSPACE"
3030
git config user.email ${{ github.actor }}-ci@gha.org
3131
git config user.name ${{ github.actor }}
32+
3233
- name: Install GitVersion
3334
uses: gittools/actions/gitversion/setup@v3.0.0
3435
with:
3536
versionSpec: "5.x"
37+
3638
- name: Set SemVer Version
3739
uses: gittools/actions/gitversion/execute@v3.0.0
3840
id: gitversion
@@ -43,7 +45,7 @@ jobs:
4345
echo "VERSION -> $GITVERSION_SEMVER"
4446
4547
test:
46-
runs-on: ubuntu-latest
48+
runs-on: ubuntu-24.04
4749
needs: set-version
4850
env:
4951
SEMVER: ${{ needs.set-version.outputs.semVer }}
@@ -52,17 +54,22 @@ jobs:
5254
steps:
5355
- uses: actions/checkout@v4
5456
with:
55-
fetch-depth: 1
57+
fetch-depth: 0
5658

5759
- name: Install Eirctl
5860
uses: ensono/actions/eirctl-setup@v0.3.1
5961
with:
60-
version: 0.9.3
62+
version: 0.11.2
6163
isPrerelease: false
6264

65+
- name: Run Commit Lint
66+
run: |
67+
eirctl commit-lint
68+
6369
- name: Run Lint
6470
run: |
6571
eirctl run pipeline lints
72+
6673
- name: Run Tests
6774
run: |
6875
eirctl run pipeline gha:unit:test

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ permissions:
1414

1515
jobs:
1616
set-version:
17-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-24.04
1818
if: ${{ github.event.workflow_run.head_branch == 'master' && github.event.workflow_run.conclusion == 'success' }}
1919
container:
20-
image: mcr.microsoft.com/dotnet/sdk:6.0
20+
image: mcr.microsoft.com/dotnet/sdk:10.0
2121
outputs:
2222
semVer: ${{ steps.gitversion.outputs.semVer }}
2323
steps:
@@ -39,7 +39,7 @@ jobs:
3939
id: gitversion
4040

4141
release:
42-
runs-on: ubuntu-latest
42+
runs-on: ubuntu-24.04
4343
needs: set-version
4444
env:
4545
SEMVER: ${{ needs.set-version.outputs.semVer }}
@@ -50,7 +50,7 @@ jobs:
5050

5151
- name: Install Eirctl
5252
uses: ensono/actions/eirctl-setup@v0.3.1
53-
with:
53+
with:
5454
version: 0.7.6
5555
isPrerelease: false
5656

.github/workflows/release_container.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
workflows: ['Lint and Test']
66
types:
77
- completed
8-
branches:
8+
branches:
99
- main
1010

1111
permissions:
1212
contents: write
13-
packages: write
13+
packages: write
1414

1515
jobs:
1616
set-version-tag:
@@ -33,7 +33,7 @@ jobs:
3333
id: gitversion
3434

3535
build-and-push:
36-
runs-on: ubuntu-latest
36+
runs-on: ubuntu-24.04
3737
needs: set-version-tag
3838
env:
3939
SEMVER: ${{ needs.set-version-tag.outputs.semVer }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ dist
1616

1717
# local testers and
1818
local/
19+
20+
# Eirctl
21+
eirctl.env
22+
.eirctl/*
23+
!.eirctl/.gitkeep

GitVersion.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Conventional Commits versioning rules:
2+
# Major: any type with ! (e.g. feat!:, fix(scope)!:) or BREAKING CHANGE in commit footer
3+
# Minor: feat: or feat(scope):
4+
# Patch: all other types (fix:, refactor:, debug:, chore:, etc.)
5+
mode: Mainline
6+
commit-message-incrementing: Enabled
7+
major-version-bump-message: '^(\w+)(\(\w+\))?!:|BREAKING CHANGE'
8+
minor-version-bump-message: '^feat(\(\w+\))?:'
9+
patch-version-bump-message: '^(\w+)(\(\w+\))?:'

cmd/configmanager/configmanager.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020

2121
type rootCmdFlags struct {
2222
verbose bool
23+
strict bool
2324
tokenSeparator string
2425
keySeparator string
2526
enableEnvSubst bool
@@ -38,14 +39,16 @@ func NewRootCmd(logger log.ILogger) *Root { //channelOut, channelErr io.Writer
3839
Short: fmt.Sprintf("%s CLI for retrieving and inserting config or secret variables", config.SELF_NAME),
3940
Long: fmt.Sprintf(`%s CLI for retrieving config or secret variables.
4041
Using a specific tokens as an array item`, config.SELF_NAME),
41-
SilenceUsage: true,
42-
Version: fmt.Sprintf("%s-%s", Version, Revision),
42+
SilenceUsage: true,
43+
SilenceErrors: true,
44+
Version: fmt.Sprintf("%s-%s", Version, Revision),
4345
},
4446
logger: logger,
4547
rootFlags: &rootCmdFlags{},
4648
}
4749

4850
rc.Cmd.PersistentFlags().BoolVarP(&rc.rootFlags.verbose, "verbose", "v", false, "Verbosity level")
51+
rc.Cmd.PersistentFlags().BoolVar(&rc.rootFlags.strict, "strict", false, "Exit with a non-zero exit code if any provider fails")
4952
rc.Cmd.PersistentFlags().StringVarP(&rc.rootFlags.tokenSeparator, "token-separator", "s", "#", "Separator to use to mark concrete store and the key within it")
5053
rc.Cmd.PersistentFlags().StringVarP(&rc.rootFlags.keySeparator, "key-separator", "k", "|", "Separator to use to mark a key look up in a map. e.g. AWSSECRETS#/token/map|key1")
5154
rc.Cmd.PersistentFlags().BoolVarP(&rc.rootFlags.enableEnvSubst, "enable-envsubst", "e", false, "Enable envsubst on input. This will fail on any unset or empty variables")
@@ -72,7 +75,7 @@ func cmdutilsInit(rootCmd *Root, cmd *cobra.Command, path string) (*cmdutils.Cmd
7275
}
7376

7477
cm := configmanager.New(cmd.Context())
75-
cm.Config.WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithOutputPath(path).WithKeySeparator(rootCmd.rootFlags.keySeparator).WithEnvSubst(rootCmd.rootFlags.enableEnvSubst)
78+
cm.Config.WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithOutputPath(path).WithKeySeparator(rootCmd.rootFlags.keySeparator).WithEnvSubst(rootCmd.rootFlags.enableEnvSubst).WithStrict(rootCmd.rootFlags.strict)
7679
gnrtr := generator.NewGenerator(cmd.Context(), func(gv *generator.GenVars) {
7780
if rootCmd.rootFlags.verbose {
7881
rootCmd.logger.SetLevel(log.DebugLvl)

cmd/configmanager/fromfileinput.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/DevLabFoundry/configmanager/v2/internal/cmdutils"
78
"github.com/spf13/cobra"
@@ -30,9 +31,16 @@ func newFromStrCmd(rootCmd *Root) {
3031
if err != nil {
3132
return err
3233
}
33-
defer outputWriter.Close()
3434

35-
return cu.GenerateStrOut(inputReader, f.input == f.path)
35+
err = cu.GenerateStrOut(inputReader, f.input == f.path)
36+
outputWriter.Close()
37+
if err != nil {
38+
if rootCmd.rootFlags.strict && f.path != "stdout" {
39+
os.Remove(f.path)
40+
}
41+
return err
42+
}
43+
return nil
3644
},
3745
PreRunE: func(cmd *cobra.Command, args []string) error {
3846
if len(f.input) < 1 {

cmd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67

78
cfgmgr "github.com/DevLabFoundry/configmanager/v2/cmd/configmanager"
89
"github.com/DevLabFoundry/configmanager/v2/internal/log"
910
)
1011

12+
const redTerminal = "\x1b[31m%s\x1b[0m"
13+
1114
func main() {
1215
logger := log.New(os.Stderr)
1316
cmd := cfgmgr.NewRootCmd(logger)
1417
if err := cmd.Execute(context.Background()); err != nil {
18+
fmt.Fprintf(os.Stderr, redTerminal+"\n", err)
1519
os.Exit(1)
1620
}
1721
}

0 commit comments

Comments
 (0)