Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ env:

jobs:
ci:
# CI is skipped because `deliver` runs it first anyway
if: "github.ref != 'refs/heads/main'"
runs-on: "ubuntu-latest"
permissions:
contents: "read"
Expand Down
15 changes: 1 addition & 14 deletions internal/tasks/delivery/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/opensourcecorp/oscar/internal/consts"
igit "github.com/opensourcecorp/oscar/internal/git"
iprint "github.com/opensourcecorp/oscar/internal/print"
"github.com/opensourcecorp/oscar/internal/tasks/ci"
containertools "github.com/opensourcecorp/oscar/internal/tasks/tools/containers"
Expand Down Expand Up @@ -64,19 +63,7 @@ func Run(ctx context.Context) (err error) {
return fmt.Errorf("internal error setting up run info: %w", err)
}

git, err := igit.New(ctx)
if err != nil {
return err
}
iprint.Infof(run.Colors.Gray + git.String() + run.Colors.Reset)

repo, err := taskutil.NewRepo(ctx)
if err != nil {
return fmt.Errorf("getting repo composition: %w", err)
}
iprint.Infof(run.Colors.Gray + repo.String() + run.Colors.Reset)

taskMap, err := getDeliveryTaskMap(repo)
taskMap, err := getDeliveryTaskMap(run.Repo)
if err != nil {
return err
}
Expand Down
22 changes: 16 additions & 6 deletions internal/tasks/tools/go/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package gotools

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/opensourcecorp/oscar/internal/oscarcfg"
iprint "github.com/opensourcecorp/oscar/internal/print"
"github.com/opensourcecorp/oscar/internal/system"
taskutil "github.com/opensourcecorp/oscar/internal/tasks/util"
)
Expand Down Expand Up @@ -47,12 +49,12 @@ func (t ghRelease) Exec(ctx context.Context) error {
return err
}

var buildErr error
var buildErrs error
for _, src := range cfg.GetDeliverables().GetGoGithubRelease().GetBuildSources() {
buildErr = goBuild(ctx, src)
buildErrs = errors.Join(buildErrs, goBuild(ctx, src))
}
if buildErr != nil {
return err
if buildErrs != nil {
return buildErrs
}

buildDir := "build"
Expand Down Expand Up @@ -121,21 +123,29 @@ func goBuild(ctx context.Context, src string) error {
}

for _, distro := range distros {
iprint.Debugf("building for %s\n", distro)

splits := strings.Split(distro, "/")
goos := splits[0]
goarch := splits[1]

binName := filepath.Base(src)
target := filepath.Join(targetDir, fmt.Sprintf("%s-%s-%s", binName, goos, goarch))

// At the time of this writing, UPX only works for Linux, so run it accordingly
runUPX := fmt.Sprintf("upx --best %s", target)
if goos != "linux" {
runUPX = ""
}

if _, err := system.RunCommand(ctx, []string{"bash", "-c", fmt.Sprintf(`
CGO_ENABLED=0 \
GOOS=%s GOARCH=%s \
go build -ldflags '-s -w -extldflags "-static"' -o %s %s
upx --best %s`,
%s`,
goos, goarch,
target, src,
target,
runUPX,
)}); err != nil {
return fmt.Errorf("building Go binary: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion oscar.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: "0.3.0-alpha1"
version: "0.3.0-alpha2"
deliverables:
go_github_release:
build_sources:
Expand Down