|
| 1 | +# Copyright 2025 The PECOS Developers |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +# the License. You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| 9 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +# specific language governing permissions and limitations under the License. |
| 11 | + |
| 12 | +name: Go test |
| 13 | + |
| 14 | +env: |
| 15 | + TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes |
| 16 | + RUSTFLAGS: -C debuginfo=0 |
| 17 | + RUST_BACKTRACE: 1 |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: [ "master", "development", "dev" ] |
| 22 | + pull_request: |
| 23 | + branches: [ "master", "development", "dev" ] |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +defaults: |
| 31 | + run: |
| 32 | + shell: bash |
| 33 | + |
| 34 | +jobs: |
| 35 | + go-test: |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + strategy: |
| 38 | + fail-fast: false |
| 39 | + matrix: |
| 40 | + os: [ubuntu-latest, windows-latest, macOS-latest] |
| 41 | + go-version: ["1.21", "1.22"] # Test on recent stable versions |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Go ${{ matrix.go-version }} |
| 47 | + uses: actions/setup-go@v5 |
| 48 | + with: |
| 49 | + go-version: ${{ matrix.go-version }} |
| 50 | + |
| 51 | + - name: Set up Rust |
| 52 | + run: rustup show |
| 53 | + |
| 54 | + - name: Cache Rust |
| 55 | + uses: Swatinem/rust-cache@v2 |
| 56 | + with: |
| 57 | + workspaces: go/pecos-go-ffi |
| 58 | + |
| 59 | + - name: Set up Visual Studio environment on Windows |
| 60 | + if: runner.os == 'Windows' |
| 61 | + uses: ilammy/msvc-dev-cmd@v1 |
| 62 | + with: |
| 63 | + arch: x64 |
| 64 | + |
| 65 | + - name: Build Rust FFI library (Windows) |
| 66 | + if: runner.os == 'Windows' |
| 67 | + shell: pwsh |
| 68 | + run: | |
| 69 | + cd go/pecos-go-ffi |
| 70 | + cargo build --release |
| 71 | +
|
| 72 | + - name: Build Rust FFI library (Unix) |
| 73 | + if: runner.os != 'Windows' |
| 74 | + shell: bash |
| 75 | + run: | |
| 76 | + # On macOS, prevent Homebrew library paths from being used during linking |
| 77 | + if [[ "${{ runner.os }}" == "macOS" ]]; then |
| 78 | + # CRITICAL: Prevent Homebrew library paths from being used during linking |
| 79 | + # This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS |
| 80 | + # Reference: https://github.com/rust-lang/rust/issues/135372 |
| 81 | + unset LIBRARY_PATH |
| 82 | + unset LD_LIBRARY_PATH |
| 83 | + unset DYLD_LIBRARY_PATH |
| 84 | + unset DYLD_FALLBACK_LIBRARY_PATH |
| 85 | + unset PKG_CONFIG_PATH |
| 86 | + export LIBRARY_PATH=/usr/lib |
| 87 | +
|
| 88 | + echo "RUSTFLAGS: $RUSTFLAGS" |
| 89 | + fi |
| 90 | +
|
| 91 | + cd go/pecos-go-ffi |
| 92 | + cargo build --release |
| 93 | +
|
| 94 | + - name: Run Go tests (Unix) |
| 95 | + if: runner.os != 'Windows' |
| 96 | + run: | |
| 97 | + cd go/pecos |
| 98 | + LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ github.workspace }}/target/release \ |
| 99 | + DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${{ github.workspace }}/target/release \ |
| 100 | + go test -v |
| 101 | +
|
| 102 | + - name: Run Go tests (Windows) |
| 103 | + if: runner.os == 'Windows' |
| 104 | + shell: pwsh |
| 105 | + run: | |
| 106 | + $env:PATH = "${{ github.workspace }}\target\release;$env:PATH" |
| 107 | + cd go/pecos |
| 108 | + go test -v |
| 109 | +
|
| 110 | + - name: Check Go formatting |
| 111 | + run: | |
| 112 | + cd go/pecos |
| 113 | + if [ -n "$(gofmt -l .)" ]; then |
| 114 | + echo "Formatting issues found:" |
| 115 | + gofmt -l . |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + echo "All Go code is properly formatted." |
| 119 | +
|
| 120 | + - name: Run Go vet |
| 121 | + run: | |
| 122 | + cd go/pecos |
| 123 | + go vet ./... |
0 commit comments