Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix release flags behavior #22

Merged
merged 2 commits into from
Dec 27, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog - Fyne.io fyne-cross

## Unreleased
- Fix android keystore path is not resolved correctly
- Fix some release flags are always set even if empty

## [1.0.0]
- Add support for "fyne release" #3
- Add support for creating packaged .tar.gz bundles on freebsd #6
Expand Down
12 changes: 11 additions & 1 deletion internal/command/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"fmt"
"os"
"path"
"path/filepath"

"github.com/fyne-io/fyne-cross/internal/log"
Expand Down Expand Up @@ -187,7 +188,16 @@ func makeAndroidContext(flags *androidFlags, args []string) (Context, error) {
ctx.OS = androidOS
ctx.ID = androidOS

ctx.Keystore = flags.Keystore
if path.IsAbs(flags.Keystore) {
return Context{}, fmt.Errorf("keystore location must be relative to the project root: %s", ctx.Volume.WorkDirHost())
}

_, err = os.Stat(volume.JoinPathHost(ctx.Volume.WorkDirHost(), flags.Keystore))
if err != nil {
return Context{}, fmt.Errorf("keystore location must be under the project root: %s", ctx.Volume.WorkDirHost())
}

ctx.Keystore = volume.JoinPathContainer(ctx.Volume.WorkDirContainer(), flags.Keystore)
ctx.KeystorePass = flags.KeystorePass
ctx.KeyPass = flags.KeyPass

Expand Down
115 changes: 115 additions & 0 deletions internal/command/android_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package command

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_makeAndroidContext(t *testing.T) {
vol, err := mockDefaultVolume()
require.Nil(t, err)

type args struct {
flags *androidFlags
args []string
}
tests := []struct {
name string
args args
want Context
wantErr bool
}{
{
name: "keystore path must be relative to project root",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "/tmp/my.keystore",
},
},
want: Context{},
wantErr: true,
},
{
name: "keystore path does not exist",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "my.keystore",
},
},
want: Context{},
wantErr: true,
},
{
name: "default",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "testdata/my.keystore",
},
},
want: Context{
AppBuild: "1",
AppID: "test",
ID: androidOS,
OS: androidOS,
DockerImage: androidImage,
Volume: vol,
CacheEnabled: true,
StripDebug: true,
Package: ".",
Keystore: "/app/testdata/my.keystore",
},
wantErr: false,
},
{
name: "default",
args: args{
flags: &androidFlags{
CommonFlags: &CommonFlags{
AppBuild: 1,
AppID: "test",
},
Keystore: "./testdata/my.keystore",
},
},
want: Context{
AppBuild: "1",
AppID: "test",
ID: androidOS,
OS: androidOS,
DockerImage: androidImage,
Volume: vol,
CacheEnabled: true,
StripDebug: true,
Package: ".",
Keystore: "/app/testdata/my.keystore",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, err := makeAndroidContext(tt.args.flags, tt.args.args)

if tt.wantErr {
require.NotNil(t, err)
return
}
require.Nil(t, err)
assert.Equal(t, tt.want, ctx)
})
}
}
24 changes: 18 additions & 6 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,26 @@ func fyneReleaseHost(ctx Context) error {

switch ctx.OS {
case darwinOS:
args = append(args, "-category", ctx.Category)
if ctx.Category != "" {
args = append(args, "-category", ctx.Category)
}
case iosOS:
args = append(args, "-certificate", ctx.Certificate)
args = append(args, "-profile", ctx.Profile)
if ctx.Certificate != "" {
args = append(args, "-certificate", ctx.Certificate)
}
if ctx.Profile != "" {
args = append(args, "-profile", ctx.Profile)
}
case windowsOS:
args = append(args, "-certificate", ctx.Certificate)
args = append(args, "-developer", ctx.Developer)
args = append(args, "-password", ctx.Password)
if ctx.Certificate != "" {
args = append(args, "-certificate", ctx.Certificate)
}
if ctx.Developer != "" {
args = append(args, "-developer", ctx.Developer)
}
if ctx.Password != "" {
args = append(args, "-password", ctx.Password)
}
}

// run the command from the host
Expand Down
32 changes: 24 additions & 8 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,32 @@ func fyneRelease(ctx Context) error {
switch ctx.OS {
case androidOS:
workDir = volume.JoinPathContainer(workDir, ctx.Package)
args = append(args, "-keyStore", ctx.Keystore)
args = append(args, "-keyStorePass", ctx.KeystorePass)
args = append(args, "-keyPass", ctx.KeyPass)
if ctx.Keystore != "" {
args = append(args, "-keyStore", ctx.Keystore)
}
if ctx.KeystorePass != "" {
args = append(args, "-keyStorePass", ctx.KeystorePass)
}
if ctx.KeyPass != "" {
args = append(args, "-keyPass", ctx.KeyPass)
}
case iosOS:
args = append(args, "-certificate", ctx.Certificate)
args = append(args, "-profile", ctx.Profile)
if ctx.Certificate != "" {
args = append(args, "-certificate", ctx.Certificate)
}
if ctx.Profile != "" {
args = append(args, "-profile", ctx.Profile)
}
case windowsOS:
args = append(args, "-certificate", ctx.Certificate)
args = append(args, "-developer", ctx.Developer)
args = append(args, "-password", ctx.Password)
if ctx.Certificate != "" {
args = append(args, "-certificate", ctx.Certificate)
}
if ctx.Developer != "" {
args = append(args, "-developer", ctx.Developer)
}
if ctx.Password != "" {
args = append(args, "-password", ctx.Password)
}
}

runOpts := Options{
Expand Down
1 change: 1 addition & 0 deletions internal/command/testdata/my.keystore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
4 changes: 2 additions & 2 deletions internal/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func Mount(workDirHost string, cacheDirHost string) (Volume, error) {
// JoinPathContainer joins any number of path elements into a single path,
// separating them with the Container OS specific Separator.
func JoinPathContainer(elem ...string) string {
return strings.Join(elem, "/")
return filepath.Clean(strings.Join(elem, "/"))
}

// JoinPathHost joins any number of path elements into a single path,
// separating them with the Host OS specific Separator.
func JoinPathHost(elem ...string) string {
return filepath.Join(elem...)
return filepath.Clean(filepath.Join(elem...))
}

// Zip compress the source file into a zip archive
Expand Down