From 6675c50e97b60aa086a23c57c6b01f49f038a1ff Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Fri, 2 May 2025 12:22:45 -0700 Subject: [PATCH] GitHub actions --- .github/workflows/cicd.yml | 75 ++++++++++++++++++++++ .github/workflows/pr-validation.yml | 97 +++++++++++++++++++++++++++++ Makefile | 24 ++++++- package.json | 5 -- pnpm-lock.yaml | 23 ------- 5 files changed, 195 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/cicd.yml create mode 100644 .github/workflows/pr-validation.yml delete mode 100644 package.json delete mode 100644 pnpm-lock.yaml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..6f1ca85 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,75 @@ +name: CI/CD Pipeline + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + GO_VERSION: '1.24' + NODE_VERSION: '20' + +jobs: + test-go: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Install Protocol Buffers Compiler + run: | + sudo apt-get update + sudo apt-get install -y protobuf-compiler + + - name: Generate Protocol Buffers + run: make gen-proto + + - name: Install Go dependencies + run: go mod download + + - name: Run Go tests + run: make test + + - name: Check Go formatting + run: make fmt-check + + - name: Build binary + run: make build + + test-web: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + cache-dependency-path: 'web/pnpm-lock.yaml' + + - name: Install pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + run_install: false + + - name: Install web dependencies + working-directory: ./web + run: pnpm install + + - name: Run web lint + run: make web-lint + + - name: Run web tests + run: make web-test + + - name: Build web assets + run: make web-build diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml new file mode 100644 index 0000000..e5053a6 --- /dev/null +++ b/.github/workflows/pr-validation.yml @@ -0,0 +1,97 @@ +name: PR Validation + +on: + pull_request: + branches: [ "main" ] + workflow_dispatch: + +env: + GO_VERSION: '1.24' + NODE_VERSION: '20' + +jobs: + validate-go: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Install Protocol Buffers Compiler + run: | + sudo apt-get update + sudo apt-get install -y protobuf-compiler + + - name: Generate Protocol Buffers + run: make gen-proto + + - name: Install Go dependencies + run: go mod download + + - name: Run Go tests + run: make test + + - name: Check go fmt + run: make fmt-check + + - name: Build binary + run: make build + + validate-web: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + cache-dependency-path: 'web/pnpm-lock.yaml' + + - name: Install pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + run_install: false + + - name: Install web dependencies + working-directory: ./web + run: pnpm install + + - name: Run ESLint + run: make web-lint + + - name: Run web tests + run: make web-test + + - name: Build web assets + run: make web-build + + - name: Upload web test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: web-test-results + path: web/coverage + + check-docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: make docker-build + env: + MESHSTREAM_SITE_TITLE: "Meshstream Test" + MESHSTREAM_SITE_DESCRIPTION: "Meshtastic Network Monitoring Test" + + - name: Check Docker image + run: docker images meshstream \ No newline at end of file diff --git a/Makefile b/Makefile index cb604f9..65980cc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build run gen-proto clean tools web-run web-build web-test web-lint docker-build docker-run +.PHONY: build test run gen-proto clean tools web-run web-build web-test web-lint docker-build docker-run fmt fmt-check ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) @@ -17,6 +17,28 @@ build: mkdir -p dist go build -o dist/meshstream +# Test the server +test: vet + go test ./... -v + +# Check Go formatting +fmt: + gofmt -w $(shell find . -name "*.go" | grep -v "/generated/" | grep -v "/node_modules/") + +# Check Go formatting without modifying files (returns non-zero if files need formatting) +fmt-check: + @echo "Checking Go formatting..." + @if [ "$$(gofmt -l $$(find . -name "*.go" | grep -v "/generated/" | grep -v "/node_modules/") | wc -l)" -gt 0 ]; then \ + echo "The following files need to be formatted with go fmt:"; \ + gofmt -l $$(find . -name "*.go" | grep -v "/generated/" | grep -v "/node_modules/"); \ + exit 1; \ + else \ + echo "All Go files are properly formatted."; \ + fi + +vet: + go vet ./... + # Run the application with json log formatting run: build @./dist/meshstream --verbose 2>&1 | go tool github.com/dpup/logista diff --git a/package.json b/package.json deleted file mode 100644 index f37b515..0000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "@eslint/js": "^9.25.1" - } -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml deleted file mode 100644 index 64822dc..0000000 --- a/pnpm-lock.yaml +++ /dev/null @@ -1,23 +0,0 @@ -lockfileVersion: '9.0' - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - -importers: - - .: - dependencies: - '@eslint/js': - specifier: ^9.25.1 - version: 9.25.1 - -packages: - - '@eslint/js@9.25.1': - resolution: {integrity: sha512-dEIwmjntEx8u3Uvv+kr3PDeeArL8Hw07H9kyYxCjnM9pBjfEhk6uLXSchxxzgiwtRhhzVzqmUSDFBOi1TuZ7qg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - -snapshots: - - '@eslint/js@9.25.1': {}