-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eb8faa4
Showing
13 changed files
with
804 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
build: | ||
name: Build & Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-code-dependencies-${{ hashFiles('go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-code-dependencies | ||
- run: | | ||
go vet ./... | ||
go test ./... | ||
docker_build: | ||
name: Docker build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Current | ||
uses: actions/checkout@v2 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: false | ||
tags: build:dev | ||
cache-from: type=gha | ||
|
||
version: | ||
name: Semantic versioning | ||
needs: [build, docker_build] | ||
runs-on: ubuntu-latest | ||
outputs: | ||
new_release_published: "${{ steps.semantic.outputs.new_release_published }}" | ||
new_release_version: "${{ steps.semantic.outputs.new_release_version }}" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-code-dependencies-${{ hashFiles('go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-code-dependencies | ||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v2 | ||
id: semantic | ||
with: | ||
extra_plugins: | | ||
@semantic-release/commit-analyzer | ||
@semantic-release/release-notes-generator | ||
@semantic-release/changelog | ||
@semantic-release/git | ||
@semantic-release/exec | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
binary_release: | ||
name: Binary release | ||
needs: version | ||
if: ${{ needs.version.outputs.new_release_published == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set git tag | ||
run: git tag ${{ needs.version.outputs.new_release_version }} | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
- name: Install vembed | ||
run: go install github.com/NoUseFreak/go-vembed/vembed@latest | ||
- name: Prepare vembed info | ||
run: echo "VEMBED=$(vembed)" >> $GITHUB_ENV | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_PAT }} | ||
|
||
docker_release: | ||
name: Docker release | ||
needs: version | ||
if: ${{ needs.version.outputs.new_release_published == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Current | ||
uses: actions/checkout@v2 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=ref,event=branch | ||
type=semver,pattern={{version}},value=${{ needs.version.outputs.new_release_version }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ needs.version.outputs.new_release_version }} | ||
type=semver,pattern={{major}},value=${{ needs.version.outputs.new_release_version }} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login to GHCR | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bundles | ||
repos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM golang:1.21 as builder | ||
|
||
WORKDIR /workspace | ||
COPY go.* . | ||
RUN go mod download | ||
COPY pkg pkg | ||
COPY cmd cmd | ||
RUN go test ./... \ | ||
&& CGO_ENABLED=0 GOOS=linux go build -a -o /go-git-backup cmd/git-backup | ||
|
||
|
||
# Use distroless as minimal base image to package the project | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM gcr.io/distroless/static:nonroot | ||
|
||
WORKDIR / | ||
COPY --from=builder /go-git-backup . | ||
ENTRYPOINT ["/go-git-backup"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# go-git-backup | ||
|
||
> A simple tool to backup your git repositories. | ||
go-git-backup creates backups of your git repositories. It can be used to backup your repositories to a local directory. Repositories are backed up as bundles. | ||
|
||
```bash | ||
# Restore a repository from a bundle | ||
git clone my_repo.bundle | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/stenic/go-git-backup/pkg/app" | ||
) | ||
|
||
var v string | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "git-backup", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return app.Run(cmd.Context(), app.Platform{ | ||
Name: "github", | ||
Organisation: "aspect-analytics", | ||
}) | ||
}, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
return setUpLogs(os.Stdout, v) | ||
}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
viper.SetDefault("log.level", "info") | ||
rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", viper.GetString("log.level"), "Log level (debug, info, warn, error, fatal, panic") | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func main() { | ||
Execute() | ||
} | ||
|
||
func setUpLogs(out io.Writer, level string) error { | ||
logrus.SetOutput(out) | ||
lvl, err := logrus.ParseLevel(level) | ||
if err != nil { | ||
return err | ||
} | ||
logrus.SetLevel(lvl) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module github.com/stenic/go-git-backup | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
github.com/NoUseFreak/go-parallel v0.0.0-20190604224018-2ba374bf3cf1 | ||
github.com/dustin/go-humanize v1.0.1 | ||
github.com/go-git/go-git/v5 v5.10.1 | ||
github.com/google/go-github/v57 v57.0.0 | ||
github.com/sirupsen/logrus v1.9.3 | ||
github.com/spf13/cobra v1.8.0 | ||
github.com/spf13/viper v1.18.0 | ||
golang.org/x/oauth2 v0.15.0 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect | ||
github.com/cloudflare/circl v1.3.3 // indirect | ||
github.com/cyphar/filepath-securejoin v0.2.4 // indirect | ||
github.com/emirpasic/gods v1.18.1 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | ||
github.com/go-git/go-billy/v5 v5.5.0 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/go-querystring v1.1.0 // indirect | ||
github.com/hashicorp/hcl v1.0.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/magiconair/properties v1.8.7 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/pjbgf/sha1cd v0.3.0 // indirect | ||
github.com/sagikazarmark/locafero v0.4.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sergi/go-diff v1.1.0 // indirect | ||
github.com/skeema/knownhosts v1.2.1 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.11.0 // indirect | ||
github.com/spf13/cast v1.6.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/xanzy/ssh-agent v0.3.3 // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/crypto v0.16.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/mod v0.12.0 // indirect | ||
golang.org/x/net v0.19.0 // indirect | ||
golang.org/x/sys v0.15.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.