From 2c5266c9a0b14b85e8b78d580920ae929b9257b2 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 5 Mar 2023 17:22:03 +0100 Subject: [PATCH] fix build system --- .github/workflows/build.yml | 17 ++++------- build/build.go | 60 ++++++++++++++++++++++++++++++++----- go.mod | 2 +- internal/config.go | 2 +- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e82998f..cb15754 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,12 +10,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Docker Labels id: meta - uses: crazy-max/ghaction-docker-meta@v2 + uses: crazy-max/ghaction-docker-meta@v4 with: images: cupcakearmy/autorestic tags: | @@ -23,12 +23,12 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: platforms: linux/amd64,linux/arm64 push: true @@ -40,14 +40,9 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: "^1.16.3" + go-version: "^1.20" - name: Build run: go run build/build.go - - - name: Sign - uses: tristan-weil/ghaction-checksum-sign-artifact@v1.0.1 - with: - path: dist/* - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/build/build.go b/build/build.go index 8bf4fd6..f1df319 100644 --- a/build/build.go +++ b/build/build.go @@ -4,7 +4,11 @@ package main import ( + "crypto/md5" + "crypto/sha1" + "crypto/sha256" "fmt" + "io/ioutil" "os" "os/exec" "path" @@ -31,12 +35,37 @@ type buildOptions struct { Target, Arch, Version string } -func build(options buildOptions, wg *sync.WaitGroup) { - fmt.Printf("Building %s %s\n", options.Target, options.Arch) +const ( + CHECKSUM_MD5 = "MD5SUMS" + CHECKSUM_SHA_1 = "SHA1SUMS" + CHECKSUM_SHA_256 = "SHA256SUMS" +) + +type Checksums struct { + filename, md5, sha1, sha256 string +} + +func writeChecksums(checksums *[]Checksums) { + FILE_MD5, _ := os.OpenFile(path.Join(DIR, CHECKSUM_MD5), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) + defer FILE_MD5.Close() + FILE_SHA1, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_1), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) + defer FILE_SHA1.Close() + FILE_SHA256, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_256), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) + defer FILE_SHA256.Close() + + for _, checksum := range *checksums { + fmt.Fprintf(FILE_MD5, "%s %s\n", checksum.md5, checksum.filename) + fmt.Fprintf(FILE_SHA1, "%s %s\n", checksum.sha1, checksum.filename) + fmt.Fprintf(FILE_SHA256, "%s %s\n", checksum.sha256, checksum.filename) + } +} + +func build(options buildOptions, wg *sync.WaitGroup, checksums *[]Checksums) { + defer wg.Done() + + fmt.Printf("Building: %s %s\n", options.Target, options.Arch) out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch) out = path.Join(DIR, out) - out, _ = filepath.Abs(out) - fmt.Println(out) // Build { @@ -65,22 +94,39 @@ func build(options buildOptions, wg *sync.WaitGroup) { panic(err) } } - wg.Done() + + // Checksum + { + file := out + ".bz2" + content, _ := ioutil.ReadFile(file) + *checksums = append(*checksums, Checksums{ + filename: path.Base(file), + md5: fmt.Sprintf("%x", md5.Sum(content)), + sha1: fmt.Sprintf("%x", sha1.Sum(content)), + sha256: fmt.Sprintf("%x", sha256.Sum256(content)), + }) + } + + fmt.Printf("Built: %s\n", path.Base(out)) } func main() { os.RemoveAll(DIR) v := internal.VERSION + checksums := []Checksums{} + + // Build async var wg sync.WaitGroup for target, archs := range targets { for _, arch := range archs { wg.Add(1) - build(buildOptions{ + go build(buildOptions{ Target: target, Arch: arch, Version: v, - }, &wg) + }, &wg, &checksums) } } wg.Wait() + writeChecksums(&checksums) } diff --git a/go.mod b/go.mod index e57b8b8..98000f5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cupcakearmy/autorestic -go 1.18 +go 1.20 require ( github.com/blang/semver/v4 v4.0.0 diff --git a/internal/config.go b/internal/config.go index 6bf1e80..b66fb2f 100644 --- a/internal/config.go +++ b/internal/config.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.7.6" +const VERSION = "1.7.7" type OptionMap map[string][]interface{} type Options map[string]OptionMap