Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 82 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: Test

on:
push:
pull_request:
branches:
- main

permissions:
contents: read
statuses: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -15,7 +21,81 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
go-version: "1.25"

- name: Run tests
run: make test
run: make test coverage-test

- name: Extract coverage percentage
id: coverage
run: |
COVERAGE="$(awk '/^total:/{print $3}' build/coverage.txt | tr -d '%')"
echo "coverage=${COVERAGE}" >> "$GITHUB_OUTPUT"

- name: Publish coverage summary
if: always()
run: |
echo "## Test Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Total: **${{ steps.coverage.outputs.coverage }}%**" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`text" >> "$GITHUB_STEP_SUMMARY"
tail -n 20 build/coverage.txt >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"

- name: Set commit coverage status
if: always() && steps.coverage.outputs.coverage != ''
uses: actions/github-script@v7
env:
COVERAGE: ${{ steps.coverage.outputs.coverage }}
with:
script: |
const sha = context.payload.pull_request?.head?.sha || context.sha;
const state = '${{ job.status }}' === 'success' ? 'success' : 'failure';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha,
state,
context: 'go-pg/coverage',
description: `Coverage ${process.env.COVERAGE}%`,
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});

- name: Comment coverage on pull request
if: always() && github.event_name == 'pull_request' && steps.coverage.outputs.coverage != ''
uses: actions/github-script@v7
env:
COVERAGE: ${{ steps.coverage.outputs.coverage }}
with:
script: |
const body = [
'<!-- go-pg-coverage -->',
`Coverage for this change: **${process.env.COVERAGE}%**`,
].join('\n');

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const previous = comments.find(c =>
c.user?.type === 'Bot' && c.body?.includes('<!-- go-pg-coverage -->')
);

if (previous) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previous.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
80 changes: 47 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,51 @@
GO ?= $(shell which go 2>/dev/null)
DOCKER ?= $(shell which docker 2>/dev/null)
WASMBUILD ?= $(shell which wasmbuild 2>/dev/null)
BUILDDIR ?= build
CMDDIR=$(wildcard cmd/*)

# Locations
BUILD_DIR ?= build
CMD_DIR := $(filter-out cmd/_%,$(wildcard cmd/*))

# Set OS and Architecture
ARCH ?= $(shell arch | tr A-Z a-z | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/')
OS ?= $(shell uname | tr A-Z a-z)
VERSION ?= $(shell git describe --tags --always | sed 's/^v//')

# Build flags
BUILD_MODULE = $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitSource=${BUILD_MODULE}
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitTag=$(shell git describe --tags --always)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitBranch=$(shell git name-rev HEAD --name-only --always)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitHash=$(shell git rev-parse HEAD)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GoBuildTime=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILD_FLAGS = -ldflags="-s -w ${BUILD_LD_FLAGS}"
# Set build flags
VERSION_PKG = "github.com/mutablelogic/go-server/pkg/version"
BUILD_LD_FLAGS += -X $(VERSION_PKG)/GitTag=$(shell git describe --tags --always)
BUILD_LD_FLAGS += -X $(VERSION_PKG)/GitBranch=$(shell git name-rev HEAD --name-only --always)
BUILD_FLAGS = -ldflags "-s -w ${BUILD_LD_FLAGS}"

# Docker
DOCKER_REPO ?= ghcr.io/mutablelogic/pgmanager
DOCKER_SOURCE ?= ${BUILD_MODULE}
DOCKER_SOURCE ?= $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
DOCKER_TAG = ${DOCKER_REPO}-${OS}-${ARCH}:${VERSION}

# All targets
all: tidy $(CMDDIR)
###############################################################################
# ALL

.PHONY: all
all: build

# Rules for building
.PHONY: $(CMDDIR)
$(CMDDIR): go-dep mkdir
@echo 'go build $@'
@rm -rf ${BUILDDIR}/$(shell basename $@)
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/$(shell basename $@) ./$@
###############################################################################
# BUILD

# Build the commands in the cmd directory
.PHONY: build
build: tidy $(CMD_DIR)

# Build pgmanager with embedded frontend
.PHONY: pgmanager
pgmanager: go-dep wasmbuild-dep tidy mkdir
@echo 'go generate frontend'
@$(GO) generate -tags frontend ./pkg/manager/httphandler/...
@echo 'go build cmd/pgmanager'
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/pgmanager ./cmd/pgmanager
$(CMD_DIR): go-dep mkdir
@echo Build command $(notdir $@) GOOS=${OS} GOARCH=${ARCH}
@GOOS=${OS} GOARCH=${ARCH} ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@) ./$@

# Build the docker image
.PHONY: docker
docker: docker-dep ${NPM_DIR}
@echo build docker image ${DOCKER_TAG} OS=${OS} ARCH=${ARCH} SOURCE=${DOCKER_SOURCE} VERSION=${VERSION}
@${DOCKER} build \
--tag ${DOCKER_TAG} \
--provenance=false \
--build-arg ARCH=${ARCH} \
--build-arg OS=${OS} \
--build-arg SOURCE=${DOCKER_SOURCE} \
Expand All @@ -65,17 +64,32 @@ docker-push: docker-dep
docker-version: docker-dep
@echo "tag=${VERSION}"

# Rules for testing
###############################################################################
# TEST

.PHONY: test
test: tidy
@echo 'running tests...'
@$(GO) test .
@$(GO) test ./pkg/...
test: unit-test coverage-test

.PHONY: unit-test
unit-test: go-dep
@echo Unit Tests
@${GO} test .
@${GO} test ./pgmanager/...
@${GO} test ./pkg/...

.PHONY: coverage-test
coverage-test: go-dep mkdir
@echo Test Coverage
@${GO} test -v -coverprofile ${BUILD_DIR}/coverprofile.out ./pkg/...
@${GO} tool cover -func ${BUILD_DIR}/coverprofile.out > ${BUILD_DIR}/coverage.txt

###############################################################################
# CLEAN

# Other rules
.PHONY: mkdir
mkdir:
@install -d $(BUILDDIR)
@install -d $(BUILD_DIR)

.PHONY: go-dep tidy
tidy:
Expand All @@ -85,7 +99,7 @@ tidy:
.PHONY: clean
clean: tidy
@echo 'clean'
@rm -fr $(BUILDDIR)
@rm -fr $(BUILD_DIR)
@$(GO) clean

###############################################################################
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
95 changes: 0 additions & 95 deletions cmd/pgmanager/connection.go

This file was deleted.

Loading
Loading