about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2023-03-27 08:16:17 -0700
committerGitHub <noreply@github.com>2023-03-27 10:16:17 -0500
commit2789d5c05647e3d6d6ae5d6e226b4218ed4a16d1 (patch)
treefb266710c9865130c2d10e389c6429802fd8515c
parent4fbe0e267ccf0adfcdd8b0c66107f1e1717ca31a (diff)
downloadvoidsky-2789d5c05647e3d6d6ae5d6e226b4218ed4a16d1.tar.zst
Basic golang CI setup (#360)
* bskyweb: Makefile and dev env

This matches the setup for local dev testing in atproto and indigo
repos.

* gitignore: don't ignore self and .github/

* CI: golang build+test and lint actions

* bskyweb: better use of godotenv

A recent change from indigo.

* prettier: ignore top-level app.json

* CI: bump from golang 1.19 to 1.20

* bskyweb: update to golang 1.20
-rw-r--r--.github/workflows/golang-test-lint.yml43
-rw-r--r--.gitignore4
-rw-r--r--.prettierignore1
-rw-r--r--bskyweb/.gitignore4
-rw-r--r--bskyweb/Makefile42
-rw-r--r--bskyweb/README.md2
-rw-r--r--bskyweb/cmd/bskyweb/main.go12
-rw-r--r--bskyweb/example.dev.env4
-rw-r--r--bskyweb/go.mod2
9 files changed, 102 insertions, 12 deletions
diff --git a/.github/workflows/golang-test-lint.yml b/.github/workflows/golang-test-lint.yml
new file mode 100644
index 000000000..39850ced4
--- /dev/null
+++ b/.github/workflows/golang-test-lint.yml
@@ -0,0 +1,43 @@
+name: golang
+
+on:
+  pull_request:
+  push:
+    branches:
+      - main
+
+concurrency:
+  group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Git Checkout
+        uses: actions/checkout@v3
+      - name: Set up Go tooling
+        uses: actions/setup-go@v3
+        with:
+          go-version: 1.20
+      - name: Dummy JS File
+        run: touch bskyweb/static/js/blah.js
+      - name: Check
+        run: cd bskyweb/ && make check
+      - name: Build (binary)
+        run: cd bskyweb/ && make build
+      - name: Test
+        run: cd bskyweb/ && make test
+  lint:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Git Checkout
+        uses: actions/checkout@v3
+      - name: Set up Go tooling
+        uses: actions/setup-go@v3
+        with:
+          go-version: 1.20
+      - name: Dummy JS File
+        run: touch bskyweb/static/js/blah.js
+      - name: Lint
+        run: cd bskyweb/ &&  make lint
diff --git a/.gitignore b/.gitignore
index 9d3293985..c6aafc848 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,3 +81,7 @@ web-build/
 
 # Temporary files created by Metro to check the health of the file watcher
 .metro-health-check*
+
+# gitignore and github actions
+!.gitignore
+!.github
diff --git a/.prettierignore b/.prettierignore
index 06cb77f4c..1a471a497 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -6,6 +6,7 @@ public
 /bskyweb/templates
 /dist/
 /.watchmanconfig
+/app.json
 
 web/index.html
 web-build/*
diff --git a/bskyweb/.gitignore b/bskyweb/.gitignore
index 4dc17cf0f..b2a31beb3 100644
--- a/bskyweb/.gitignore
+++ b/bskyweb/.gitignore
@@ -1,4 +1,8 @@
 .env
+test-coverage.out
 
 # Don't check in the binary.
 /bskyweb
+
+# Don't ignore this file
+!.gitignore
diff --git a/bskyweb/Makefile b/bskyweb/Makefile
new file mode 100644
index 000000000..957f043f5
--- /dev/null
+++ b/bskyweb/Makefile
@@ -0,0 +1,42 @@
+
+SHELL = /bin/bash
+.SHELLFLAGS = -o pipefail -c
+
+.PHONY: help
+help: ## Print info about all commands
+	@echo "Commands:"
+	@echo
+	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "    \033[01;32m%-20s\033[0m %s\n", $$1, $$2}'
+
+.PHONY: build
+build: ## Build all executables
+	go build ./cmd/bskyweb
+
+.PHONY: test
+test: ## Run all tests
+	go test ./...
+
+.PHONY: coverage-html
+coverage-html: ## Generate test coverage report and open in browser
+	go test ./... -coverpkg=./... -coverprofile=test-coverage.out
+	go tool cover -html=test-coverage.out
+
+.PHONY: lint
+lint: ## Verify code style and run static checks
+	go vet ./...
+	test -z $(gofmt -l ./...)
+
+.PHONY: fmt
+fmt: ## Run syntax re-formatting (modify in place)
+	go fmt ./...
+
+.PHONY: check
+check: ## Compile everything, checking syntax (does not output binaries)
+	go build ./...
+
+.env:
+	if [ ! -f ".env" ]; then cp example.dev.env .env; fi
+
+.PHONY: run-dev-bskyweb
+run-dev-bskyweb: .env ## Runs 'bskyweb' for local dev
+	GOLOG_LOG_LEVEL=info go run ./cmd/bskyweb serve
diff --git a/bskyweb/README.md b/bskyweb/README.md
index 2c381495f..a74cda0d5 100644
--- a/bskyweb/README.md
+++ b/bskyweb/README.md
@@ -24,7 +24,7 @@ Then build and copy over the big 'ol `bundle.web.js` file:
 
 ### Golang Daemon
 
-Install golang. We are generally using v1.19+.
+Install golang. We are generally using v1.20+.
 
 In this directory (`bskyweb/`):
 
diff --git a/bskyweb/cmd/bskyweb/main.go b/bskyweb/cmd/bskyweb/main.go
index fd1429902..8c0591954 100644
--- a/bskyweb/cmd/bskyweb/main.go
+++ b/bskyweb/cmd/bskyweb/main.go
@@ -3,8 +3,9 @@ package main
 import (
 	"os"
 
+	_ "github.com/joho/godotenv/autoload"
+
 	logging "github.com/ipfs/go-log"
-	"github.com/joho/godotenv"
 	"github.com/urfave/cli/v2"
 )
 
@@ -16,15 +17,6 @@ func init() {
 }
 
 func main() {
-
-	// only try dotenv if it exists
-	if _, err := os.Stat(".env"); err == nil {
-		err := godotenv.Load()
-		if err != nil {
-			log.Fatal("Error loading .env file")
-		}
-	}
-
 	run(os.Args)
 }
 
diff --git a/bskyweb/example.dev.env b/bskyweb/example.dev.env
new file mode 100644
index 000000000..921963b5e
--- /dev/null
+++ b/bskyweb/example.dev.env
@@ -0,0 +1,4 @@
+GOLOG_LOG_LEVEL=info
+ATP_PDS_HOST=http://localhost:2583
+ATP_AUTH_HANDLE="admin.test"
+ATP_AUTH_PASSWORD="admin"
diff --git a/bskyweb/go.mod b/bskyweb/go.mod
index f6e03f4fd..a81a74acf 100644
--- a/bskyweb/go.mod
+++ b/bskyweb/go.mod
@@ -1,6 +1,6 @@
 module github.com/bluesky-social/social-app/bskyweb
 
-go 1.19
+go 1.20
 
 require (
 	github.com/bluesky-social/indigo v0.0.0-20230307000525-294e33e70185