Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
theotow committed Aug 22, 2024
0 parents commit 1c223d8
Show file tree
Hide file tree
Showing 168 changed files with 19,260 additions and 0 deletions.
Empty file added .envrc
Empty file.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
target-branch: "next"
schedule:
interval: daily

- package-ecosystem: gomod
directory: /
target-branch: "next"
schedule:
interval: daily
108 changes: 108 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: ci

on:
push:
branches:
- "*"
pull_request:
branches:
- beta
- next

permissions:
contents: write

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: '>=1.22.6'
- uses: golangci/golangci-lint-action@v6
with:
version: latest
skip-cache: false
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: '>=1.22.6'
- run: make test
test-acceptance:
runs-on: ubuntu-latest
steps:
- run: dd if=/dev/zero of=/tmp/zfsstorage bs=524288000 count=1 # 500mb storage
- run: sudo apt-get update
- run: sudo apt install zfsutils-linux
- run: sudo zpool create zfs-pool2 /tmp/zfsstorage
- run: sudo zfs create zfs-pool2/unencrypted
- run: echo "ddddddddddddddddddddddddddddddd" > /tmp/zfs-key
- run: sudo zfs create -o encryption=on -o keylocation=file:///tmp/zfs-key -o keyformat=raw -u -v zfs-pool2/encrypted
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: '>=1.22.6'
- run: sudo make test-acceptance
release:
runs-on: ubuntu-latest
needs: [ lint, test, test-acceptance ]
if: github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/next'
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: '>=1.22.6'
- uses: cycjimmy/semantic-release-action@v4
id: semantic
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: git reset --hard && git clean -fdx
- uses: goreleaser/goreleaser-action@v6
if: steps.semantic.outputs.new_release_published == 'true'
with:
distribution: goreleaser
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/next'
needs: [ release ]
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v4
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
142 changes: 142 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
linters-settings:
whitespace:
multi-if: true
multi-func: true
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable-all: true
disable:
- fieldalignment
nolintlint:
require-explanation: true
require-specific: true
varnamelen:
min-name-length: 2
max-distance: 12
unparam:
check-exported: true
depguard:
rules:
cmd:
list-mode: strict
files:
- "**/cmd/**/*.go"
- "**/cmd/*.go"
allow:
- $all
- $gostd
- "github.com/spf13/cobra"
- "github.com/backup-blob/zfs-backup-blob/internal/driver"
- "github.com/backup-blob/zfs-backup-blob/internal/repository"
- "github.com/backup-blob/zfs-backup-blob/internal/usecase"
- "github.com/backup-blob/zfs-backup-blob/internal/domain"
- "github.com/backup-blob/zfs-backup-blob/cmd/command"
- "github.com/backup-blob/zfs-backup-blob/pkg/format"
- "github.com/golobby/container/v3"
repo:
list-mode: strict
files:
- "**/internal/repository/**/*.go"
- "**/internal/repository/*.go"
allow:
- $gostd
- "github.com/backup-blob/zfs-backup-blob/internal/domain"
- "github.com/backup-blob/zfs-backup-blob/internal/driver"
usecase:
list-mode: strict
files:
- "**/internal/usecase/**/*.go"
- "**/internal/usecase/*.go"
allow:
- $gostd
- "github.com/backup-blob/zfs-backup-blob/internal/domain"
- "github.com/backup-blob/zfs-backup-blob/internal/repository"
driver:
list-mode: strict
files:
- "**/internal/driver/**/*.go"
- "**/internal/driver/*.go"
allow:
- $gostd
- "github.com/go-playground/validator/v10"
- "github.com/backup-blob/zfs-backup-blob/internal/domain"
- "github.com/backup-blob/zfs-backup-blob/pkg"
- "github.com/aws/aws-sdk-go-v2"
- "github.com/rs/zerolog"
- "github.com/jedib0t/go-pretty/v6/table"
deny:
- pkg: "github.com/backup-blob/zfs-backup-blob/internal/repository"
desc: not allowed
- pkg: "github.com/backup-blob/zfs-backup-blob/internal/usecase"
desc: not allowed
pkg:
list-mode: strict
files:
- "**/pkg/**/*.go"
- "**/pkg/*.go"
allow:
- $all
- $gostd
- "github.com/fujiwara/shapeio"
- "github.com/docker/go-units"
deny:
- pkg: "github.com/backup-blob/zfs-backup-blob/internal"
desc: not allowed

linters:
disable-all: true
enable:
- wsl
- govet
- whitespace
- varnamelen
- unparam
- unconvert
- testpackage
- tenv
- nolintlint
- nestif
- nilerr
- maintidx
- gosec
- mnd
- goconst
- gocritic
- godot
- bodyclose
- containedctx
- depguard
- dupl
- durationcheck
- errname
- forcetypeassert
- cyclop
run:
issues-exit-code: 1
tests: false

issues:
max-same-issues: 0
exclude-files:
- ".*_test.go$"
- "pkg/fakemiddleware/fakemiddleware.go$"
exclude-dirs:
- "docs"
exclude-rules:
- linters:
- mnd
text: "Magic number: 2, in <condition> detected"

output:
show-stats: true
43 changes: 43 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
main: ./cmd

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
23 changes: 23 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"branches": [
{
"name": "main"
},
{
"name": "beta",
"channel": "alpha",
"prerelease": true
},
{
"name": "next",
"channel": "alpha",
"prerelease": true
}
],
"tagFormat": "v${version}",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/github", {"successComment": false, "failComment": false}]
]
}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.22.6
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PHONY: install lint format

install:
@asdf install
@go install github.com/google/go-licenses@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/smartystreets/goconvey@latest
@go install go.uber.org/mock/mockgen@latest
@make -C docs install

lint:
@test -z $(gofmt -l .)
@golangci-lint run ./...
@make -C docs lint

license-check:
@go-licenses report ./... --ignore github.com/backup-blob/zfs-backup-blob,golang.org/x/sys/unix

format:
@go fmt ./...

test:
@go test ./... -cover -short -count=1

coverage:
@go test ./... -cover -short -coverprofile=coverage.out
@go tool cover -html=coverage.out

test-acceptance:
@go test ./... -cover -run Integration -count=1

gen-mocks:
@mockgen -source=internal/domain/zfs.go -destination=internal/domain/mocks/zfs.go -package mocks
@mockgen -source=internal/domain/snapshot.go -destination=internal/domain/mocks/snapshot.go -package mocks
@mockgen -source=internal/domain/storage.go -destination=internal/domain/mocks/storage.go -package mocks
@mockgen -source=internal/domain/backup.go -destination=internal/domain/mocks/backup.go -package mocks
@mockgen -source=internal/domain/volume.go -destination=internal/domain/mocks/volume.go -package mocks
@mockgen -source=internal/domain/render.go -destination=internal/domain/mocks/render.go -package mocks
@mockgen -source=internal/domain/backup_state.go -destination=internal/domain/mocks/backup_state.go -package mocks
@mockgen -source=internal/domain/config/config.go -destination=internal/domain/config/mocks/config.go -package mocks_config
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Zfs-Backup-Blob

A Backup tool to back up zfs snapshots to a blob storage.
Loading

0 comments on commit 1c223d8

Please sign in to comment.