Skip to content

Commit d9800db

Browse files
authored
Add new version of pgmanager (#47)
* Added new version of pgmanager * Adding connections * Added connection handlers * Updated connection metrics * Updates * Added extensions * Update extensions * Added schemas * Finished adding schema code * Added settings * Updated * Updated settings * Updated list * Updated to add roles * Updated roles * Added tablespaces * Added tablespace metrics * Added replication slots * Added statements * Updates * Added test coverage changes * Updates * Added statements * Updated statement * Added objects * Removed old version of manager * Updates * Updates
1 parent 2d74e0c commit d9800db

193 files changed

Lines changed: 4924 additions & 15104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
name: Test
22

33
on:
4+
push:
45
pull_request:
56
branches:
67
- main
78

9+
permissions:
10+
contents: read
11+
statuses: write
12+
pull-requests: write
13+
814
jobs:
915
test:
1016
runs-on: ubuntu-latest
@@ -15,7 +21,81 @@ jobs:
1521
- name: Set up Go
1622
uses: actions/setup-go@v5
1723
with:
18-
go-version: "1.24"
24+
go-version: "1.25"
1925

2026
- name: Run tests
21-
run: make test
27+
run: make test coverage-test
28+
29+
- name: Extract coverage percentage
30+
id: coverage
31+
run: |
32+
COVERAGE="$(awk '/^total:/{print $3}' build/coverage.txt | tr -d '%')"
33+
echo "coverage=${COVERAGE}" >> "$GITHUB_OUTPUT"
34+
35+
- name: Publish coverage summary
36+
if: always()
37+
run: |
38+
echo "## Test Coverage" >> "$GITHUB_STEP_SUMMARY"
39+
echo "" >> "$GITHUB_STEP_SUMMARY"
40+
echo "Total: **${{ steps.coverage.outputs.coverage }}%**" >> "$GITHUB_STEP_SUMMARY"
41+
echo "" >> "$GITHUB_STEP_SUMMARY"
42+
echo "\`\`\`text" >> "$GITHUB_STEP_SUMMARY"
43+
tail -n 20 build/coverage.txt >> "$GITHUB_STEP_SUMMARY"
44+
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
45+
46+
- name: Set commit coverage status
47+
if: always() && steps.coverage.outputs.coverage != ''
48+
uses: actions/github-script@v7
49+
env:
50+
COVERAGE: ${{ steps.coverage.outputs.coverage }}
51+
with:
52+
script: |
53+
const sha = context.payload.pull_request?.head?.sha || context.sha;
54+
const state = '${{ job.status }}' === 'success' ? 'success' : 'failure';
55+
await github.rest.repos.createCommitStatus({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
sha,
59+
state,
60+
context: 'go-pg/coverage',
61+
description: `Coverage ${process.env.COVERAGE}%`,
62+
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
63+
});
64+
65+
- name: Comment coverage on pull request
66+
if: always() && github.event_name == 'pull_request' && steps.coverage.outputs.coverage != ''
67+
uses: actions/github-script@v7
68+
env:
69+
COVERAGE: ${{ steps.coverage.outputs.coverage }}
70+
with:
71+
script: |
72+
const body = [
73+
'<!-- go-pg-coverage -->',
74+
`Coverage for this change: **${process.env.COVERAGE}%**`,
75+
].join('\n');
76+
77+
const { data: comments } = await github.rest.issues.listComments({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
issue_number: context.issue.number,
81+
});
82+
83+
const previous = comments.find(c =>
84+
c.user?.type === 'Bot' && c.body?.includes('<!-- go-pg-coverage -->')
85+
);
86+
87+
if (previous) {
88+
await github.rest.issues.updateComment({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
comment_id: previous.id,
92+
body,
93+
});
94+
} else {
95+
await github.rest.issues.createComment({
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
issue_number: context.issue.number,
99+
body,
100+
});
101+
}

Makefile

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,51 @@
22
GO ?= $(shell which go 2>/dev/null)
33
DOCKER ?= $(shell which docker 2>/dev/null)
44
WASMBUILD ?= $(shell which wasmbuild 2>/dev/null)
5-
BUILDDIR ?= build
6-
CMDDIR=$(wildcard cmd/*)
5+
6+
# Locations
7+
BUILD_DIR ?= build
8+
CMD_DIR := $(filter-out cmd/_%,$(wildcard cmd/*))
79

810
# Set OS and Architecture
911
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/')
1012
OS ?= $(shell uname | tr A-Z a-z)
1113
VERSION ?= $(shell git describe --tags --always | sed 's/^v//')
1214

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

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

27-
# All targets
28-
all: tidy $(CMDDIR)
26+
###############################################################################
27+
# ALL
28+
29+
.PHONY: all
30+
all: build
2931

30-
# Rules for building
31-
.PHONY: $(CMDDIR)
32-
$(CMDDIR): go-dep mkdir
33-
@echo 'go build $@'
34-
@rm -rf ${BUILDDIR}/$(shell basename $@)
35-
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/$(shell basename $@) ./$@
32+
###############################################################################
33+
# BUILD
34+
35+
# Build the commands in the cmd directory
36+
.PHONY: build
37+
build: tidy $(CMD_DIR)
3638

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

4543
# Build the docker image
4644
.PHONY: docker
4745
docker: docker-dep ${NPM_DIR}
4846
@echo build docker image ${DOCKER_TAG} OS=${OS} ARCH=${ARCH} SOURCE=${DOCKER_SOURCE} VERSION=${VERSION}
4947
@${DOCKER} build \
5048
--tag ${DOCKER_TAG} \
49+
--provenance=false \
5150
--build-arg ARCH=${ARCH} \
5251
--build-arg OS=${OS} \
5352
--build-arg SOURCE=${DOCKER_SOURCE} \
@@ -65,17 +64,32 @@ docker-push: docker-dep
6564
docker-version: docker-dep
6665
@echo "tag=${VERSION}"
6766

68-
# Rules for testing
67+
###############################################################################
68+
# TEST
69+
6970
.PHONY: test
70-
test: tidy
71-
@echo 'running tests...'
72-
@$(GO) test .
73-
@$(GO) test ./pkg/...
71+
test: unit-test coverage-test
72+
73+
.PHONY: unit-test
74+
unit-test: go-dep
75+
@echo Unit Tests
76+
@${GO} test .
77+
@${GO} test ./pgmanager/...
78+
@${GO} test ./pkg/...
79+
80+
.PHONY: coverage-test
81+
coverage-test: go-dep mkdir
82+
@echo Test Coverage
83+
@${GO} test -v -coverprofile ${BUILD_DIR}/coverprofile.out ./pkg/...
84+
@${GO} tool cover -func ${BUILD_DIR}/coverprofile.out > ${BUILD_DIR}/coverage.txt
85+
86+
###############################################################################
87+
# CLEAN
7488

7589
# Other rules
7690
.PHONY: mkdir
7791
mkdir:
78-
@install -d $(BUILDDIR)
92+
@install -d $(BUILD_DIR)
7993

8094
.PHONY: go-dep tidy
8195
tidy:
@@ -85,7 +99,7 @@ tidy:
8599
.PHONY: clean
86100
clean: tidy
87101
@echo 'clean'
88-
@rm -fr $(BUILDDIR)
102+
@rm -fr $(BUILD_DIR)
89103
@$(GO) clean
90104

91105
###############################################################################

cmd/pgmanager/connection.go

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)