diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..fc9d24f --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,51 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go Build & Test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.24' + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + $GOPATH/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod tidy + + - name: Build server + run: go build -v -o server ./server.go + + - name: Build client + run: go build -v -o client ./client.go + + - name: Run tests (if available) + run: | + if ls *_test.go > /dev/null 2>&1 || find . -name '*_test.go' | grep .; then + echo "Running tests..." + go test -v ./... + else + echo "No tests found, skipping tests." + fi