Skip to content
Open
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv_if_exists .env
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
include:
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.23.2'
go-version: "^1.24.0"
- run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} -ldflags="-X 'main.Version=${GITHUB_REF##*/}' -X 'main.CommitHash=${GITHUB_SHA}' -X 'main.BuildTimestamp=$(date)'" ./cmd/git-backup
env:
GOOS: ${{ matrix.goos }}
Expand All @@ -59,7 +59,7 @@ jobs:
needs:
- build
name: Build Docker
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ backup/
git-backup.yml
.idea/
git-backup
.env
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ The latest version can be downloaded from the [releases page](https://github.com

## Configuration File

Example yaml Configuration:
The configuration file supports go templating to load secrets and other variables from the environment.
An example `yaml`-Configuration looks like:

```yaml
# The github section contains backup jobs for
# GitHub and GitHub Enterprise
Expand All @@ -21,7 +23,7 @@ github:
# token. Create one with the scopes:
# "read:org, repo"
# https://github.com/settings/tokens/new?scopes=repo,read:org
access_token: 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
access_token: '{{ env "GITHUB_PAT" }}'
# (optional) Back up repos you own.
# (default: true)
owned: true
Expand Down Expand Up @@ -55,7 +57,7 @@ gitlab:
# (required) The GitLab access token.
# Create one with the scopes: "api"
# https://gitlab.com/-/profile/personal_access_tokens?scopes=api&name=git-backup
access_token: glpat-6t78yuihy789uy8t768
access_token: '{{ env "GITLAB_PAT" }}'
# (optional) Back up repos you own.
# (default: true)
owned: true
Expand Down
35 changes: 33 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package git_backup

import (
"gopkg.in/yaml.v3"
"bytes"
"io"
"os"
"text/template"

"gopkg.in/yaml.v3"
)

type Config struct {
Expand Down Expand Up @@ -53,9 +56,37 @@ func LoadFile(path string) (out Config, err error) {
}

func LoadReader(reader io.Reader) (out Config, err error) {
dec := yaml.NewDecoder(reader)
data, err := io.ReadAll(reader)
if err != nil {
return
}
rendered, err := parse(string(data))
if err != nil {
return
}

dec := yaml.NewDecoder(rendered)
dec.KnownFields(true)
err = dec.Decode(&out)
out.setDefaults()
return
}

func parse(rawTemplate string) (rendered io.Reader, err error) {
fmap := template.FuncMap{
"env": os.Getenv,
}

tmpl := template.New("").Funcs(fmap).Option("missingkey=error")

tmpl, err = tmpl.Parse(rawTemplate)
if err != nil {
return
}

buf := &bytes.Buffer{}
err = tmpl.Execute(buf, nil)
rendered = bytes.NewReader(buf.Bytes())

return
}
2 changes: 1 addition & 1 deletion gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"slices"
"strings"

"github.com/xanzy/go-gitlab"
gitlab "gitlab.com/gitlab-org/api/client-go"
)

type GitLabConfig struct {
Expand Down
42 changes: 21 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
module git-backup

go 1.22.0

toolchain go1.23.2
go 1.24.0

require (
github.com/go-git/go-git/v5 v5.12.0
github.com/go-git/go-git/v5 v5.16.3
github.com/google/go-github/v43 v43.0.0
github.com/xanzy/go-gitlab v0.113.0
golang.org/x/oauth2 v0.23.0
gitlab.com/gitlab-org/api/client-go v0.157.0
golang.org/x/oauth2 v0.32.0
gopkg.in/yaml.v3 v3.0.1
)

require (
dario.cat/mergo v1.0.1 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
github.com/ProtonMail/go-crypto v1.3.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/kevinburke/ssh_config v1.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/pjbgf/sha1cd v0.5.0 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.46.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/time v0.14.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading