Skip to content

Commit

Permalink
Merge pull request #225 from fyne-io/develop
Browse files Browse the repository at this point in the history
Trigger CI before release of getting develop to master
  • Loading branch information
Bluebugs committed Apr 2, 2024
2 parents 150cf61 + 5448401 commit 540d232
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"

20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: go install golang.org/x/tools/cmd/goimports@latest

# Checks-out the repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Run linters
- name: Run go vet
Expand All @@ -34,7 +34,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# use max/min supported Go versions
go-version: ["1.18.x", "1.14.x"]
go-version: ["1.21.x", "1.17.x"]

steps:
- name: Setup Go environment
Expand All @@ -44,7 +44,7 @@ jobs:
go-version: ${{ matrix.go-version }}

# Checks-out the repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Run tests
- run: go test -v -cover -race ./...
Expand All @@ -66,7 +66,7 @@ jobs:
go-version: ${{ matrix.go-version }}

# Checks-out the repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Run tests
- run: go build -tags k8s
Expand All @@ -80,7 +80,7 @@ jobs:
fail-fast: false
matrix:
# use max/min supported Go versions
go-version: ["1.18.x", "1.14.x"]
go-version: ["1.21.x", "1.17.x"]
target:
- os: linux
- os: windows
Expand Down Expand Up @@ -108,12 +108,12 @@ jobs:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: fyne-cross

- name: Checkout fyne-io/calculator
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: fyne-io/calculator
path: calculator
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
fail-fast: false
matrix:
# use max/min supported Go versions
go-version: ["1.18.x", "1.14.x"]
go-version: ["1.21.x", "1.17.x"]
target:
- os: linux
- os: windows
Expand Down Expand Up @@ -190,12 +190,12 @@ jobs:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: fyne-cross

- name: Checkout fyne-io/terminal
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: fyne-io/terminal
path: terminal
Expand Down
3 changes: 3 additions & 0 deletions internal/command/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (cmd *android) Parse(args []string) error {
flagSet.StringVar(&flags.Keystore, "keystore", "", "The location of .keystore file containing signing information")
flagSet.StringVar(&flags.KeystorePass, "keystore-pass", "", "Password for the .keystore file")
flagSet.StringVar(&flags.KeyPass, "key-pass", "", "Password for the signer's private key, which is needed if the private key is password-protected")
flagSet.StringVar(&flags.KeyName, "key-name", "", "Name of the key to use for signing")

flagSet.Usage = cmd.Usage
flagSet.Parse(args)
Expand Down Expand Up @@ -147,6 +148,7 @@ type androidFlags struct {
Keystore string //Keystore represents the location of .keystore file containing signing information
KeystorePass string //Password for the .keystore file
KeyPass string //Password for the signer's private key, which is needed if the private key is password-protected
KeyName string //Name of the key to use for signing

// TargetArch represents a list of target architecture to build on separated by comma
TargetArch *targetArchFlag
Expand Down Expand Up @@ -196,6 +198,7 @@ func (cmd *android) setupContainerImages(flags *androidFlags, args []string) err
cmd.defaultContext.Keystore = volume.JoinPathContainer(cmd.defaultContext.Volume.WorkDirContainer(), flags.Keystore)
cmd.defaultContext.KeystorePass = flags.KeystorePass
cmd.defaultContext.KeyPass = flags.KeyPass
cmd.defaultContext.KeyName = flags.KeyName

cmd.Images = append(cmd.Images, image)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func fyneCommand(binary, command, icon string, ctx Context, image containerImage
// add tags to command, if any
tags := image.Tags()
if len(tags) > 0 {
args = append(args, "-tags", fmt.Sprintf("%q", strings.Join(tags, ",")))
args = append(args, "-tags", strings.Join(tags, ","))
}

if ctx.Metadata != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/command/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ func fyneRelease(ctx Context, image containerImage) error {
if ctx.KeyPass != "" {
args = append(args, "-keyPass", ctx.KeyPass)
}
if ctx.KeyName != "" {
args = append(args, "-keyName", ctx.KeyName)
}
case iosOS:
if ctx.Certificate != "" {
args = append(args, "-certificate", ctx.Certificate)
Expand Down
6 changes: 6 additions & 0 deletions internal/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -72,6 +73,7 @@ type Context struct {
Keystore string //Keystore represents the location of .keystore file containing signing information [Android]
KeystorePass string //KeystorePass represents the password for the .keystore file [Android]
KeyPass string //KeyPass represents the assword for the signer's private key, which is needed if the private key is password-protected [Android]
KeyName string //KeyName represents the name of the key to sign the build [Android]
Password string //Password represents the password for the certificate used to sign the build [Windows]
Profile string //Profile represents the name of the provisioning profile for this release build [iOS]
}
Expand Down Expand Up @@ -173,6 +175,10 @@ func makeDefaultContext(flags *CommonFlags, args []string) (Context, error) {
return ctx, err
}

if env := os.Getenv("GOFLAGS"); env != "" {
ctx.Env["GOFLAGS"] = env
}

if len(flags.Ldflags) > 0 {
goflags := ""
for _, ldflags := range strings.Fields(flags.Ldflags) {
Expand Down
28 changes: 17 additions & 11 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func AppendEnv(args []string, environs map[string]string, quoteNeeded bool) []st
for k, v := range environs {
env := k + "=" + v
if quoteNeeded && strings.Contains(v, "=") {
// engine requires to double quote the env var when value contains
// engine requires to double quote the value when it contains
// the `=` char
env = fmt.Sprintf("%q", env)
env = fmt.Sprintf("%s=%q", k, v)
}
args = append(args, "-e", env)
}
Expand All @@ -104,8 +104,8 @@ func (i *localContainerImage) cmd(vol volume.Volume, opts options, cmdArgs []str
}

mountFormat := "%s:%s:z"
if runtime.GOOS == darwinOS && runtime.GOARCH == string(ArchArm64) {
// When running on darwin with a Arm64, we rely on going through a VM setup that doesn't allow the :z
if runtime.GOOS == darwinOS {
// When running on darwin with an Arm64 or Amd64, we rely on going through a VM setup that doesn't allow the :z
mountFormat = "%s:%s"
}

Expand All @@ -129,19 +129,25 @@ func (i *localContainerImage) cmd(vol volume.Volume, opts options, cmdArgs []str
if runtime.GOOS != "windows" {
u, err := user.Current()
if err == nil {
args = append(args, "-u", fmt.Sprintf("%s:%s", u.Uid, u.Gid))
args = append(args, "--entrypoint", "fixuid")
if !debugging() {
// silent fixuid if not debug mode
cmdArgs = append([]string{"-q"}, cmdArgs...)
}
// Container runs as current host UID
args = append(args, "--user", u.Uid)
// Set HOME to something writable by the user
args = append(args, "-e", "HOME=/tmp")
}
}
}

// detect ssh-agent socket for private repositories access
if sshAuthSock := os.Getenv("SSH_AUTH_SOCK"); sshAuthSock != "" {
if realSshAuthSock, err := filepath.EvalSymlinks(sshAuthSock); err == nil {
if runtime.GOOS == "darwin" {
// Podman doesn't yet support sshagent forwarding on macOS
if !i.runner.engine.IsPodman() {
// on macOS, the SSH_AUTH_SOCK is not available in the container directly,
// but instead we need to the magic path "/run/host-services/ssh-auth.sock"
args = append(args, "-v", "/run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock")
args = append(args, "-e", "SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock")
}
} else if realSshAuthSock, err := filepath.EvalSymlinks(sshAuthSock); err == nil {
args = append(args, "-v", fmt.Sprintf("%s:/tmp/ssh-agent", realSshAuthSock))
args = append(args, "-e", "SSH_AUTH_SOCK=/tmp/ssh-agent")
}
Expand Down
120 changes: 116 additions & 4 deletions internal/command/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestCmdEngineDocker(t *testing.T) {
log.Println(expectedCmd)

uid, _ := user.Current()
mountFlag := ":z"
if runtime.GOOS == darwinOS && runtime.GOARCH == string(ArchArm64) {
// When running on darwin with a Arm64, we rely on going through a VM setup that doesn't allow the :z
mountFlag = ""
}

workDir := filepath.Join(os.TempDir(), "fyne-cross-test", "app")
cacheDir := filepath.Join(os.TempDir(), "fyne-cross-test", "cache")
Expand Down Expand Up @@ -65,7 +70,7 @@ func TestCmdEngineDocker(t *testing.T) {
opts: options{},
cmdArgs: []string{"command", "arg"},
},
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z --platform linux/amd64 -u %s:%s --entrypoint fixuid -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s -q command arg", expectedCmd, workDir, uid.Uid, uid.Gid, dockerImage),
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app%s --platform linux/%s --user %s -e HOME=/tmp -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, workDir, mountFlag, runtime.GOARCH, uid.Uid, dockerImage),
wantWindows: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z --platform linux/amd64 -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, workDir, dockerImage),
},
{
Expand All @@ -83,7 +88,7 @@ func TestCmdEngineDocker(t *testing.T) {
},
cmdArgs: []string{"command", "arg"},
},
want: fmt.Sprintf("%s run --rm -t -w %s -v %s:/app:z --platform linux/amd64 -u %s:%s --entrypoint fixuid -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s -q command arg", expectedCmd, customWorkDir, workDir, uid.Uid, uid.Gid, dockerImage),
want: fmt.Sprintf("%s run --rm -t -w %s -v %s:/app%s --platform linux/%s --user %s -e HOME=/tmp -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, customWorkDir, workDir, mountFlag, runtime.GOARCH, uid.Uid, dockerImage),
wantWindows: fmt.Sprintf("%s run --rm -t -w %s -v %s:/app:z --platform linux/amd64 -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, customWorkDir, workDir, dockerImage),
},
{
Expand All @@ -100,7 +105,7 @@ func TestCmdEngineDocker(t *testing.T) {
opts: options{},
cmdArgs: []string{"command", "arg"},
},
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z -v %s:/go:z --platform linux/amd64 -u %s:%s --entrypoint fixuid -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s -q command arg", expectedCmd, workDir, cacheDir, uid.Uid, uid.Gid, dockerImage),
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app%s -v %s:/go%s --platform linux/%s --user %s -e HOME=/tmp -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, workDir, mountFlag, cacheDir, mountFlag, runtime.GOARCH, uid.Uid, dockerImage),
wantWindows: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z -v %s:/go:z --platform linux/amd64 -e CGO_ENABLED=1 -e GOCACHE=/go/go-build %s command arg", expectedCmd, workDir, cacheDir, dockerImage),
},
{
Expand All @@ -118,7 +123,7 @@ func TestCmdEngineDocker(t *testing.T) {
opts: options{},
cmdArgs: []string{"command", "arg"},
},
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z --platform linux/amd64 -u %s:%s --entrypoint fixuid -e CGO_ENABLED=1 -e GOCACHE=/go/go-build -e GOPROXY=proxy.example.com %s -q command arg", expectedCmd, workDir, uid.Uid, uid.Gid, dockerImage),
want: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app%s --platform linux/%s --user %s -e HOME=/tmp -e CGO_ENABLED=1 -e GOCACHE=/go/go-build -e GOPROXY=proxy.example.com %s command arg", expectedCmd, workDir, mountFlag, runtime.GOARCH, uid.Uid, dockerImage),
wantWindows: fmt.Sprintf("%s run --rm -t -w /app -v %s:/app:z --platform linux/amd64 -e CGO_ENABLED=1 -e GOCACHE=/go/go-build -e GOPROXY=proxy.example.com %s command arg", expectedCmd, workDir, dockerImage),
},
}
Expand Down Expand Up @@ -268,6 +273,113 @@ func TestCmdEnginePodman(t *testing.T) {
}
}

func TestAppendEnv(t *testing.T) {
type args struct {
args []string
env map[string]string
quoteNeeded bool
}
tests := []struct {
name string
args args
wantStart []string
wantEnd [][2]string
}{
{
name: "empty",
args: args{
args: []string{},
env: map[string]string{},
quoteNeeded: true,
},
wantStart: []string{},
wantEnd: [][2]string{},
},
{
name: "quote needed",
args: args{
args: []string{},
env: map[string]string{"VAR": "value"},
quoteNeeded: true,
},
wantStart: []string{},
wantEnd: [][2]string{{"-e", "VAR=value"}},
},
{
name: "quote not needed",
args: args{
args: []string{},
env: map[string]string{"VAR": "value"},
quoteNeeded: false,
},
wantStart: []string{},
wantEnd: [][2]string{{"-e", "VAR=value"}},
},
{
name: "multiple",
args: args{
args: []string{},
env: map[string]string{"VAR": "value", "VAR2": "value2"},
quoteNeeded: true,
},
wantStart: []string{},
wantEnd: [][2]string{{"-e", "VAR=value"}, {"-e", "VAR2=value2"}},
},
{
name: "multiple with args",
args: args{
args: []string{"arg1", "arg2"},
env: map[string]string{"VAR": "value", "VAR2": "value2"},
quoteNeeded: true,
},
wantStart: []string{"arg1", "arg2"},
wantEnd: [][2]string{{"-e", "VAR=value"}, {"-e", "VAR2=value2"}},
},
{
name: "multiple with args and equal sign require quoting values",
args: args{
args: []string{"arg1", "arg2"},
env: map[string]string{"VAR": "value", "VAR2": "value2=2"},
quoteNeeded: true,
},
wantStart: []string{"arg1", "arg2"},
wantEnd: [][2]string{{"-e", "VAR=value"}, {"-e", "VAR2=\"value2=2\""}},
},
{
name: "multiple with args and equal sign do not require quoting values",
args: args{
args: []string{"arg1", "arg2"},
env: map[string]string{"VAR": "value", "VAR2": "value2=2"},
quoteNeeded: false,
},
wantStart: []string{"arg1", "arg2"},
wantEnd: [][2]string{{"-e", "VAR=value"}, {"-e", "VAR2=value2=2"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := AppendEnv(tt.args.args, tt.args.env, tt.args.quoteNeeded)
var i int
for _, v := range tt.wantStart {
assert.Equal(t, v, got[i])
i++
}
for ; i < len(got); i += 2 {
found := false
for k, v := range tt.wantEnd {
if v[0] == got[i] && v[1] == got[i+1] {
tt.wantEnd = append(tt.wantEnd[:k], tt.wantEnd[k+1:]...)
found = true
break
}
}
assert.Equal(t, true, found)
}
assert.Equal(t, 0, len(tt.wantEnd))
})
}
}

func TestMain(m *testing.M) {
os.Unsetenv("SSH_AUTH_SOCK")
os.Exit(m.Run())
Expand Down

0 comments on commit 540d232

Please sign in to comment.