Skip to content

Commit 2c5266c

Browse files
committed
fix build system
1 parent 087b293 commit 2c5266c

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Set up QEMU
13-
uses: docker/setup-qemu-action@v1
13+
uses: docker/setup-qemu-action@v2
1414
- name: Set up Docker Buildx
15-
uses: docker/setup-buildx-action@v1
15+
uses: docker/setup-buildx-action@v2
1616
- name: Docker Labels
1717
id: meta
18-
uses: crazy-max/ghaction-docker-meta@v2
18+
uses: crazy-max/ghaction-docker-meta@v4
1919
with:
2020
images: cupcakearmy/autorestic
2121
tags: |
2222
type=semver,pattern={{version}}
2323
type=semver,pattern={{major}}.{{minor}}
2424
type=semver,pattern={{major}}
2525
- name: Login to DockerHub
26-
uses: docker/login-action@v1
26+
uses: docker/login-action@v2
2727
with:
2828
username: ${{ secrets.DOCKERHUB_USERNAME }}
2929
password: ${{ secrets.DOCKERHUB_TOKEN }}
3030
- name: Build and push
31-
uses: docker/build-push-action@v2
31+
uses: docker/build-push-action@v3
3232
with:
3333
platforms: linux/amd64,linux/arm64
3434
push: true
@@ -40,14 +40,9 @@ jobs:
4040
- uses: actions/checkout@v2
4141
- uses: actions/setup-go@v2
4242
with:
43-
go-version: "^1.16.3"
43+
go-version: "^1.20"
4444
- name: Build
4545
run: go run build/build.go
46-
47-
- name: Sign
48-
uses: tristan-weil/[email protected]
49-
with:
50-
path: dist/*
5146
- name: Release
5247
uses: softprops/action-gh-release@v1
5348
with:

build/build.go

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
package main
55

66
import (
7+
"crypto/md5"
8+
"crypto/sha1"
9+
"crypto/sha256"
710
"fmt"
11+
"io/ioutil"
812
"os"
913
"os/exec"
1014
"path"
@@ -31,12 +35,37 @@ type buildOptions struct {
3135
Target, Arch, Version string
3236
}
3337

34-
func build(options buildOptions, wg *sync.WaitGroup) {
35-
fmt.Printf("Building %s %s\n", options.Target, options.Arch)
38+
const (
39+
CHECKSUM_MD5 = "MD5SUMS"
40+
CHECKSUM_SHA_1 = "SHA1SUMS"
41+
CHECKSUM_SHA_256 = "SHA256SUMS"
42+
)
43+
44+
type Checksums struct {
45+
filename, md5, sha1, sha256 string
46+
}
47+
48+
func writeChecksums(checksums *[]Checksums) {
49+
FILE_MD5, _ := os.OpenFile(path.Join(DIR, CHECKSUM_MD5), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
50+
defer FILE_MD5.Close()
51+
FILE_SHA1, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_1), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
52+
defer FILE_SHA1.Close()
53+
FILE_SHA256, _ := os.OpenFile(path.Join(DIR, CHECKSUM_SHA_256), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
54+
defer FILE_SHA256.Close()
55+
56+
for _, checksum := range *checksums {
57+
fmt.Fprintf(FILE_MD5, "%s %s\n", checksum.md5, checksum.filename)
58+
fmt.Fprintf(FILE_SHA1, "%s %s\n", checksum.sha1, checksum.filename)
59+
fmt.Fprintf(FILE_SHA256, "%s %s\n", checksum.sha256, checksum.filename)
60+
}
61+
}
62+
63+
func build(options buildOptions, wg *sync.WaitGroup, checksums *[]Checksums) {
64+
defer wg.Done()
65+
66+
fmt.Printf("Building: %s %s\n", options.Target, options.Arch)
3667
out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch)
3768
out = path.Join(DIR, out)
38-
out, _ = filepath.Abs(out)
39-
fmt.Println(out)
4069

4170
// Build
4271
{
@@ -65,22 +94,39 @@ func build(options buildOptions, wg *sync.WaitGroup) {
6594
panic(err)
6695
}
6796
}
68-
wg.Done()
97+
98+
// Checksum
99+
{
100+
file := out + ".bz2"
101+
content, _ := ioutil.ReadFile(file)
102+
*checksums = append(*checksums, Checksums{
103+
filename: path.Base(file),
104+
md5: fmt.Sprintf("%x", md5.Sum(content)),
105+
sha1: fmt.Sprintf("%x", sha1.Sum(content)),
106+
sha256: fmt.Sprintf("%x", sha256.Sum256(content)),
107+
})
108+
}
109+
110+
fmt.Printf("Built: %s\n", path.Base(out))
69111
}
70112

71113
func main() {
72114
os.RemoveAll(DIR)
73115
v := internal.VERSION
116+
checksums := []Checksums{}
117+
118+
// Build async
74119
var wg sync.WaitGroup
75120
for target, archs := range targets {
76121
for _, arch := range archs {
77122
wg.Add(1)
78-
build(buildOptions{
123+
go build(buildOptions{
79124
Target: target,
80125
Arch: arch,
81126
Version: v,
82-
}, &wg)
127+
}, &wg, &checksums)
83128
}
84129
}
85130
wg.Wait()
131+
writeChecksums(&checksums)
86132
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/cupcakearmy/autorestic
22

3-
go 1.18
3+
go 1.20
44

55
require (
66
github.com/blang/semver/v4 v4.0.0

internal/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/spf13/viper"
1818
)
1919

20-
const VERSION = "1.7.6"
20+
const VERSION = "1.7.7"
2121

2222
type OptionMap map[string][]interface{}
2323
type Options map[string]OptionMap

0 commit comments

Comments
 (0)