feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -7,11 +7,9 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/homarr-labs/homarr/tools/homarr-dev/internal/docker"
|
||||
"github.com/homarr-labs/homarr/tools/homarr-dev/internal/gh"
|
||||
)
|
||||
|
||||
func BuildCurrentImage(tag, directory string) error {
|
||||
@@ -19,11 +17,11 @@ func BuildCurrentImage(tag, directory string) error {
|
||||
}
|
||||
|
||||
func buildCurrentImage(ctx context.Context, tag, directory string, stdout, stderr io.Writer) error {
|
||||
root, revision, err := checkoutDetails(ctx, directory)
|
||||
options, err := CurrentBuildOptions(ctx, tag, directory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return docker.BuildContext(ctx, docker.BuildOptions{Context: root, Tag: tag, Source: root, Revision: revision}, stdout, stderr)
|
||||
return docker.BuildContext(ctx, options, stdout, stderr)
|
||||
}
|
||||
|
||||
func BuildPRImage(number int, tag string) error {
|
||||
@@ -31,44 +29,18 @@ func BuildPRImage(number int, tag string) error {
|
||||
}
|
||||
|
||||
func buildPRImage(ctx context.Context, number int, tag string, stdout, stderr io.Writer) error {
|
||||
if number <= 0 {
|
||||
return fmt.Errorf("PR number must be positive")
|
||||
}
|
||||
temporaryRoot, err := os.MkdirTemp("", "homarr-pr-*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("create temporary checkout: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(temporaryRoot)
|
||||
|
||||
checkout := filepath.Join(temporaryRoot, "homarr")
|
||||
clone := exec.CommandContext(ctx, "gh", prCloneArgs(checkout)...)
|
||||
clone.Stdout = stdout
|
||||
clone.Stderr = stderr
|
||||
if err := clone.Run(); err != nil {
|
||||
return fmt.Errorf("clone %s: %w", gh.Repo, err)
|
||||
}
|
||||
command := exec.CommandContext(ctx, "gh", "pr", "checkout", strconv.Itoa(number), "--detach")
|
||||
command.Dir = checkout
|
||||
command.Stdout = stdout
|
||||
command.Stderr = stderr
|
||||
if err := command.Run(); err != nil {
|
||||
return fmt.Errorf("checkout PR #%d: %w", number, err)
|
||||
}
|
||||
_, revision, err := checkoutDetails(ctx, checkout)
|
||||
options, cleanup, err := PRBuildOptions(ctx, number, tag, func(line string) {
|
||||
_, _ = fmt.Fprintln(stdout, line)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return docker.BuildContext(ctx, docker.BuildOptions{
|
||||
Context: checkout,
|
||||
Tag: tag,
|
||||
Source: fmt.Sprintf("https://github.com/%s/pull/%d", gh.Repo, number),
|
||||
Revision: revision,
|
||||
PRNumber: number,
|
||||
}, stdout, stderr)
|
||||
defer cleanup()
|
||||
return docker.BuildContext(ctx, options, stdout, stderr)
|
||||
}
|
||||
|
||||
func prCloneArgs(checkout string) []string {
|
||||
return []string{"repo", "clone", gh.Repo, checkout, "--", "--depth=1", "--filter=blob:none"}
|
||||
func prFetchArgs(repoURL, refSpec string) []string {
|
||||
return []string{"fetch", "--depth=1", repoURL, refSpec}
|
||||
}
|
||||
|
||||
func RebuildImage(image docker.Image) error {
|
||||
@@ -89,7 +61,16 @@ func RebuildImageContext(ctx context.Context, image docker.Image, stdout, stderr
|
||||
}
|
||||
|
||||
func checkoutDetails(ctx context.Context, directory string) (root string, revision string, err error) {
|
||||
rootOutput, err := exec.CommandContext(ctx, "git", "-C", directory, "rev-parse", "--show-toplevel").CombinedOutput()
|
||||
cmdRoot := exec.CommandContext(ctx, "git", "-C", directory, "rev-parse", "--show-toplevel")
|
||||
cmdRoot.Env = append(
|
||||
os.Environ(),
|
||||
"MISE_TRUSTED_CONFIG_PATHS=*",
|
||||
"MISE_QUIET=1",
|
||||
"MISE_SILENT=1",
|
||||
"MISE_YES=1",
|
||||
"MISE_OVERRIDE_CONFIG_FILENAMES=",
|
||||
)
|
||||
rootOutput, err := cmdRoot.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("find Homarr checkout: %w: %s", err, strings.TrimSpace(string(rootOutput)))
|
||||
}
|
||||
@@ -97,7 +78,16 @@ func checkoutDetails(ctx context.Context, directory string) (root string, revisi
|
||||
if _, err := os.Stat(filepath.Join(root, "Dockerfile")); err != nil {
|
||||
return "", "", fmt.Errorf("%s is not a Homarr checkout", root)
|
||||
}
|
||||
revisionOutput, err := exec.CommandContext(ctx, "git", "-C", root, "rev-parse", "HEAD").CombinedOutput()
|
||||
cmdRev := exec.CommandContext(ctx, "git", "-C", root, "rev-parse", "HEAD")
|
||||
cmdRev.Env = append(
|
||||
os.Environ(),
|
||||
"MISE_TRUSTED_CONFIG_PATHS=*",
|
||||
"MISE_QUIET=1",
|
||||
"MISE_SILENT=1",
|
||||
"MISE_YES=1",
|
||||
"MISE_OVERRIDE_CONFIG_FILENAMES=",
|
||||
)
|
||||
revisionOutput, err := cmdRev.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("read checkout revision: %w: %s", err, strings.TrimSpace(string(revisionOutput)))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/homarr-labs/homarr/tools/homarr-dev/internal/docker"
|
||||
"github.com/homarr-labs/homarr/tools/homarr-dev/internal/gh"
|
||||
)
|
||||
|
||||
// Cleanup releases a temporary checkout. It is always safe to call.
|
||||
type Cleanup func()
|
||||
|
||||
func noCleanup() {}
|
||||
|
||||
// CurrentBuildOptions describes a build of the checkout that contains
|
||||
// directory, recording the source and revision on the image so it can be
|
||||
// rebuilt later without the user remembering where it came from.
|
||||
func CurrentBuildOptions(ctx context.Context, tag, directory string) (docker.BuildOptions, error) {
|
||||
root, revision, err := checkoutDetails(ctx, directory)
|
||||
if err != nil {
|
||||
return docker.BuildOptions{}, err
|
||||
}
|
||||
return docker.BuildOptions{Context: root, Tag: tag, Source: root, Revision: revision}, nil
|
||||
}
|
||||
|
||||
// PRBuildOptions clones a pull request into a temporary checkout and describes
|
||||
// a build of it. The returned Cleanup must run once the build has finished.
|
||||
//
|
||||
// Progress is reported through log rather than written to stdout, because the
|
||||
// caller is a background job rendering inside a TUI, not a shell.
|
||||
func PRBuildOptions(ctx context.Context, number int, tag string, log func(string)) (docker.BuildOptions, Cleanup, error) {
|
||||
if number <= 0 {
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("PR number must be positive")
|
||||
}
|
||||
if log == nil {
|
||||
log = func(string) {}
|
||||
}
|
||||
temporaryRoot, err := os.MkdirTemp("", "homarr-pr-*")
|
||||
if err != nil {
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("create temporary checkout: %w", err)
|
||||
}
|
||||
cleanup := func() { _ = os.RemoveAll(temporaryRoot) }
|
||||
|
||||
checkout := filepath.Join(temporaryRoot, "homarr")
|
||||
if err := os.MkdirAll(checkout, 0o755); err != nil {
|
||||
cleanup()
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("create checkout directory: %w", err)
|
||||
}
|
||||
|
||||
repoURL := fmt.Sprintf("https://github.com/%s.git", gh.Repo)
|
||||
branchName := fmt.Sprintf("pr-%d", number)
|
||||
refSpec := fmt.Sprintf("refs/pull/%d/head:%s", number, branchName)
|
||||
|
||||
log(fmt.Sprintf("fetching PR #%d (shallow) from %s", number, gh.Repo))
|
||||
initCmd := exec.CommandContext(ctx, "git", "init", checkout)
|
||||
if err := runLogged(initCmd, log); err != nil {
|
||||
cleanup()
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("init git repository: %w", err)
|
||||
}
|
||||
|
||||
fetchCmd := exec.CommandContext(ctx, "git", "-C", checkout, "fetch", "--depth", "1", repoURL, refSpec)
|
||||
if err := runLogged(fetchCmd, log); err != nil {
|
||||
cleanup()
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("fetch PR #%d: %w", number, err)
|
||||
}
|
||||
|
||||
checkoutCmd := exec.CommandContext(ctx, "git", "-C", checkout, "checkout", branchName)
|
||||
if err := runLogged(checkoutCmd, log); err != nil {
|
||||
cleanup()
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("checkout PR #%d: %w", number, err)
|
||||
}
|
||||
|
||||
_, revision, err := checkoutDetails(ctx, checkout)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return docker.BuildOptions{}, noCleanup, err
|
||||
}
|
||||
log("building " + revision[:min(len(revision), 12)])
|
||||
return docker.BuildOptions{
|
||||
Context: checkout,
|
||||
Tag: tag,
|
||||
Source: fmt.Sprintf("https://github.com/%s/pull/%d", gh.Repo, number),
|
||||
Revision: revision,
|
||||
PRNumber: number,
|
||||
}, cleanup, nil
|
||||
}
|
||||
|
||||
// RebuildOptions describes a rebuild of an existing local image from the
|
||||
// provenance recorded on it, whether that is a pull request or a checkout.
|
||||
func RebuildOptions(ctx context.Context, image docker.Image, log func(string)) (docker.BuildOptions, Cleanup, error) {
|
||||
if image.PRNumber > 0 {
|
||||
return PRBuildOptions(ctx, image.PRNumber, image.Tag, log)
|
||||
}
|
||||
if image.Source == "" {
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("homarr:%s has no build source metadata", image.Tag)
|
||||
}
|
||||
if info, err := os.Stat(image.Source); err != nil || !info.IsDir() {
|
||||
return docker.BuildOptions{}, noCleanup, fmt.Errorf("build source %s is no longer available", image.Source)
|
||||
}
|
||||
options, err := CurrentBuildOptions(ctx, image.Tag, image.Source)
|
||||
return options, noCleanup, err
|
||||
}
|
||||
|
||||
func runLogged(command *exec.Cmd, log func(string)) error {
|
||||
command.Env = append(
|
||||
os.Environ(),
|
||||
"MISE_TRUSTED_CONFIG_PATHS=*",
|
||||
"MISE_QUIET=1",
|
||||
"MISE_SILENT=1",
|
||||
"MISE_YES=1",
|
||||
"MISE_OVERRIDE_CONFIG_FILENAMES=",
|
||||
)
|
||||
lines, err := docker.StreamCommand(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for line := range lines {
|
||||
if line.Done {
|
||||
return line.Err
|
||||
}
|
||||
log(line.Text)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func BuildPlan(opts Options) (*Plan, error) {
|
||||
}
|
||||
p.Env = append(p.Env, opts.Env...)
|
||||
if opts.Demo {
|
||||
p.Env = append(p.Env, "DEMO_MODE=true", "UNSAFE_ENABLE_MOCK_INTEGRATION=true")
|
||||
p.Env = append(p.Env, "DEMO_MODE=true", "DEMO_READ_ONLY=false", "UNSAFE_ENABLE_MOCK_INTEGRATION=true")
|
||||
p.Label += " (demo)"
|
||||
}
|
||||
return p, nil
|
||||
|
||||
@@ -19,10 +19,10 @@ func TestPRPlanUsesAMD64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRCloneIsShallow(t *testing.T) {
|
||||
args := prCloneArgs("/tmp/checkout")
|
||||
if !slices.Contains(args, "--depth=1") || !slices.Contains(args, "--filter=blob:none") {
|
||||
t.Fatalf("clone args = %v", args)
|
||||
func TestPRFetchIsShallow(t *testing.T) {
|
||||
args := prFetchArgs("https://github.com/homarr-labs/homarr.git", "refs/pull/1/head:pr-1")
|
||||
if !slices.Contains(args, "--depth=1") {
|
||||
t.Fatalf("fetch args = %v", args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,24 @@ func TestBuildPlanFailsWhenNoPortIsAvailable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPlanPreservesEnvironmentOverrides(t *testing.T) {
|
||||
want := []string{
|
||||
"WORKSHOP_WEB_URL=https://app-v2.preview.homarr.dev/",
|
||||
"FEATURE_OPTIONS=one=two",
|
||||
}
|
||||
plan, err := BuildPlan(Options{
|
||||
PR: 1,
|
||||
Env: want,
|
||||
FindPort: func(int) int { return 7575 },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Equal(plan.Env, want) {
|
||||
t.Fatalf("environment = %v, want %v", plan.Env, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartPRIntegration(t *testing.T) {
|
||||
if os.Getenv("HOMARR_DOCKER_INTEGRATION_TEST") != "1" {
|
||||
t.Skip("set HOMARR_DOCKER_INTEGRATION_TEST=1 and HOMARR_TEST_PR=<number>")
|
||||
|
||||
Reference in new issue
Block a user