Skip to content

Commit

Permalink
fix build system
Browse files Browse the repository at this point in the history
  • Loading branch information
cupcakearmy committed Mar 5, 2023
1 parent 087b293 commit 2c5266c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ 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: |
type=semver,pattern={{version}}
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
Expand All @@ -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/[email protected]
with:
path: dist/*
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
60 changes: 53 additions & 7 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
package main

import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cupcakearmy/autorestic

go 1.18
go 1.20

require (
github.com/blang/semver/v4 v4.0.0
Expand Down
2 changes: 1 addition & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c5266c

Please sign in to comment.