Browse Source

start testing on GitHub Actions

No windows yet, because a few portability issues remain.
Daniel Martí 2 years ago
parent
commit
ab560ff007
7 changed files with 45 additions and 10 deletions
  1. 2 0
      .gitattributes
  2. 1 0
      .github/FUNDING.yml
  3. 18 0
      .github/workflows/test.yml
  4. 1 1
      README.md
  5. 6 1
      main.go
  6. 11 0
      main_test.go
  7. 6 8
      testdata/scripts/basic.txt

+ 2 - 0
.gitattributes

@@ -0,0 +1,2 @@
+# To prevent CRLF breakages on Windows for fragile files, like testdata.
+* -text

+ 1 - 0
.github/FUNDING.yml

@@ -0,0 +1 @@
+github: mvdan

+ 18 - 0
.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 ./...

+ 1 - 1
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]
 

+ 6 - 1
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:]...)
 

+ 11 - 0
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

+ 6 - 8
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'