Skip to content

Commit

Permalink
Run tests on Windows and MacOS
Browse files Browse the repository at this point in the history
- Extend the CI workflow to test on Windows and MacOS
- Add missing Close() calls when opening the temporary test files
- Fix test with relative paths on different drives.
  On the Windows GitHub runners the cache directory is on drive C and
  the current working directory is on drive D which makes the relative
  path resolution fail.
  • Loading branch information
thschmitt committed Dec 20, 2024
1 parent d47619a commit 1327ad0
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 20 deletions.
60 changes: 48 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on: [push]

env:
UIPATHCLI_BASE_VERSION: "v1.1"
GO_VERSION: "1.22.2"

jobs:
build:
Expand All @@ -17,22 +18,39 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.22.2'
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Version
id: version
run: |
UIPATHCLI_VERSION=$(./version.sh "$UIPATHCLI_BASE_VERSION")
echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_ENV
echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_OUTPUT
- name: Install dependencies
run: go get .
- name: Build
run: go build -ldflags="-X github.com/UiPath/uipathcli/commandline.Version=$UIPATHCLI_VERSION" .
- name: Lint
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run
- name: Package
run: ./build.sh && ./package.sh
- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: build/packages/
if-no-files-found: error

test_linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Test
run: go test -coverprofile="coverage.out" -coverpkg "$(go list github.com/UiPath/uipathcli/... | grep -v 'test' | tr '\n' ',')" ./...
- name: Coverage
Expand All @@ -41,17 +59,35 @@ jobs:
run: |
go install github.com/mattn/goveralls@latest
goveralls -coverprofile="coverage.out" -service="github"
- name: Package
run: ./build.sh && ./package.sh
- name: Upload packages
uses: actions/upload-artifact@v4
test_windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
name: packages
path: build/packages/
if-no-files-found: error
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Test
run: go test ./...

test_macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Test
run: go test ./...

publish_pages:
needs: build
needs: [build, test_linux, test_windows, test_macos]
permissions:
pages: write
id-token: write
Expand Down Expand Up @@ -79,7 +115,7 @@ jobs:
uses: actions/deploy-pages@v4

release:
needs: build
needs: [build, test_linux, test_windows, test_macos]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ uipathcli
build/
coverage.out
coverage.html
bin/
bin/
tmp/
8 changes: 7 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ func createFile(t *testing.T, directory string, name string) string {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Remove(tempFile.Name()) })
defer tempFile.Close()
t.Cleanup(func() {
err := os.Remove(tempFile.Name())
if err != nil {
t.Fatal(err)
}
})
return tempFile.Name()
}

Expand Down
8 changes: 7 additions & 1 deletion plugin/digitizer/digitizer_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,13 @@ func createFile(t *testing.T) string {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Remove(tempFile.Name()) })
defer tempFile.Close()
t.Cleanup(func() {
err := os.Remove(tempFile.Name())
if err != nil {
t.Fatal(err)
}
})
return tempFile.Name()
}

Expand Down
8 changes: 7 additions & 1 deletion plugin/orchestrator/orchestrator_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,13 @@ func createFile(t *testing.T) string {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Remove(tempFile.Name()) })
defer tempFile.Close()
t.Cleanup(func() {
err := os.Remove(tempFile.Name())
if err != nil {
t.Fatal(err)
}
})
return tempFile.Name()
}

Expand Down
4 changes: 2 additions & 2 deletions test/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,10 @@ paths:
WithResponse(200, "").
Build()

path := createFile(t)
currentPath, _ := os.Getwd()
path := createFileInFolder(t, filepath.Join(currentPath, "tmp"))
writeFile(t, path, []byte("hello-world"))

currentPath, _ := os.Getwd()
relativePath, _ := filepath.Rel(currentPath, path)
result := RunCli([]string{"myservice", "upload", "--file", relativePath}, context)

Expand Down
20 changes: 18 additions & 2 deletions test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,27 @@ func RunCli(args []string, context Context) Result {
}

func createFile(t *testing.T) string {
tempFile, err := os.CreateTemp("", "uipath-test")
return createFileInFolder(t, "")
}

func createFileInFolder(t *testing.T, path string) string {
if path != "" {
err := os.MkdirAll(path, 0700)
if err != nil {
t.Fatal(err)
}
}
tempFile, err := os.CreateTemp(path, "uipath-test")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Remove(tempFile.Name()) })
defer tempFile.Close()
t.Cleanup(func() {
err := os.Remove(tempFile.Name())
if err != nil {
t.Fatal(err)
}
})
return tempFile.Name()
}

Expand Down
2 changes: 2 additions & 0 deletions utils/file_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestFileStreamName(t *testing.T) {

func TestFileStreamSize(t *testing.T) {
tempFile, _ := os.CreateTemp("", "uipath-test")
defer tempFile.Close()
t.Cleanup(func() { os.Remove(tempFile.Name()) })
err := os.WriteFile(tempFile.Name(), []byte("hello-world"), 0600)
if err != nil {
Expand All @@ -37,6 +38,7 @@ func TestFileStreamSize(t *testing.T) {

func TestFileStreamData(t *testing.T) {
tempFile, _ := os.CreateTemp("", "uipath-test")
defer tempFile.Close()
t.Cleanup(func() { os.Remove(tempFile.Name()) })
err := os.WriteFile(tempFile.Name(), []byte("hello-world"), 0600)
if err != nil {
Expand Down

0 comments on commit 1327ad0

Please sign in to comment.