Skip to content

Commit 4790038

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 4790038

14 files changed

Lines changed: 214 additions & 66 deletions

File tree

.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: 9 additions & 20 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:
@@ -27,23 +27,7 @@ jobs:
2727
run: |
2828
apt-get update && apt-get install -y jq git
2929
git config --global --add safe.directory "$GITHUB_WORKSPACE"
30-
git config user.email ${{ github.actor }}-ci@gha.org
31-
git config user.name ${{ github.actor }}
32-
- name: Install GitVersion
33-
uses: gittools/actions/gitversion/setup@v3.0.0
34-
with:
35-
versionSpec: "5.x"
36-
- name: Set SemVer Version
37-
uses: gittools/actions/gitversion/execute@v3.0.0
38-
id: gitversion
39-
40-
- name: echo VERSIONS
41-
run: |
42-
echo "REVISION -> $GITHUB_SHA"
43-
echo "VERSION -> $GITVERSION_SEMVER"
44-
45-
test:
46-
runs-on: ubuntu-latest
30+
git config user.email ${{ github.ub
4731
needs: set-version
4832
env:
4933
SEMVER: ${{ needs.set-version.outputs.semVer }}
@@ -57,12 +41,17 @@ jobs:
5741
- name: Install Eirctl
5842
uses: ensono/actions/eirctl-setup@v0.3.1
5943
with:
60-
version: 0.9.3
44+
version: 0.11.2
6145
isPrerelease: false
6246

47+
- name: Run Commit Lint
48+
run: |
49+
eirctl commit-lint
50+
6351
- name: Run Lint
6452
run: |
6553
eirctl run pipeline lints
54+
6655
- name: Run Tests
6756
run: |
6857
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 }}

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
}

eirctl.yaml

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ contexts:
1111
container:
1212
name: mirror.gcr.io/bash:5.0.18-alpine3.22
1313

14+
committed:
15+
container:
16+
name: alpine:3
17+
shell: /bin/sh
18+
shell_args: ["-c"]
19+
1420
pipelines:
21+
commit-lint:
22+
- task: lint:commits
23+
1524
gha:unit:test:
16-
- pipeline: test:unit
25+
- pipeline: test:unit
1726
env:
1827
ROOT_PKG_NAME: github.com/DevLabFoundry
1928
- task: sonar:coverage:prep
@@ -30,6 +39,26 @@ pipelines:
3039
depends_on: clean
3140

3241
tasks:
42+
lint:commits:
43+
context: committed
44+
description: Lint commit messages against Conventional Commits using committed
45+
command:
46+
- |
47+
apk add --no-cache git
48+
git config --global safe.directory '*'
49+
if [ ! -f /eirctl/.eirctl/committed ]; then
50+
echo "Downloading committed binary..."
51+
wget -qO- https://github.com/crate-ci/committed/releases/download/v1.1.11/committed-v1.1.11-x86_64-unknown-linux-musl.tar.gz \
52+
| tar xz -C /tmp
53+
install -m 755 /tmp/committed /eirctl/.eirctl/committed
54+
fi
55+
if [ -n "$GITHUB_BASE_REF" ]; then
56+
RANGE="HEAD^1..HEAD^2"
57+
else
58+
RANGE="origin/main..HEAD"
59+
fi
60+
/eirctl/.eirctl/committed $RANGE --no-merge-commit
61+
3362
show:coverage:
3463
description: Opens the current coverage viewer for the the configmanager utility.
3564
command: go tool cover -html=.coverage/out
@@ -39,7 +68,6 @@ tasks:
3968
Opens a webview with godoc running
4069
Already filters the packages to this one and enables
4170
internal/private package documentation
42-
# go install golang.org/x/tools/cmd/godoc@latest
4371
command: |
4472
open http://localhost:6060/pkg/github.com/DevLabFoundry/configmanager/v2/?m=all
4573
godoc -notes "BUG|TODO" -play -http=:6060
@@ -61,27 +89,27 @@ tasks:
6189
echo "Version: ${VERSION}"
6290
reset_context: true
6391
variations:
64-
- BUILD_GOOS: darwin
65-
BUILD_GOARCH: amd64
66-
BUILD_SUFFIX: ""
67-
- BUILD_GOOS: darwin
68-
BUILD_GOARCH: arm64
69-
BUILD_SUFFIX: ""
70-
- BUILD_GOOS: linux
71-
BUILD_GOARCH: amd64
72-
BUILD_SUFFIX: ""
73-
- BUILD_GOOS: linux
74-
BUILD_GOARCH: arm64
75-
BUILD_SUFFIX: ""
92+
# - BUILD_GOOS: darwin
93+
# BUILD_GOARCH: amd64
94+
# BUILD_SUFFIX: ""
95+
# - BUILD_GOOS: darwin
96+
# BUILD_GOARCH: arm64
97+
# BUILD_SUFFIX: ""
98+
# - BUILD_GOOS: linux
99+
# BUILD_GOARCH: amd64
100+
# BUILD_SUFFIX: ""
101+
# - BUILD_GOOS: linux
102+
# BUILD_GOARCH: arm64
103+
# BUILD_SUFFIX: ""
76104
- BUILD_GOOS: windows
77105
BUILD_GOARCH: amd64
78106
BUILD_SUFFIX: ".exe"
79-
- BUILD_GOOS: windows
80-
BUILD_GOARCH: arm64
81-
BUILD_SUFFIX: ".exe"
82-
- BUILD_GOOS: windows
83-
BUILD_GOARCH: "386"
84-
BUILD_SUFFIX: ".exe"
107+
# - BUILD_GOOS: windows
108+
# BUILD_GOARCH: arm64
109+
# BUILD_SUFFIX: ".exe"
110+
# - BUILD_GOOS: windows
111+
# BUILD_GOARCH: "386"
112+
# BUILD_SUFFIX: ".exe"
85113
required:
86114
env:
87115
- VERSION
@@ -90,7 +118,7 @@ tasks:
90118
sonar:coverage:prep:
91119
context: bash
92120
command:
93-
- |
121+
- |
94122
sed -i 's|github.com/DevLabFoundry/configmanager/v2/||g' .coverage/out
95123
echo "Coverage file first 20 lines after conversion:"
96124
head -20 .coverage/out

internal/cmdutils/cmdutils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func (c *CmdUtils) generateFromToken(tokens []string) error {
4848
pm, err := c.configManager.Retrieve(tokens)
4949
if err != nil {
5050
// return full error to terminal if no tokens were parsed
51-
if len(pm) < 1 {
51+
// or if strict mode is enabled
52+
if len(pm) < 1 || c.configManager.GeneratorConfig().Strict() {
5253
return err
5354
}
5455
c.logger.Error("%v", err)

0 commit comments

Comments
 (0)