Skip to content

Commit

Permalink
Support plus in version (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
kminehart authored Oct 2, 2024
1 parent de4ba17 commit 0c4f4a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion artifacts/package_deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifacts
import (
"context"
"log/slog"
"strings"

"dagger.io/dagger"
"github.com/grafana/grafana-build/arguments"
Expand Down Expand Up @@ -54,6 +55,11 @@ func (d *Deb) Builder(ctx context.Context, opts *pipeline.ArtifactContainerOpts)
return fpm.Builder(opts.Client), nil
}

func debVersion(version string) string {
// If there is a `+security-` modifier to the version, simply use `-`
return strings.ReplaceAll(version, "+security-", "-")
}

func (d *Deb) BuildFile(ctx context.Context, builder *dagger.Container, opts *pipeline.ArtifactContainerOpts) (*dagger.File, error) {
targz, err := opts.Store.File(ctx, d.Tarball)
if err != nil {
Expand All @@ -63,7 +69,7 @@ func (d *Deb) BuildFile(ctx context.Context, builder *dagger.Container, opts *pi
return fpm.Build(builder, fpm.BuildOpts{
Name: d.Name,
Enterprise: d.Enterprise,
Version: d.Version,
Version: debVersion(d.Version),
BuildID: d.BuildID,
Distribution: d.Distribution,
PackageType: fpm.PackageTypeDeb,
Expand Down
9 changes: 8 additions & 1 deletion artifacts/package_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"fmt"
"log/slog"
"strings"

"dagger.io/dagger"
"github.com/grafana/grafana-build/arguments"
Expand Down Expand Up @@ -69,6 +70,12 @@ func (d *RPM) Builder(ctx context.Context, opts *pipeline.ArtifactContainerOpts)
return fpm.Builder(opts.Client), nil
}

func rpmVersion(version string) string {
// https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/#_snapshots
// If there's a buildmeta revision, then use that as a snapshot version
return strings.ReplaceAll(version, "+", "^")
}

func (d *RPM) BuildFile(ctx context.Context, builder *dagger.Container, opts *pipeline.ArtifactContainerOpts) (*dagger.File, error) {
targz, err := opts.Store.File(ctx, d.Tarball)
if err != nil {
Expand All @@ -78,7 +85,7 @@ func (d *RPM) BuildFile(ctx context.Context, builder *dagger.Container, opts *pi
rpm := fpm.Build(builder, fpm.BuildOpts{
Name: d.Name,
Enterprise: d.Enterprise,
Version: d.Version,
Version: rpmVersion(d.Version),
BuildID: d.BuildID,
Distribution: d.Distribution,
PackageType: fpm.PackageTypeRPM,
Expand Down
6 changes: 3 additions & 3 deletions frontend/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
// NPMPackages returns a dagger.Directory which contains the Grafana NPM packages from the grafana source code.
func NPMPackages(builder *dagger.Container, src *dagger.Directory, ersion string) *dagger.Directory {
return builder.WithExec([]string{"mkdir", "npm-packages"}).
WithEnvVariable("SHELL", "/bin/bash").
WithExec([]string{"yarn", "install", "--immutable"}).
WithExec([]string{"yarn", "run", "packages:build"}).
// TODO: We should probably start reusing the yarn pnp map if we can figure that out instead of rerunning yarn install everywhere.
WithExec([]string{"yarn", "run", "lerna", "version", ersion, "--exact", "--no-git-tag-version", "--no-push", "--force-publish", "-y"}).
WithExec([]string{"yarn", "lerna", "exec", "--no-private", "--", "yarn", "pack", "--out", fmt.Sprintf("/src/npm-packages/%%s-%v.tgz", "v"+ersion)}).
WithExec([]string{"/bin/bash", "-c", fmt.Sprintf("yarn run lerna version %s --exact --no-git-tag-version --no-push --force-publish -y && yarn lerna exec --no-private -- yarn pack --out /src/npm-packages/%%s-%v.tgz", ersion, "v"+ersion)}).
Directory("./npm-packages")
}

Expand Down

0 comments on commit 0c4f4a5

Please sign in to comment.