Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from openmeterio/improve-release
Browse files Browse the repository at this point in the history
ci: improve binary archive
  • Loading branch information
sagikazarmark authored Jan 23, 2024
2 parents 597166d + 07fa85d commit 32e89df
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
module: github.com/${{ github.repository }}/ci@${{ github.ref }}
args: --checkout ${{ github.ref }} ci
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.9.5"
version: "0.9.7"

build:
name: Build
Expand Down
45 changes: 14 additions & 31 deletions ci/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"path"
"strings"
"time"
)
Expand Down Expand Up @@ -89,6 +88,7 @@ func (m *Build) binary(platform Platform, version string) *File {
WithCgoDisabled().
WithSource(m.Source).
Build(GoWithSourceBuildOpts{
Name: "benthos",
Trimpath: true,
RawArgs: []string{
"-ldflags",
Expand Down Expand Up @@ -116,38 +116,21 @@ func (m *Build) binaryArchives(version string) []*File {
}

func (m *Build) binaryArchive(version string, platform Platform) *File {
binary := m.binary(platform, version)
var archiver interface {
Archive(name string, source *Directory) *File
} = dag.Archivist().TarGz()

dir := dag.Directory().
WithFile("benthos", binary).
WithFile("", m.Source.File("README.md")).
WithFile("", m.Source.File("LICENSE"))

archiveName := fmt.Sprintf("benthos_%s.tar.gz", strings.ReplaceAll(string(platform), "/", "_"))

return dag.Container().
From(alpineBaseImage).
WithWorkdir("/work").
WithMountedDirectory("/work", dir).
WithExec([]string{"tar", "-czf", archiveName, "."}).
File(path.Join("/work", archiveName))
}

func (m *Build) checksums(files []*File) *File {
return dag.Container().
From(alpineBaseImage).
WithWorkdir("/work").
With(func(c *Container) *Container {
dir := dag.Directory()

for _, file := range files {
dir = dir.WithFile("", file)
}
if strings.HasPrefix(string(platform), "windows/") {
archiver = dag.Archivist().Zip()
}

return c.WithMountedDirectory("/work", dir)
}).
WithExec([]string{"sh", "-c", "sha256sum $(ls) > checksums.txt"}).
File("/work/checksums.txt")
return archiver.Archive(
fmt.Sprintf("benthos_%s", strings.ReplaceAll(string(platform), "/", "_")),
dag.Directory().
WithFile("", m.binary(platform, version)).
WithFile("", m.Source.File("README.md")).
WithFile("", m.Source.File("LICENSE")),
)
}

func (m *Build) HelmChart(
Expand Down
7 changes: 4 additions & 3 deletions ci/dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"api/client/node/node_modules"
],
"dependencies": [
"github.com/sagikazarmark/daggerverse/archivist@493a0d97d9468d8dee23dec1f805268e940c386d",
"github.com/sagikazarmark/daggerverse/checksum@5b3e18c117fb761d645d04c69347b0e1ced73e77",
"github.com/sagikazarmark/daggerverse/gh@ef6b5bf932277ffc4b7e1ea9fd9a1c26a2780da3",
"github.com/sagikazarmark/daggerverse/go@54de323eba85e8d1154751b84a3fb7ab8e2fdd8e",
"github.com/sagikazarmark/daggerverse/go@493a0d97d9468d8dee23dec1f805268e940c386d",
"github.com/sagikazarmark/daggerverse/golangci-lint@fd0f3da52f511b9188a6f5bd44b193e3d614f0e2",
"github.com/sagikazarmark/daggerverse/helm-docs@1e4b4c1ac88f2980870d084f51f5adb33bf227a3",
"github.com/sagikazarmark/daggerverse/helm@4e48ba4471930a7b1f131f029afd4785c8a6f133",
"github.com/shykes/daggerverse/supergit@4113b803fcf4ba83b39cd464856af94656197cbf"
"github.com/sagikazarmark/daggerverse/helm@4e48ba4471930a7b1f131f029afd4785c8a6f133"
]
}
2 changes: 1 addition & 1 deletion ci/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ require (

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
github.com/vektah/gqlparser/v2 v2.5.6
)
2 changes: 1 addition & 1 deletion ci/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (m *Ci) pushImages(ctx context.Context, version string, tags []string) erro

func (m *Ci) releaseAssets(version string) []*File {
binaryArchives := m.Build().binaryArchives(version)
checksums := m.Build().checksums(binaryArchives)
checksums := dag.Checksum().Sha256().Calculate(binaryArchives)

return append(binaryArchives, checksums)
}
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32e89df

Please sign in to comment.