Skip to content

Commit ad76826

Browse files
committed
ref: replace extendio.i18n with li18ngo (#226)
1 parent 6ae7817 commit ad76826

28 files changed

+189
-81
lines changed

.github/workflows/ci-workflow.yml

+40-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Pixa Continuous Integration
2+
23
on:
34
push:
45

@@ -7,43 +8,68 @@ jobs:
78
name: lint
89
runs-on: ubuntu-latest
910
steps:
10-
- uses: actions/setup-go@v3
11+
- uses: actions/setup-go@v4
1112
with:
12-
go-version: 1.22
13+
go-version: 1.23
1314
- uses: actions/checkout@v3
1415
- name: golangci-lint
15-
uses: golangci/golangci-lint-action@v4
16+
uses: golangci/golangci-lint-action@v3
1617
with:
17-
version: v1.56.2
18+
version: v1.60.3
1819
args: --verbose
1920

2021
test:
2122
strategy:
2223
matrix:
23-
go-version: [1.22]
24+
go-version: [1.23]
2425
platform: [ubuntu-latest, macos-latest]
2526

2627
runs-on: ${{ matrix.platform }}
2728

29+
env:
30+
COVER_DIR: ${{ github.workspace }}/coverage
31+
COVER_FILE: coverage.out
32+
COVER_OUT_PATH: ${{ github.workspace }}/coverage/coverage.out
33+
COVER_HTML_PATH: ${{ github.workspace }}/coverage/coverage.html
34+
GINKGO_REPORT: ginkgo.report
35+
2836
steps:
2937
- name: Install Go
30-
uses: actions/setup-go@v3
38+
uses: actions/setup-go@v5
3139
with:
3240
go-version: ${{ matrix.go-version }}
3341

3442
- name: Install goveralls
3543
run: go install github.com/mattn/goveralls@latest
3644

45+
- name: Install ginkgo
46+
run: go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.2
47+
3748
- name: Checkout code
38-
uses: actions/checkout@v3
49+
uses: actions/checkout@v4
3950

40-
- run: go test -v -coverprofile=coverage.out ./...
51+
- name: Ensure coverage directory exists
52+
run: |
53+
mkdir -p ${{ github.workspace }}/coverage
54+
55+
- name: Run tests and generate coverage profile with Ginkgo
56+
run: |
57+
ginkgo run -r -json-report {{env.GINKGO_REPORT}} -coverpkg=./... -coverprofile=coverage.out
4158
42-
- uses: shogo82148/actions-goveralls@v1
59+
- name: Apply coverage exclusions
60+
run: |
61+
${{ github.workspace }}/scripts/apply-coverage-exclusions.sh
62+
63+
- name: Check coverage directory contents
64+
run: |
65+
echo "Contents of ${{ github.workspace }}/coverage:"
66+
ls -la ${{ github.workspace }}/coverage
67+
68+
- name: Generate HTML coverage report
69+
run: |
70+
go tool cover -html=coverage.out -o ${{ github.workspace }}/coverage/coverage.html
71+
72+
- name: Upload coverage to Coveralls
73+
uses: shogo82148/actions-goveralls@v1
4374
with:
4475
path-to-profile: coverage.out
45-
46-
- name: Send coverage
47-
env:
48-
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
run: goveralls -coverprofile=coverage.out -service=github

.golangci.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ linters-settings:
1212
- performance
1313
- style
1414
govet:
15-
check-shadowing: true
15+
shadow: true
1616
disable:
1717
- fieldalignment # too strict
1818

1919
nolintlint:
20-
require-explanation: true
20+
require-explanation: false
2121
require-specific: true
22-
2322
linters:
2423
disable-all: true
2524
enable:
@@ -29,22 +28,22 @@ linters:
2928
# it can be re-enabled.
3029
# https://github.com/OpenPeeDeeP/depguard#example-configs
3130
# - depguard
31+
- copyloopvar
3232
- dogsled
3333
# - dupl
3434
- errcheck
35-
- exportloopref
3635
- exhaustive
3736
- goconst
3837
- gocritic
3938
- gofmt
4039
- goimports
41-
- gomnd
4240
- gocyclo
4341
- gosec
4442
- gosimple
4543
- govet
4644
- ineffassign
4745
- misspell
46+
- mnd
4847
- nolintlint
4948
- nakedret
5049
- prealloc
@@ -70,4 +69,4 @@ issues:
7069

7170
run:
7271
issues-exit-code: 1
73-
timeout: 5m
72+
timeout: "5m"

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"cmocks",
1919
"cobrass",
2020
"configurator",
21+
"copyloopvar",
22+
"coverpkg",
23+
"coverprofile",
2124
"cubiest",
2225
"deadcode",
2326
"deepcopy",

Taskfile.yml

+29-1
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,38 @@ tasks:
225225

226226
# === coverage =============================================
227227

228-
cover:
228+
cover-clean:
229+
cmds:
230+
- rm -rf ./coverage
231+
232+
cover-publish:
229233
cmds:
230234
- goveralls -repotoken {{.COVERALLS_TOKEN}}
231235

236+
cover-setup:
237+
cmds:
238+
- mkdir -p ./coverage
239+
240+
cover-ginkgo:
241+
cmds:
242+
- ginkgo run -r -json-report {{.GINKGO_REPORT}} -coverpkg=./... -coverprofile={{.COVER_FILE}} --output-dir {{.COVER_DIR}}
243+
244+
cover-show:
245+
cmds:
246+
- open {{.COVER_HTML_PATH}}
247+
248+
cover-exclude:
249+
cmds:
250+
- ./scripts/apply-coverage-exclusions.sh
251+
252+
cover:
253+
cmds:
254+
- task: cover-setup
255+
- task: cover-ginkgo
256+
- task: cover-exclude
257+
- go tool cover -html=./coverage.out -o {{.COVER_HTML_PATH}}
258+
- open {{.COVER_HTML_PATH}}
259+
232260
# === i18n =================================================
233261

234262
clear:

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/snivilised/pixa
22

3-
go 1.22
3+
go 1.23.0
44

55
require (
66
github.com/charmbracelet/bubbletea v1.1.1
@@ -11,6 +11,7 @@ require (
1111
github.com/pkg/errors v0.9.1
1212
github.com/samber/lo v1.47.0
1313
github.com/snivilised/extendio v0.7.0
14+
github.com/snivilised/li18ngo v0.1.4
1415
github.com/snivilised/lorax v0.5.2
1516
github.com/spf13/cobra v1.8.1
1617
github.com/spf13/viper v1.18.2

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ github.com/snivilised/cobrass v0.4.5 h1:NeU/NwuOuJzotqa4JwnqGqbV1fs1SjB6GF53sXFO
125125
github.com/snivilised/cobrass v0.4.5/go.mod h1:hGVu/zjWVG3tRKo3P0tjelm5S44vMTa/w29ygnvi+lY=
126126
github.com/snivilised/extendio v0.7.0 h1:MY6w9qCK5wVEvP2WpMT5ywJwpDJe97WHDGuwrsTLpek=
127127
github.com/snivilised/extendio v0.7.0/go.mod h1:l8MwJOy9ojMQYJrSKRbQS3WfDylevnRtBp/zwAmFEKc=
128+
github.com/snivilised/li18ngo v0.1.4 h1:y6EECoVFpmkud2yDEeBnMnebPmSvdrEZ/LAq1PoPctE=
129+
github.com/snivilised/li18ngo v0.1.4/go.mod h1:Or3qUhpR6AM1X51i82RtyCvORWy2/hrxY9lg1i1gFTE=
128130
github.com/snivilised/lorax v0.5.2 h1:iReIJl63tydiPSSD0YzsNQFX1CctmvMkYx0aSxoZJKo=
129131
github.com/snivilised/lorax v0.5.2/go.mod h1:7H1JPgSn4h4p8NSqfl64raacYefdm/FiFkfcZ51PVHY=
130132
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=

scripts/apply-coverage-exclusions.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Define paths relative to the root directory
4+
ROOT_DIR="$(git rev-parse --show-toplevel)"
5+
COVERAGE_FILE="$ROOT_DIR/coverage.out"
6+
EXCLUSIONS_FILE="$ROOT_DIR/scripts/coverage-exclusion-list.txt"
7+
8+
# Check if required files exist
9+
if [ ! -f "$COVERAGE_FILE" ]; then
10+
echo "Error: Coverage file not found at $COVERAGE_FILE"
11+
exit 1
12+
fi
13+
14+
if [ ! -f "$EXCLUSIONS_FILE" ]; then
15+
echo "Error: Exclusions file not found at $EXCLUSIONS_FILE"
16+
exit 1
17+
fi
18+
19+
# Create a temporary file
20+
TEMP_FILE=$(mktemp)
21+
22+
# Process the exclusions
23+
while IFS= read -r line || [[ -n "$line" ]]; do
24+
# Escape special characters in the line for use in sed
25+
escaped_line=$(echo "$line" | sed 's/[\/&]/\\&/g')
26+
27+
# Remove matching lines from the coverage file
28+
sed "/${escaped_line}/d" "$COVERAGE_FILE" > "$TEMP_FILE"
29+
30+
# Replace the original file with the modified content
31+
mv "$TEMP_FILE" "$COVERAGE_FILE"
32+
done < "$EXCLUSIONS_FILE"
33+
34+
echo "Coverage exclusions have been applied successfully."

scripts/coverage-exclusion-list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/snivilised/pixa/src/internal/matchers

src/app/cfg/config-runner.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/snivilised/cobrass/src/assistant/configuration"
1212
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
1313
"github.com/snivilised/extendio/collections"
14-
xi18n "github.com/snivilised/extendio/i18n"
1514
"github.com/snivilised/extendio/xfs/storage"
15+
"github.com/snivilised/li18ngo"
1616
"github.com/snivilised/pixa/src/app/proxy/common"
1717
"github.com/spf13/viper"
1818
"golang.org/x/text/language"
@@ -216,18 +216,18 @@ func (c *configRunner) handleLangSetting(config configuration.ViperConfig) {
216216
return parsedTag
217217
},
218218
func() language.Tag {
219-
return xi18n.DefaultLanguage.Get()
219+
return li18ngo.DefaultLanguage
220220
},
221221
)
222222

223-
err := xi18n.Use(func(uo *xi18n.UseOptions) {
223+
err := li18ngo.Use(func(uo *li18ngo.UseOptions) {
224224
uo.Tag = tag
225-
uo.From = xi18n.LoadFrom{
226-
Sources: xi18n.TranslationFiles{
227-
c.sourceID: xi18n.TranslationSource{
225+
uo.From = li18ngo.LoadFrom{
226+
Sources: li18ngo.TranslationFiles{
227+
c.sourceID: li18ngo.TranslationSource{
228228
Name: c.applicationName,
229229
},
230-
ci18n.CobrassSourceID: xi18n.TranslationSource{
230+
ci18n.CobrassSourceID: li18ngo.TranslationSource{
231231
Name: "cobrass",
232232
},
233233
},

src/app/cfg/config-runner_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/snivilised/cobrass/src/assistant/mocks"
1414
"github.com/snivilised/extendio/xfs/storage"
15+
"github.com/snivilised/li18ngo"
1516
"github.com/snivilised/pixa/src/app/cfg"
1617
"github.com/snivilised/pixa/src/app/proxy/common"
1718
"github.com/snivilised/pixa/src/internal/helpers"
@@ -58,7 +59,7 @@ type runnerTE struct {
5859
assert func(entry *runnerTE, runner common.ConfigRunner, err error)
5960
}
6061

61-
var _ = Describe("ConfigRunner", func() {
62+
var _ = Describe("ConfigRunner", Ordered, func() {
6263
var (
6364
repo string
6465
configPath string
@@ -67,6 +68,10 @@ var _ = Describe("ConfigRunner", func() {
6768
mock *mocks.MockViperConfig
6869
)
6970

71+
BeforeAll(func() {
72+
Expect(li18ngo.Use()).To(Succeed())
73+
})
74+
7075
BeforeEach(func() {
7176
viper.Reset()
7277
vfs = storage.UseMemFS()

src/app/command/bootstrap.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"github.com/snivilised/cobrass/src/assistant"
1717
"github.com/snivilised/cobrass/src/assistant/configuration"
1818
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
19-
xi18n "github.com/snivilised/extendio/i18n"
2019
"github.com/snivilised/extendio/xfs/storage"
2120
"github.com/snivilised/extendio/xfs/utils"
21+
"github.com/snivilised/li18ngo"
2222
"github.com/snivilised/pixa/src/app/cfg"
2323
"github.com/snivilised/pixa/src/app/plog"
2424
"github.com/snivilised/pixa/src/app/proxy"
@@ -51,7 +51,7 @@ func validatePositionalArgs(cmd *cobra.Command, args []string) error {
5151
directory := utils.ResolvePath(args[0])
5252

5353
if !utils.Exists(directory) {
54-
return xi18n.NewPathNotFoundError("shrink directory", directory)
54+
return li18ngo.NewPathNotFoundError("shrink directory", directory)
5555
}
5656

5757
return nil
@@ -125,8 +125,8 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
125125
b.Container = assistant.NewCobraContainer(
126126
&cobra.Command{
127127
Use: "main",
128-
Short: xi18n.Text(locale.RootCmdShortDescTemplData{}),
129-
Long: xi18n.Text(locale.RootCmdLongDescTemplData{}),
128+
Short: li18ngo.Text(locale.RootCmdShortDescTemplData{}),
129+
Long: li18ngo.Text(locale.RootCmdLongDescTemplData{}),
130130
Version: fmt.Sprintf("'%v'", Version),
131131
RunE: func(_ *cobra.Command, args []string) error {
132132
inputs := b.getRootInputs()
@@ -178,7 +178,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
178178

179179
func (b *Bootstrap) configure() {
180180
if err := b.OptionsInfo.Runner.Run(); err != nil {
181-
msg := xi18n.Text(locale.UsingConfigFileTemplData{
181+
msg := li18ngo.Text(locale.UsingConfigFileTemplData{
182182
ConfigFileName: b.OptionsInfo.Config.Viper.ConfigFileUsed(),
183183
})
184184

@@ -202,18 +202,18 @@ func handleLangSetting(config configuration.ViperConfig) {
202202
return parsedTag
203203
},
204204
func() language.Tag {
205-
return xi18n.DefaultLanguage.Get()
205+
return li18ngo.DefaultLanguage
206206
},
207207
)
208208

209-
err := xi18n.Use(func(uo *xi18n.UseOptions) {
209+
err := li18ngo.Use(func(uo *li18ngo.UseOptions) {
210210
uo.Tag = tag
211-
uo.From = xi18n.LoadFrom{
212-
Sources: xi18n.TranslationFiles{
213-
common.Definitions.Pixa.SourceID: xi18n.TranslationSource{
211+
uo.From = li18ngo.LoadFrom{
212+
Sources: li18ngo.TranslationFiles{
213+
common.Definitions.Pixa.SourceID: li18ngo.TranslationSource{
214214
Name: common.Definitions.Pixa.AppName,
215215
},
216-
ci18n.CobrassSourceID: xi18n.TranslationSource{
216+
ci18n.CobrassSourceID: li18ngo.TranslationSource{
217217
Name: "cobrass",
218218
},
219219
},

src/app/command/magick-cmd_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
. "github.com/onsi/gomega" //nolint:revive // foo
66

77
"github.com/snivilised/cobrass/src/assistant/configuration"
8-
xi18n "github.com/snivilised/extendio/i18n"
98
"github.com/snivilised/extendio/xfs/storage"
9+
"github.com/snivilised/li18ngo"
1010
"github.com/snivilised/pixa/src/app/command"
1111
"github.com/snivilised/pixa/src/app/proxy/common"
1212
"github.com/snivilised/pixa/src/internal/helpers"
@@ -28,7 +28,7 @@ var _ = Describe("MagickCmd", Ordered, func() {
2828
})
2929

3030
BeforeEach(func() {
31-
xi18n.ResetTx()
31+
Expect(li18ngo.Use()).To(Succeed())
3232
vfs, _ = helpers.SetupTest(
3333
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
3434
)

0 commit comments

Comments
 (0)