Skip to content

Commit 9279e96

Browse files
authored
PMM-7602 Add github actions (#40)
* PMM-7602 Add github actions * PMM-7602 Fix group. * PMM-7602 Fix permitions. * PMM-7602 Fix paths. * PMM-7602 Fix env var. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Try to fix permitions. * PMM-7602 Fix go build tags.. * PMM-7602 Remove old version of postgress.
1 parent 142334c commit 9279e96

File tree

9 files changed

+1397
-27
lines changed

9 files changed

+1397
-27
lines changed

.github/workflows/go.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- v[0-9]+.[0-9]+.[0-9]+*
9+
pull_request:
10+
11+
jobs:
12+
test:
13+
name: Test
14+
strategy:
15+
matrix:
16+
go-version:
17+
- 1.15
18+
- 1.16
19+
postgresql-image:
20+
- postgres:10
21+
- postgres:11
22+
- postgres:12
23+
include:
24+
- go-version: tip
25+
os: ubuntu-latest
26+
postgresql-image: postgres:12
27+
may-fail: true
28+
runs-on: ubuntu-latest
29+
# The environment this job references
30+
environment:
31+
name: CI
32+
steps:
33+
- name: Set up Go release
34+
if: matrix.go-version != 'tip'
35+
uses: percona-platform/setup-go@v2
36+
with:
37+
go-version: ${{ matrix.go-version }}
38+
- name: Set up Go tip
39+
if: matrix.go-version == 'tip'
40+
env:
41+
# to avoid error due to `go version` accepting -v flag with an argument since 1.15
42+
GOFLAGS: ""
43+
run: |
44+
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
45+
cd $HOME/gotip/src
46+
./make.bash
47+
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
48+
echo "$HOME/gotip/bin" >> $GITHUB_PATH
49+
- name: Checkout code
50+
uses: percona-platform/checkout@v2
51+
- name: Run checks
52+
run: |
53+
go build -modfile=tools/go.mod -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
54+
go build -modfile=tools/go.mod -o bin/reviewdog github.com/reviewdog/reviewdog/cmd/reviewdog
55+
bin/golangci-lint run -c=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
56+
bin/golangci-lint run -c=.golangci.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
57+
- name: Run Tests
58+
run: |
59+
sudo chown 999:999 testdata/ssl/*
60+
sudo chmod 600 testdata/ssl/*
61+
docker-compose up -d
62+
make
63+
make test
64+
env:
65+
POSTGRESQL_IMAGE: ${{ matrix.postgresql-image }}
66+
- name: Run debug commands on failure
67+
if: ${{ failure() }}
68+
run: |
69+
env
70+
go version
71+
go env
72+
pwd
73+
git status
74+
docker --version
75+
docker-compose --version
76+
docker-compose logs

.promu.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ repository:
33
build:
44
flags: -a -tags netgo
55
ldflags: |
6-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
7-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
8-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
9-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
10-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
6+
-X github.com/prometheus/common/version.Version={{.Version}}
7+
-X github.com/prometheus/common/version.Revision={{.Revision}}
8+
-X github.com/prometheus/common/version.Branch={{.Branch}}
9+
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
10+
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
1111
tarball:
1212
files:
1313
- LICENSE

Makefile

+9-19
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414
GO ?= go
1515
GOFMT ?= $(GO)fmt
1616
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
17-
PROMU := $(FIRST_GOPATH)/bin/promu
18-
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
19-
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
17+
PROMU := bin/promu
18+
STATICCHECK := bin/staticcheck
2019
pkgs = ./...
2120

2221
PREFIX ?= $(shell pwd)
2322
BIN_DIR ?= $(shell pwd)
2423
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
2524
DOCKER_IMAGE_NAME ?= postgres-exporter
2625

27-
all: vet style staticcheck unused build test
26+
all: vet style staticcheck build test
2827

2928
style:
3029
@echo ">> checking code style"
31-
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
30+
! $(GOFMT) -d $$(find . -name '*.go' -print) | grep '^'
3231

3332
check_license:
3433
@echo ">> checking license header"
35-
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
34+
@licRes=$$(for file in $$(find . -type f -iname '*.go') ; do \
3635
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
3736
done); \
3837
if [ -n "$${licRes}" ]; then \
@@ -58,11 +57,8 @@ vet:
5857

5958
staticcheck: $(STATICCHECK)
6059
@echo ">> running staticcheck"
61-
$(STATICCHECK) $(pkgs)
62-
63-
unused: $(GOVENDOR)
64-
@echo ">> running check for unused packages"
65-
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
60+
GOOS= GOARCH= $(GO) build -modfile=tools/go.mod -o bin/staticcheck honnef.co/go/tools/cmd/staticcheck
61+
bin/staticcheck $(pkgs)
6662

6763
build: promu
6864
@echo ">> building binaries"
@@ -77,12 +73,6 @@ docker:
7773
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
7874

7975
promu:
80-
GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
81-
82-
$(FIRST_GOPATH)/bin/staticcheck:
83-
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
84-
85-
$(FIRST_GOPATH)/bin/govendor:
86-
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
76+
GOOS= GOARCH= $(GO) build -modfile=tools/go.mod -o bin/promu github.com/prometheus/promu
8777

88-
.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor
78+
.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck bin/staticcheck

cmd/postgres_exporter/pg_setting_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !integration
12
// +build !integration
23

34
package main

cmd/postgres_exporter/postgres_exporter_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !integration
12
// +build !integration
23

34
package main

docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ services:
1515
container_name: postgres_exporter_postgresql-ssl
1616
command: >
1717
-c ssl=on
18-
-c ssl_cert_file=/var/lib/postgresql/ssl/server.crt
19-
-c ssl_key_file=/var/lib/postgresql/ssl/server.key
18+
-c ssl_cert_file=/ssl/server.crt
19+
-c ssl_key_file=/ssl/server.key
2020
-c log_min_messages=DEBUG4
2121
ports:
2222
- 127.0.0.1:5433:5432
2323
environment:
2424
- POSTGRES_USER=root
2525
- POSTGRES_PASSWORD=root
2626
volumes:
27-
- ./testdata/ssl:/var/lib/postgresql/ssl
27+
- ./testdata/ssl:/ssl

tools/go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/percona/postgres_exporter/tools
2+
3+
go 1.16
4+
5+
require (
6+
github.com/golangci/golangci-lint v1.40.1
7+
github.com/prometheus/promu v0.12.0
8+
github.com/reviewdog/reviewdog v0.11.0
9+
honnef.co/go/tools v0.1.4
10+
)

0 commit comments

Comments
 (0)