Skip to content

Commit 8a18003

Browse files
authored
fix: add lints and coverage tests back + publish a container (#53)
* fix: add lints and coverage tests * fix: coverage * fix: add v2 to sed * fix: style
1 parent b9f339f commit 8a18003

File tree

18 files changed

+206
-136
lines changed

18 files changed

+206
-136
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master, main ]
5+
branches: [master, main]
66
pull_request:
7-
branches: [ master, main ]
7+
branches: [master, main]
88

99
permissions:
10+
contents: write
11+
statuses: write
1012
checks: write
13+
pull-requests: write
1114

1215
jobs:
1316
set-version:
@@ -29,7 +32,7 @@ jobs:
2932
- name: Install GitVersion
3033
uses: gittools/actions/gitversion/[email protected]
3134
with:
32-
versionSpec: '5.x'
35+
versionSpec: "5.x"
3336
- name: Set SemVer Version
3437
uses: gittools/actions/gitversion/[email protected]
3538
id: gitversion
@@ -38,6 +41,7 @@ jobs:
3841
run: |
3942
echo "REVISION -> $GITHUB_SHA"
4043
echo "VERSION -> $GITVERSION_SEMVER"
44+
4145
test:
4246
runs-on: ubuntu-latest
4347
needs: set-version
@@ -49,36 +53,36 @@ jobs:
4953
- uses: actions/checkout@v4
5054
with:
5155
fetch-depth: 1
56+
5257
- name: Install Eirctl
5358
uses: ensono/actions/[email protected]
54-
with:
55-
version: 0.7.6
59+
with:
60+
version: 0.9.3
5661
isPrerelease: false
5762

5863
- name: Run Lint
5964
run: |
60-
eirctl run pipeline lint
65+
eirctl run pipeline lints
6166
- name: Run Tests
6267
run: |
63-
eirctl run pipeline test
64-
ls -alt .coverage/out
65-
ls -lat .coverage/report-junit.xml
68+
eirctl run pipeline gha:unit:test
69+
6670
- name: Publish Junit style Test Report
6771
uses: mikepenz/action-junit-report@v4
6872
if: always() # always run even if the previous step fails
6973
with:
70-
report_paths: '**/.coverage/report-junit.xml'
74+
report_paths: "**/.coverage/report-junit.xml"
75+
7176
- name: Analyze with SonarCloud
72-
# You can pin the exact commit or the version.
73-
uses: SonarSource/[email protected]
77+
uses: SonarSource/sonarqube-scan-action@v6
7478
env:
75-
SEMVER: $SEMVER
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
77-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
79+
# Needed to get PR information
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
# Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
82+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7883
with:
79-
# Additional arguments for the sonarcloud scanner
80-
# mandatory
84+
projectBaseDir: .
8185
args: >
8286
-Dsonar.projectVersion=${{ needs.set-version.outputs.semVer }}
83-
-Dsonar.go.coverage.reportPaths=.coverage/out
84-
-Dsonar.go.tests.reportPaths=.coverage/report-junit.xml
87+
-Dsonar.working.directory=.scannerwork
88+
-Dsonar.scm.provider=git
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish Container
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Lint and Test']
6+
types:
7+
- completed
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: write
13+
packages: write
14+
15+
jobs:
16+
set-version-tag:
17+
if: ${{ github.event.workflow_run.head_branch == 'main' }}
18+
runs-on: ubuntu-24.04
19+
outputs:
20+
semVer: ${{ steps.gitversion.outputs.semVer }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
# get version
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- name: Install GitVersion
28+
uses: gittools/actions/gitversion/[email protected]
29+
with:
30+
versionSpec: '5.x'
31+
- name: Set SemVer Version
32+
uses: gittools/actions/gitversion/[email protected]
33+
id: gitversion
34+
35+
build-and-push:
36+
runs-on: ubuntu-latest
37+
needs: set-version-tag
38+
env:
39+
SEMVER: ${{ needs.set-version-tag.outputs.semVer }}
40+
steps:
41+
- name: Check out repository
42+
uses: actions/checkout@v3
43+
44+
- name: Log in to GitHub Container Registry
45+
uses: docker/login-action@v2
46+
with:
47+
registry: ghcr.io
48+
# GITHUB_TOKEN is automatically provided in GitHub Actions
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Set up QEMU (for multi-arch builds, optional)
53+
uses: docker/setup-qemu-action@v3
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Build and push Docker image
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: .
62+
push: true
63+
build-args: Version=${{ needs.set-version-tag.outputs.semVer }},Revision=${{ github.sha }}
64+
tags: |
65+
ghcr.io/ensono/eirctl:${{ needs.set-version-tag.outputs.semVer }}
66+
platforms: linux/amd64,linux/arm64 # adjust as needed

.golangci.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: "2"
2+
linters:
3+
# Default set of linters.
4+
# The value can be: `standard`, `all`, `none`, or `fast`.
5+
# Default: standard
6+
default: standard
7+
exclusions:
8+
generated: lax
9+
# Log a warning if an exclusion rule is unused.
10+
# Default: false
11+
warn-unused: true
12+
# Predefined exclusion rules.
13+
# Default: []
14+
presets:
15+
- comments
16+
- std-error-handling
17+
- common-false-positives
18+
- legacy
19+
# Excluding configuration per-path, per-linter, per-text and per-source.
20+
rules:
21+
# Exclude some linters from running on tests files.
22+
- path: _test\.go
23+
linters:
24+
- gocyclo
25+
- errcheck
26+
- dupl
27+
- gosec
28+
- ineffassign
29+
- staticcheck
30+
- unused
31+
- govet
32+
# Exclude some linters from running on examples files.
33+
- path: examples/
34+
linters:
35+
- gocyclo
36+
- errcheck
37+
- dupl
38+
- gosec
39+
- ineffassign
40+
- staticcheck
41+
- unused
42+
- govet

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG Version
2+
ARG Revision
3+
4+
FROM docker.io/golang:1-trixie AS builder
5+
6+
ARG Version=0.0.1
7+
ARG Revision=beta01
8+
9+
WORKDIR /app
10+
11+
COPY ./ /app
12+
RUN CGO_ENABLED=0 go build -mod=readonly -buildvcs=false \
13+
-ldflags="-s -w -X \"github.com/DevLabFoundry/configmanager/v2/cmd/configmanager.Version=${Version}\" -X \"github.com/DevLabFoundry/configmanager/v2/cmd/configmanager.Revision=${Revision}\" -extldflags -static" \
14+
-o bin/configmanager cmd/main.go
15+
16+
FROM docker.io/alpine:3
17+
18+
COPY --from=builder /app/bin/configmanager /usr/bin/configmanager
19+
20+
ENTRYPOINT ["configmanager"]

cmd/configmanager/fromfileinput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func newFromStrCmd(rootCmd *Root) {
4646
inside a variable to be searched for tokens.
4747
If value is a valid path it will open it if not it will accept the string as an input.
4848
e.g. -i /some/file or -i $"(cat /som/file)", are both valid input values`)
49-
fromstrCmd.MarkPersistentFlagRequired("input")
49+
_ = fromstrCmd.MarkPersistentFlagRequired("input")
5050
fromstrCmd.PersistentFlags().StringVarP(&f.path, "path", "p", "./app.env", `Path where to write out the
5151
replaced a config/secret variables. Special value of stdout can be used to return the output to stdout e.g. -p stdout,
5252
unix style output only`)

cmd/configmanager/insert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ func newInsertCmd(rootCmd *Root) {
2929
},
3030
}
3131
insertCmd.PersistentFlags().StringToStringVarP(&f.insertKv, "config-pair", "", defaultInsertKv, " token=value pair. This can be specified multiple times.")
32-
insertCmd.MarkPersistentFlagRequired("config-pair")
32+
_ = insertCmd.MarkPersistentFlagRequired("config-pair")
3333
rootCmd.Cmd.AddCommand(insertCmd)
3434
}

cmd/configmanager/retrieve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func newRetrieveCmd(rootCmd *Root) {
3535
},
3636
}
3737
retrieveCmd.PersistentFlags().StringArrayVarP(&f.tokens, "token", "t", []string{}, "Token pointing to a config/secret variable. This can be specified multiple times.")
38-
retrieveCmd.MarkPersistentFlagRequired("token")
38+
_ = retrieveCmd.MarkPersistentFlagRequired("token")
3939
retrieveCmd.PersistentFlags().StringVarP(&f.path, "path", "p", "./app.env", "Path where to write out the replaced a config/secret variables. Special value of stdout can be used to return the output to stdout e.g. -p stdout, unix style output only")
4040
rootCmd.Cmd.AddCommand(retrieveCmd)
4141
}

0 commit comments

Comments
 (0)