diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b39c71a..43258ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Main on: push: tags: - - "v*.*.*" + - 'v*.*.*' jobs: docker: @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "^1.20" + go-version: '^1.21' - name: Build run: go run build/build.go - name: Release diff --git a/Dockerfile b/Dockerfile index 1d3f8a8..a7b91bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20-alpine as builder +FROM golang:1.22-alpine as builder WORKDIR /app COPY go.* . @@ -6,8 +6,8 @@ RUN go mod download COPY . . RUN go build -FROM restic/restic:0.16.0 -RUN apk add --no-cache rclone bash docker-cli +FROM restic/restic:0.16.4 +RUN apk add --no-cache rclone bash curl docker-cli COPY --from=builder /app/autorestic /usr/bin/autorestic ENTRYPOINT [] CMD [ "autorestic" ] diff --git a/cmd/root.go b/cmd/root.go index fd367a1..3da9e25 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -59,24 +59,7 @@ func initConfig() { os.Exit(1) } } else { - configPaths := []string{"."} - - // Home - if home, err := homedir.Dir(); err == nil { - configPaths = append(configPaths, home) - } - - // XDG_CONFIG_HOME - { - prefix, found := os.LookupEnv("XDG_CONFIG_HOME") - if !found { - if home, err := homedir.Dir(); err != nil { - prefix = filepath.Join(home, ".config") - } - } - xdgConfig := filepath.Join(prefix, "autorestic") - configPaths = append(configPaths, xdgConfig) - } + configPaths := getConfigPaths() for _, cfgPath := range configPaths { viper.AddConfigPath(cfgPath) } @@ -88,3 +71,22 @@ func initConfig() { viper.AutomaticEnv() } } + +func getConfigPaths() []string { + result := []string{"."} + if home, err := homedir.Dir(); err == nil { + result = append(result, home) + } + + { + xdgConfigHome, found := os.LookupEnv("XDG_CONFIG_HOME") + if !found { + if home, err := homedir.Dir(); err == nil { + xdgConfigHome = filepath.Join(home, ".config") + } + } + xdgConfig := filepath.Join(xdgConfigHome, "autorestic") + result = append(result, xdgConfig) + } + return result +} diff --git a/cmd/root_test.go b/cmd/root_test.go new file mode 100644 index 0000000..feabb1b --- /dev/null +++ b/cmd/root_test.go @@ -0,0 +1,36 @@ +package cmd + +import ( + "github.com/mitchellh/go-homedir" + "os" + "path/filepath" + "slices" + "testing" +) + +const xdgConfigHome = "XDG_CONFIG_HOME" + +func assertContains(t *testing.T, array []string, element string) { + if !slices.Contains(array, element) { + t.Errorf("Expected %s to be contained in %s", element, array) + } +} + +func TestConfigResolving(t *testing.T) { + t.Run("~/.config/autorestic is used if XDG_CONFIG_HOME is not set", func(t *testing.T) { + // Override env using testing so that env gets restored after test + t.Setenv(xdgConfigHome, "") + _ = os.Unsetenv("XDG_CONFIG_HOME") + configPaths := getConfigPaths() + homeDir, _ := homedir.Dir() + expectedConfigPath := filepath.Join(homeDir, ".config/autorestic") + assertContains(t, configPaths, expectedConfigPath) + }) + + t.Run("XDG_CONFIG_HOME is respected if set", func(t *testing.T) { + t.Setenv(xdgConfigHome, "/foo/bar") + + configPaths := getConfigPaths() + assertContains(t, configPaths, filepath.Join("/", "foo", "bar", "autorestic")) + }) +} diff --git a/docs/pages/cli/forget.md b/docs/pages/cli/forget.md index e3d9f6f..29e7d69 100644 --- a/docs/pages/cli/forget.md +++ b/docs/pages/cli/forget.md @@ -4,7 +4,7 @@ autorestic forget [-l, --location] [-a, --all] [--dry-run] [--prune] ``` -This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/forget). +This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/options/forget). The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data. diff --git a/docs/pages/config.md b/docs/pages/config.md index 749fd6c..ce5aec5 100644 --- a/docs/pages/config.md +++ b/docs/pages/config.md @@ -2,10 +2,11 @@ ## Path -By default autorestic searches for a `.autorestic.yml` file in the current directory and your home folder. +By default autorestic searches for a `.autorestic.yml` file in the current directory, your home folder and your XDG config folder (`~/.config/` by default): - `./.autorestic.yml` - `~/.autorestic.yml` +- `~/.config/autorestic/.autorestic.yml` You can also specify a custom file with the `-c path/to/some/config.yml` diff --git a/docs/pages/installation.md b/docs/pages/installation.md index 244d5c8..21952be 100644 --- a/docs/pages/installation.md +++ b/docs/pages/installation.md @@ -30,4 +30,4 @@ Fedora users can install the [autorestic](https://src.fedoraproject.org/rpms/aut ### AUR -~~If you are on Arch there is an [AUR Package](https://aur.archlinux.org/packages/autorestic-bin/) (looking for maintainers).~~ - Deprecated +If you are on Arch there is an [AUR Package](https://aur.archlinux.org/packages/autorestic-bin/) diff --git a/go.mod b/go.mod index 98000f5..7c6bfdc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cupcakearmy/autorestic -go 1.20 +go 1.21 require ( github.com/blang/semver/v4 v4.0.0 diff --git a/internal/backend.go b/internal/backend.go index 1742fda..3241d2b 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -143,6 +143,7 @@ func (b Backend) Exec(args []string) error { return err } options := ExecuteOptions{Envs: env} + args = append(args, combineBackendOptions("exec", b)...) _, out, err := ExecuteResticCommand(options, args...) if err != nil { colors.Error.Println(out) diff --git a/internal/config.go b/internal/config.go index 3d8eac4..46b7956 100644 --- a/internal/config.go +++ b/internal/config.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.7.9" +const VERSION = "1.7.11" type OptionMap map[string][]interface{} type Options map[string]OptionMap diff --git a/main.go b/main.go index 66b47bf..ae644c3 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,