Fix staticcheck warnings and errors #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Test Network Mapper | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| paths: | |
| - 'network-mapper/**' | |
| - '.github/workflows/build.yml' | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'network-mapper/**' | |
| env: | |
| GO_VERSION: '1.21' | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('network-mapper/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| working-directory: network-mapper | |
| run: go mod download | |
| - name: Verify dependencies | |
| working-directory: network-mapper | |
| run: go mod verify | |
| - name: Run tests | |
| working-directory: network-mapper | |
| run: go test -v ./... | |
| - name: Run go vet | |
| working-directory: network-mapper | |
| run: go vet ./... | |
| - name: Install staticcheck | |
| run: go install honnef.co/go/tools/cmd/staticcheck@latest | |
| - name: Run staticcheck | |
| working-directory: network-mapper | |
| run: staticcheck ./... | |
| - name: Check formatting | |
| working-directory: network-mapper | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "Code is not formatted properly:" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| strategy: | |
| matrix: | |
| goos: [linux, windows, darwin] | |
| goarch: [amd64, arm64] | |
| exclude: | |
| - goos: windows | |
| goarch: arm64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('network-mapper/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| working-directory: network-mapper | |
| run: go mod download | |
| - name: Build binary | |
| working-directory: network-mapper | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| run: | | |
| mkdir -p build | |
| BINARY_NAME=network-mapper-${{ matrix.goos }}-${{ matrix.goarch }} | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| BINARY_NAME="${BINARY_NAME}.exe" | |
| fi | |
| go build -ldflags "-X main.version=${GITHUB_REF#refs/tags/}" -o build/${BINARY_NAME} . | |
| - name: Generate checksums | |
| working-directory: network-mapper | |
| run: | | |
| cd build | |
| sha256sum * > checksums-${{ matrix.goos }}-${{ matrix.goarch }}.txt | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: network-mapper-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: | | |
| network-mapper/build/network-mapper-${{ matrix.goos }}-${{ matrix.goarch }}* | |
| network-mapper/build/checksums-${{ matrix.goos }}-${{ matrix.goarch }}.txt | |
| retention-days: 30 | |