From 241683016ca08f9382138e87d33080bd514e1836 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Fri, 1 Dec 2023 19:29:48 -0800 Subject: [PATCH] chore: adopt go-releaser for release automation --- .github/workflows/release-please.yml | 19 +++++++++ .github/workflows/release.yml | 37 +++++++++++------- .gitignore | 1 + .goreleaser.yaml | 58 ++++++++++++++++++++++++++++ Dockerfile | 11 ++++++ go.sum | 10 ----- resticui.go | 20 +++++++--- 7 files changed, 128 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/release-please.yml create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 00000000..b945d689 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,19 @@ +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v4 + with: + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} + release-type: simple diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41f48b69..68d2a7b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,10 @@ name: "tagged-release" on: push: tags: - - "v*" - workflow_dispatch: + - "*" + +permissions: + contents: write jobs: tagged-release: @@ -13,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v4 @@ -27,16 +31,23 @@ jobs: - name: Install Deps run: ./scripts/install-deps.sh - - name: Build - run: ./scripts/build-all.sh + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - uses: "marvinpinto/action-automatic-releases@latest" + - name: Upload Artifacts + uses: actions/upload-artifact@v3 with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false - files: | - LICENSE - resticui-linux-amd64 - resticui-linux-arm64 - resticui-darwin-amd64 - resticui-darwin-arm64 + name: release-artifacts + path: dist/* diff --git a/.gitignore b/.gitignore index c15bb77e..74d2b988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ resticui resticui-* +dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..7a5eba70 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,58 @@ +# 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 + - go generate ./... + - sh -c "ls && cd ./webui && npm i && npm run build" + +builds: + - main: . + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + # - windows + goarch: + - amd64 + - arm64 + hooks: + post: rice append --exec {{ .Path }} + +archives: + - format: tar.gz + 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 }} + format_overrides: + - goos: windows + format: zip + +dockers: + - image_templates: + - garethgeorge/resticweb:latest + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + github: + owner: garethgeorge + name: resticweb diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b0b867f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:alpine as gobuild +RUN mkdir /tmp-orig +COPY resticweb /resticweb +RUN /resticweb --install-deps=true + +FROM scratch +COPY --from=gobuild /root/.local/share/resticui/ /.local/share/resticui/ +COPY --from=gobuild /tmp-orig /tmp + +ENTRYPOINT ["/resticweb"] +COPY resticweb /resticweb \ No newline at end of file diff --git a/go.sum b/go.sum index 65264e55..69eb8831 100644 --- a/go.sum +++ b/go.sum @@ -46,29 +46,19 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 h1:W12Pwm4urIbRdGhMEg2NM9O3TWKjNcxQhs46V0ypf/k= google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4/go.mod h1:5RBcpGRxr25RbDzY5w+dmaqpSEvl8Gwl1x2CICf60ic= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 h1:ZcOkrmX74HbKFYnpPY8Qsw93fC29TbJXspYKaBkSXDQ= google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4/go.mod h1:k2dtGpRrbsSyKcNPKKI5sstZkrNCZwpU/ns96JoHbGg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 h1:DC7wcm+i+P1rN3Ff07vL+OndGg5OhNddHyTA+ocPqYE= google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM= google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= diff --git a/resticui.go b/resticui.go index 5a0adfa6..279c3f0c 100644 --- a/resticui.go +++ b/resticui.go @@ -3,6 +3,7 @@ package main import ( "context" "errors" + "flag" "net/http" "os" "os/signal" @@ -23,11 +24,25 @@ import ( "go.uber.org/zap/zapcore" ) +var ( + installOnly = flag.Bool("install-deps", false, "Install resticui and exit") +) + func main() { + flag.Parse() ctx := context.Background() ctx, cancel := context.WithCancel(ctx) go onterm(cancel) + resticPath, err := resticinstaller.FindOrInstallResticBinary() + if err != nil { + zap.S().Fatalf("Error finding or installing restic: %v", err) + } + + if *installOnly { + return + } + configStore := createConfigProvider() cfg, err := configStore.Get() @@ -58,11 +73,6 @@ func main() { } defer oplog.Close() - resticPath, err := resticinstaller.FindOrInstallResticBinary() - if err != nil { - zap.S().Fatalf("Error finding or installing restic: %v", err) - } - orchestrator, err := orchestrator.NewOrchestrator(resticPath, cfg, oplog) if err != nil { zap.S().Fatalf("Error creating orchestrator: %v", err)