Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo 🛎
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Lint Code Base 🕵🏻‍♀️
uses: super-linter/super-linter@v7
uses: super-linter/super-linter/slim@v8
env:
LINTER_RULES_PATH: /
VALIDATE_ALL_CODEBASE: false
Expand All @@ -47,20 +47,20 @@ jobs:
strategy:
matrix:
go-version:
- 1.23.6
- 1.24.7
steps:
- name: Checkout Repo 🛎
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Setup Go 🐹
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
cache: true
cache-dependency-path: go.sum

- name: Lint Go Code 🕵🏻‍♂️
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: latest
only-new-issues: false
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo 🛎
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Setup Go 🐹
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: 1.23.6
go-version: 1.24.7
cache: true
cache-dependency-path: go.sum

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ jobs:
strategy:
matrix:
go-version:
- 1.23.6
- 1.24.7
defaults:
run:
shell: bash
steps:
- name: Checkout Repo 🛎
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Setup Go 🐹
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
cache: true
Expand Down Expand Up @@ -92,14 +92,14 @@ jobs:
strategy:
matrix:
go-version:
- 1.23.6
- 1.24.7
runs-on: ubuntu-latest
steps:
- name: Checkout Repo 🛎
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Setup Go 🐹
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
cache: true
Expand Down
66 changes: 39 additions & 27 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gosec
- goconst
version: "2"
linters:
enable:
- gosec
- unconvert
- gocyclo
- goconst
- goimports
- gocritic
- govet
- gocyclo
- gosec
- lll
- revive
linters-settings:
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
enable:
- shadow
gocyclo:
# minimal code complexity to report, 30 by default
min-complexity: 15
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
- unconvert
settings:
errcheck:
check-blank: true
gocyclo:
min-complexity: 15
lll:
line-length: 120

exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- goconst
- gosec
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
14 changes: 14 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Customization options: https://goreleaser.com/customization/
version: 2
project_name: git-synchronizer
before:
hooks:
Expand Down Expand Up @@ -38,3 +39,16 @@ dockers:
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--build-arg=PROJECT_NAME={{ .ProjectName }}"
- "--platform=linux/amd64"

# Update to this config in the future.
# dockers_v2:
# - images:
# - "ghcr.io/insightsengineering/{{ .ProjectName }}"
# tags:
# - "latest"
# - "{{ .Version }}"
# labels:
# "org.opencontainers.image.created": "{{ .Date }}"
# "org.opencontainers.image.title": "{{ .ProjectName }}"
# "org.opencontainers.image.revision": "{{ .FullCommit }}"
# "org.opencontainers.image.version": "{{ .Version }}"
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM scratch
ARG PROJECT_NAME="git-synchronizer"
# Uncomment when goreleaser config is updated to dockers_v2.
# ARG TARGETPLATFORM
ENV PROJECT_NAME=${PROJECT_NAME}
COPY ${PROJECT_NAME} /
# Change to this when goreleaser config is updated to dockers_v2.
# COPY $TARGETPLATFORM/${PROJECT_NAME} /
WORKDIR /
# hadolint ignore=DL3025
ENTRYPOINT ${PROJECT_NAME}
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ help: ## Show this help menu

devdeps: ## Install development dependencies
@printf "Executing target: [$@] 🎯\n"
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v1.51.2
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v2.5.0
@which -a typex > /dev/null || go install github.com/dtgorski/typex@latest
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser@latest
@# Goreleaser v2.12 requires Go 1.25, so pin to v2.11.2 for now
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser/v2@v2.11.2
@which -a gocover-cobertura > /dev/null || go install github.com/boumenot/gocover-cobertura@latest
@which -a misspell > /dev/null || go install github.com/client9/misspell/cmd/misspell@latest
@which -a gotestdox > /dev/null || go install github.com/bitfield/gotestdox/cmd/gotestdox@latest
Expand Down Expand Up @@ -60,7 +61,7 @@ format: ## Format source code

lint: devdeps spell ## Lint source code
@printf "Executing target: [$@] 🎯\n"
@golangci-lint run --fast -c .golangci.yml
@golangci-lint run -c .golangci.yml

test: clean tidy devdeps spell ## Run unit tests and generate reports
@printf "Executing target: [$@] 🎯\n"
Expand Down
17 changes: 12 additions & 5 deletions cmd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func ListRemote(remote *git.Remote, listOptions *git.ListOptions, repository str
}

// GetBranchesAndTagsFromRemote returns list of branches and tags present in remoteName of repository.
func GetBranchesAndTagsFromRemote(repository *git.Repository, remoteName string, listOptions *git.ListOptions, sourceRepository string) ([]string, []string, error) {
func GetBranchesAndTagsFromRemote(repository *git.Repository, remoteName string, listOptions *git.ListOptions,
sourceRepository string) ([]string, []string, error) {
var branchList []string
var tagList []string
var err error
Expand Down Expand Up @@ -229,7 +230,8 @@ func GetDestinationAuth(destAuth Authentication) *githttp.BasicAuth {
}

// GitPlainClone clones git repository and is retried in case of error.
func GitPlainClone(gitDirectory string, cloneOptions *git.CloneOptions, repositoryName string) (*git.Repository, error) {
func GitPlainClone(gitDirectory string, cloneOptions *git.CloneOptions,
repositoryName string) (*git.Repository, error) {
repository, err := git.PlainClone(gitDirectory, false, cloneOptions)
if err == gittransport.ErrAuthenticationRequired {
// Terminate backoff.
Expand Down Expand Up @@ -279,7 +281,8 @@ func PushRefs(repository *git.Repository, auth *githttp.BasicAuth, refSpecString

// MirrorRepository mirrors branches and tags from source to destination. Tags and branches
// no longer present in source are removed from destination.
func MirrorRepository(messages chan MirrorStatus, source, destination string, sourceAuthentication, destinationAuthentication Authentication) {
func MirrorRepository(messages chan MirrorStatus, source, destination string,
sourceAuthentication, destinationAuthentication Authentication) {
log.Debug("Cloning ", source)
cloneStart := time.Now()
gitDirectory, err := os.MkdirTemp(localTempDirectory, "")
Expand Down Expand Up @@ -345,7 +348,9 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so

destinationAuth := GetDestinationAuth(destinationAuthentication)

destinationBranchList, destinationTagList, err := GetBranchesAndTagsFromRemote(repository, "destination", &git.ListOptions{Auth: destinationAuth}, destination)
destinationBranchList, destinationTagList, err := GetBranchesAndTagsFromRemote(
repository, "destination", &git.ListOptions{Auth: destinationAuth}, destination,
)
if err != nil {
ProcessError(err, "getting branches and tags from ", destination, &allErrors)
}
Expand All @@ -359,7 +364,9 @@ func MirrorRepository(messages chan MirrorStatus, source, destination string, so
pushBranchesBackoff.MaxElapsedTime = 2 * time.Minute
err = backoff.Retry(
func() error {
return PushRefs(repository, destinationAuth, "+"+refBranchPrefix+branch+":"+refBranchPrefix+branch, destination)
return PushRefs(
repository, destinationAuth, "+"+refBranchPrefix+branch+":"+refBranchPrefix+branch, destination,
)
},
pushBranchesBackoff,
)
Expand Down
65 changes: 30 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,79 +1,74 @@
module github.com/insightsengineering/git-synchronizer

go 1.23.0

toolchain go1.23.6
go 1.24.7

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/go-git/go-git/v5 v5.13.2
github.com/go-git/go-git/v5 v5.16.2
github.com/jamiealquiza/envy v1.1.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/spf13/cobra v1.10.1
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.11.1
go.szostok.io/version v1.2.0
)

require (
dario.cat/mergo v1.0.1 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.5 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/cyphar/filepath-securejoin v0.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/goccy/go-yaml v1.15.17 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/kevinburke/ssh_config v1.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.29.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading
Loading