From ab560ff007cc857e9f5f012409be5c92d9faf3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 9 Dec 2019 12:44:43 +0000 Subject: [PATCH] start testing on GitHub Actions No windows yet, because a few portability issues remain. --- .gitattributes | 2 ++ .github/FUNDING.yml | 1 + .github/workflows/test.yml | 18 ++++++++++++++++++ README.md | 2 +- main.go | 7 ++++++- main_test.go | 11 +++++++++++ testdata/scripts/basic.txt | 14 ++++++-------- 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/test.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6f95229 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# To prevent CRLF breakages on Windows for fragile files, like testdata. +* -text diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..098c3ca --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: mvdan diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..434af18 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,18 @@ +on: [push, pull_request] +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.13.x] + platform: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v1 + - name: Test + run: go test ./... diff --git a/README.md b/README.md index 727c679..f8b9e49 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ GO111MODULE=on go get mvdan.cc/garble -Obfuscate a Go build. +Obfuscate a Go build. Requires Go 1.13 or later. garble build [build flags] [packages] diff --git a/main.go b/main.go index a9f796f..1969df4 100644 --- a/main.go +++ b/main.go @@ -101,11 +101,16 @@ func main1() int { // If we recognise an argument, we're not running within -toolexec. switch args[0] { case "build": + execPath, err := os.Executable() + if err != nil { + fmt.Fprintln(os.Stderr, err) + return 1 + } goArgs := []string{ "build", "-a", "-trimpath", - "-toolexec=" + os.Args[0], + "-toolexec=" + execPath, } goArgs = append(goArgs, args[1:]...) diff --git a/main_test.go b/main_test.go index a74456b..27f352d 100644 --- a/main_test.go +++ b/main_test.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "testing" "github.com/rogpeppe/go-internal/testscript" @@ -32,12 +33,22 @@ func TestScripts(t *testing.T) { if err := os.Mkdir(bindir, 0777); err != nil { return err } + binfile := filepath.Join(bindir, "garble") + if runtime.GOOS == "windows" { + binfile += ".exe" + } if err := os.Symlink(os.Args[0], filepath.Join(bindir, "garble")); err != nil { return err } env.Vars = append(env.Vars, fmt.Sprintf("PATH=%s%c%s", bindir, filepath.ListSeparator, os.Getenv("PATH"))) env.Vars = append(env.Vars, "TESTSCRIPT_COMMAND=garble") + // GitHub Actions doesn't define %LocalAppData% on + // Windows, which breaks $GOCACHE. Set it ourselves. + if runtime.GOOS == "windows" { + env.Vars = append(env.Vars, fmt.Sprintf(`LOCALAPPDATA=%s\appdata`, env.WorkDir)) + } + for _, name := range [...]string{ "HOME", "USERPROFILE", // $HOME for windows diff --git a/testdata/scripts/basic.txt b/testdata/scripts/basic.txt index c527e1c..1907ca1 100644 --- a/testdata/scripts/basic.txt +++ b/testdata/scripts/basic.txt @@ -1,14 +1,12 @@ -# TODO: make this script run on mac and windows - # Check that the program works as expected without garble. exec go build main.go exec ./main cmp stderr main.stderr # The default build includes DWARF and the symbol table. -exec readelf --section-headers main -stdout 'debug_info' -stdout '\.symtab' +[!windows] [exec:readelf] exec readelf --section-headers main$exe +[!windows] [exec:readelf] stdout 'debug_info' +[!windows] [exec:readelf] stdout '\.symtab' # The default build includes full non-trimmed paths, as well as our names. bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc' @@ -22,9 +20,9 @@ exec go build -a -trimpath -toolexec=garble main.go exec ./main cmp stderr main.stderr -exec readelf --section-headers main -! stdout 'debug_info' -! stdout '\.symtab' +[!windows] [exec:readelf] exec readelf --section-headers main$exe +[!windows] [exec:readelf] ! stdout 'debug_info' +[!windows] [exec:readelf] ! stdout '\.symtab' ! bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc'