Skip to content

Commit

Permalink
Merge pull request #276 from jumppad-labs/f-plugins
Browse files Browse the repository at this point in the history
Updated release to deploy to gemfury
  • Loading branch information
nicholasjackson committed Feb 28, 2024
2 parents 3f83783 + 704e79a commit 352d9a9
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 178 deletions.
12 changes: 10 additions & 2 deletions .dagger/dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
"sdk": "go",
"dependencies": [
{
"name": "github",
"source": "github.com/jumppad-labs/daggerverse/github@bd8d1b2e3b21195e29e9ac2f4db6938861b2c0ef"
"name": "checksum",
"source": "github.com/jumppad-labs/daggerverse/checksum@49dff54b421df9844fec87766e3710138bc98914"
},
{
"name": "brew",
"source": "github.com/jumppad-labs/daggerverse/brew@0190848d9c2a55d275de79dd97fb4d25624bbcfd"
},
{
"name": "deb",
"source": "github.com/jumppad-labs/daggerverse/deb@1151c479411222d6540dc068ec10bb8231ac8158"
},
{
"name": "github",
"source": "github.com/jumppad-labs/daggerverse/github@0db72e1659d198fe446725bf1e895cd2b60b022b"
},
{
"name": "jumppad",
"source": "github.com/jumppad-labs/daggerverse/jumppad@862ddf584a73ef19dc14e3bedbfae56cb90b4e79"
Expand Down
191 changes: 152 additions & 39 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,20 @@ func (d *JumppadCI) All(
return output, d.lastError
}

func (d *JumppadCI) getVersion(ctx context.Context, token *Secret, src *Directory) (string, string, error) {
if d.hasError() {
return "", "", d.lastError
}

cli := dag.Pipeline("get-version")

// get the latest git sha from the source
ref, err := cli.Container().
From("alpine/git").
WithDirectory("/src", src).
WithWorkdir("/src").
WithExec([]string{"rev-parse", "HEAD"}).
Stdout(ctx)

if err != nil {
d.lastError = err
return "", "", err
}

// make sure there is no whitespace from the output
ref = strings.TrimSpace(ref)
log.Info("github reference", "sha", ref)

// get the next version from the associated PR label
v, err := cli.Github().
WithToken(token).
NextVersionFromAssociatedPrlabel(ctx, owner, repo, ref)
func (d *JumppadCI) Release(ctx context.Context, src *Directory, archives *Directory, githubToken *Secret, gemfuryToken *Secret) (string, error) {
// create a new github release
version, _ := d.GithubRelease(ctx, src, archives, githubToken)

if err != nil {
d.lastError = err
return "", "", err
}
// update the brew formula at jumppad-labs/homebrew-repo
d.UpdateBrew(ctx, version, githubToken)

// if there is no version, default to 0.0.0
if v == "" {
v = "0.0.0"
}
// update the gemfury repository
d.UpdateGemFury(ctx, version, gemfuryToken, archives)

log.Info("new version", "semver", v)
// update latest version on website
d.UpdateWebsite(ctx, version, gemfuryToken)

return v, ref, nil
return version, d.lastError
}

func (d *JumppadCI) Build(ctx context.Context, src *Directory, version, sha string) (*Directory, error) {
Expand Down Expand Up @@ -260,6 +232,8 @@ func (d *JumppadCI) Archive(ctx context.Context, binaries *Directory, version st
From("alpine:latest").
WithExec([]string{"apk", "add", "zip"})

checksums := strings.Builder{}

for _, a := range archives {
outPath := strings.ReplaceAll(a.Output, "%%VERSION%%", version)
switch a.Type {
Expand All @@ -285,8 +259,19 @@ func (d *JumppadCI) Archive(ctx context.Context, binaries *Directory, version st
case "copy":
out = out.WithFile(outPath, binaries.File(a.Path))
}

// generate the checksum
cs, err := cli.Checksum().CalculateFromFile(ctx, out.File(outPath))
if err != nil {
d.lastError = fmt.Errorf("unable to generate checksum for archive: %w", err)
return nil, d.lastError
}

checksums.WriteString(fmt.Sprintf("%s %s\n", cs, outPath))
}

out = out.WithNewFile("checksums.txt", checksums.String())

return out, nil
}

Expand Down Expand Up @@ -334,7 +319,7 @@ func (d JumppadCI) SignAndNotorize(ctx context.Context, version string, archives
return out, nil
}

func (d *JumppadCI) Release(ctx context.Context, src *Directory, archives *Directory, githubToken *Secret) (string, error) {
func (d *JumppadCI) GithubRelease(ctx context.Context, src *Directory, archives *Directory, githubToken *Secret) (string, error) {
if d.hasError() {
return "", d.lastError
}
Expand Down Expand Up @@ -364,11 +349,139 @@ func (d *JumppadCI) Release(ctx context.Context, src *Directory, archives *Direc
return version, err
}

func (d *JumppadCI) UpdateBrew(ctx context.Context, version string, githubToken *Secret) error {
if d.hasError() {
return d.lastError
}

cli := dag.Pipeline("update-brew")

_, err := cli.Brew().Formula(
ctx,
"https://jumppad.dev",
"jumppad-labs/homebrew-repo",
version,
"Mr Jumppad",
"hello@jumppad.dev",
"jumppad",
githubToken,
BrewFormulaOpts{
DarwinX86Url: fmt.Sprintf("https://github.com/jumppad-labs/jumppad/releases/download/%s/jumppad_%s_darwin_x86_64.zip", version, version),
DarwinArm64Url: fmt.Sprintf("https://github.com/jumppad-labs/jumppad/releases/download/%s/jumppad_%s_darwin_arm64.zip", version, version),
LinuxX86Url: fmt.Sprintf("https://github.com/jumppad-labs/jumppad/releases/download/%s/jumppad_%s_linux_x86_64.tar.g", version, version),
LinuxArm64Url: fmt.Sprintf("https://github.com/jumppad-labs/jumppad/releases/download/%s/jumppad_%s_linux_arm64.tar.giz", version, version),
},
)

if err != nil {
d.lastError = err
}

return err
}

var gemFury = []Archive{
{Path: "/pkg/linux/amd64/jumppad.deb", Type: "copy", Output: "jumppad_%%VERSION%%_linux_x86_64.deb"},
{Path: "/pkg/linux/arm64/jumppad.deb", Type: "copy", Output: "jumppad_%%VERSION%%_linux_arm64.deb"},
}

func (d *JumppadCI) UpdateGemFury(ctx context.Context, version string, gemFuryToken *Secret, archives *Directory) error {
cli := dag.Pipeline("update-gem-fury")

tkn, _ := gemFuryToken.Plaintext(ctx)
url := fmt.Sprintf("https://%s@push.fury.io/jumppad/", tkn)

for _, a := range gemFury {
output := strings.Replace(a.Output, "%%VERSION%%", version, 1)

_, err := cli.Container().
From("curlimages/curl:latest").
WithFile(output, archives.File(output)).
WithExec([]string{"-F", fmt.Sprintf("package=@%s", output), url}).
Sync(ctx)

if err != nil {
d.lastError = err
return err
}
}

return nil
}

func (d *JumppadCI) UpdateWebsite(ctx context.Context, version string, githubToken *Secret) error {
cli := dag.Pipeline("update-website")

f := cli.Directory().WithNewFile("version", version).File("version")

_, err := cli.Github().
WithToken(githubToken).
CommitFile(
ctx,
"jumppad-labs", "jumppad-labs.github.io",
"Mr Jumppad", "hello@jumppad.dev",
"./public/latest",
fmt.Sprintf("Update latest version: %s", version),
f,
)

if err != nil {
d.lastError = fmt.Errorf("failed to update website: %w", err)
return d.lastError
}

return nil
}

func (d *JumppadCI) WithGoCache(cache *CacheVolume) *JumppadCI {
d.goCacheVolume = cache
return d
}

func (d *JumppadCI) getVersion(ctx context.Context, token *Secret, src *Directory) (string, string, error) {
if d.hasError() {
return "", "", d.lastError
}

cli := dag.Pipeline("get-version")

// get the latest git sha from the source
ref, err := cli.Container().
From("alpine/git").
WithDirectory("/src", src).
WithWorkdir("/src").
WithExec([]string{"rev-parse", "HEAD"}).
Stdout(ctx)

if err != nil {
d.lastError = err
return "", "", err
}

// make sure there is no whitespace from the output
ref = strings.TrimSpace(ref)
log.Info("github reference", "sha", ref)

// get the next version from the associated PR label
v, err := cli.Github().
WithToken(token).
NextVersionFromAssociatedPrlabel(ctx, owner, repo, ref)

if err != nil {
d.lastError = err
return "", "", err
}

// if there is no version, default to 0.0.0
if v == "" {
v = "0.0.0"
}

log.Info("new version", "semver", v)

return v, ref, nil
}

func (d *JumppadCI) goCache() *CacheVolume {
if d.goCacheVolume == nil {
d.goCacheVolume = dag.CacheVolume("go-cache")
Expand Down

0 comments on commit 352d9a9

Please sign in to comment.