Skip to content

Commit 76f2e0a

Browse files
committed
add test ci work flow
1 parent 4176278 commit 76f2e0a

File tree

6 files changed

+210
-17
lines changed

6 files changed

+210
-17
lines changed

.github/workflows/release.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # 匹配 v1.0.2 格式的标签
7+
8+
permissions:
9+
contents: write # 需要写权限来创建 release
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # 需要完整的 git 历史来生成 changelog
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: 'go.mod'
24+
cache: true
25+
26+
- name: Run GoReleaser
27+
uses: goreleaser/goreleaser-action@v6
28+
with:
29+
distribution: goreleaser
30+
version: latest
31+
args: release --clean
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Upload artifacts
36+
uses: actions/upload-artifact@v4
37+
if: always()
38+
with:
39+
name: dist
40+
path: dist/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Test Release
2+
3+
on:
4+
workflow_dispatch: # 允许手动触发
5+
pull_request:
6+
paths:
7+
- '.goreleaser.yml'
8+
- '.github/workflows/release.yaml'
9+
- '.github/workflows/test-release.yaml'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: 'go.mod'
27+
cache: true
28+
29+
- name: Test GoReleaser config
30+
uses: goreleaser/goreleaser-action@v6
31+
with:
32+
distribution: goreleaser
33+
version: latest
34+
args: check
35+
36+
- name: Build snapshot
37+
uses: goreleaser/goreleaser-action@v6
38+
with:
39+
distribution: goreleaser
40+
version: latest
41+
args: release --snapshot --clean --skip=publish
42+
43+
- name: List artifacts
44+
run: |
45+
echo "Generated artifacts:"
46+
ls -lh dist/*.tar.gz || true
47+
echo ""
48+
echo "Checksums:"
49+
cat dist/checksums.txt || true

.goreleaser.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
version: 2
2+
3+
env:
4+
- CGO_ENABLED=0
5+
6+
before:
7+
hooks:
8+
- go mod download
9+
- go mod tidy
10+
11+
builds:
12+
- id: pg_exporter
13+
main: ./main.go
14+
binary: pg_exporter
15+
goos:
16+
- linux
17+
- darwin
18+
goarch:
19+
- amd64
20+
- arm64
21+
goamd64:
22+
- v1 # 只使用基础 amd64,不生成 v2/v3/v4 变体
23+
ldflags:
24+
- -s -w
25+
- -extldflags "-static"
26+
- -X 'pg_exporter/exporter.Version={{.Version}}'
27+
- -X 'pg_exporter/exporter.Branch={{.Branch}}'
28+
- -X 'pg_exporter/exporter.Revision={{.ShortCommit}}'
29+
- -X 'pg_exporter/exporter.BuildDate={{.Date}}'
30+
flags:
31+
- -a
32+
33+
archives:
34+
- id: pg_exporter
35+
name_template: "{{ .ProjectName }}-{{ .Version }}.{{ .Os }}-{{ .Arch }}"
36+
files:
37+
- pg_exporter.yml
38+
- LICENSE
39+
- package/pg_exporter.default
40+
- package/pg_exporter.service
41+
# NFPMs configuration commented out for now - will be added in future iteration
42+
# nfpms:
43+
44+
checksum:
45+
name_template: 'checksums.txt'
46+
algorithm: sha256
47+
48+
snapshot:
49+
version_template: "{{ .Tag }}-next"
50+
51+
changelog:
52+
sort: asc
53+
filters:
54+
exclude:
55+
- '^docs:'
56+
- '^test:'
57+
- '^chore:'
58+
- Merge pull request
59+
- Merge branch
60+
61+
release:
62+
github:
63+
owner: pgsty
64+
name: pg_exporter
65+
draft: false
66+
prerelease: auto
67+
mode: replace
68+
name_template: "{{.ProjectName}}-v{{.Version}}"
69+
disable: false
70+
71+
# Docker builds are temporarily disabled
72+
# To build Docker images, use the existing docker/build.sh and docker/release.sh scripts
73+
# or uncomment and adjust the configuration below once a goreleaser-specific Dockerfile is created

Makefile

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#==============================================================#
22
# File : Makefile
3-
# Mtime : 2025-07-17
3+
# Mtime : 2025-08-14
44
# License : Apache-2.0 @ https://github.com/pgsty/pg_exporter
55
# Copyright : 2018-2025 Ruohang Feng / Vonng (rh@vonng.com)
66
#==============================================================#
@@ -46,36 +46,36 @@ linux-amd64: clean build-linux-amd64
4646
rm -rf $(LINUX_AMD_DIR) && mkdir -p $(LINUX_AMD_DIR)
4747
nfpm package --packager rpm --config package/nfpm-amd64-rpm.yaml --target dist/$(VERSION)
4848
nfpm package --packager deb --config package/nfpm-amd64-deb.yaml --target dist/$(VERSION)
49-
cp -r pg_exporter $(LINUX_AMD_DIR)/pg_exporter
50-
cp -f pg_exporter.yml $(LINUX_AMD_DIR)/pg_exporter.yml
51-
cp -f LICENSE $(LINUX_AMD_DIR)/LICENSE
49+
cp pg_exporter $(LINUX_AMD_DIR)/pg_exporter
50+
cp pg_exporter.yml $(LINUX_AMD_DIR)/pg_exporter.yml
51+
cp LICENSE $(LINUX_AMD_DIR)/LICENSE
5252
tar -czf dist/$(VERSION)/pg_exporter-$(VERSION).linux-amd64.tar.gz -C dist/$(VERSION) pg_exporter-$(VERSION).linux-amd64
5353
rm -rf $(LINUX_AMD_DIR)
5454

5555
linux-arm64: clean build-linux-arm64
5656
rm -rf $(LINUX_ARM_DIR) && mkdir -p $(LINUX_ARM_DIR)
5757
nfpm package --packager rpm --config package/nfpm-arm64-rpm.yaml --target dist/$(VERSION)
5858
nfpm package --packager deb --config package/nfpm-arm64-deb.yaml --target dist/$(VERSION)
59-
cp -r pg_exporter $(LINUX_ARM_DIR)/pg_exporter
60-
cp -f pg_exporter.yml $(LINUX_ARM_DIR)/pg_exporter.yml
61-
cp -f LICENSE $(LINUX_ARM_DIR)/LICENSE
59+
cp pg_exporter $(LINUX_ARM_DIR)/pg_exporter
60+
cp pg_exporter.yml $(LINUX_ARM_DIR)/pg_exporter.yml
61+
cp LICENSE $(LINUX_ARM_DIR)/LICENSE
6262
tar -czf dist/$(VERSION)/pg_exporter-$(VERSION).linux-arm64.tar.gz -C dist/$(VERSION) pg_exporter-$(VERSION).linux-arm64
6363
rm -rf $(LINUX_ARM_DIR)
6464

6565
release-darwin: darwin-amd64 darwin-arm64
6666
darwin-amd64: clean build-darwin-amd64
6767
rm -rf $(DARWIN_AMD_DIR) && mkdir -p $(DARWIN_AMD_DIR)
68-
cp -r pg_exporter $(DARWIN_AMD_DIR)/pg_exporter
69-
cp -f pg_exporter.yml $(DARWIN_AMD_DIR)/pg_exporter.yml
70-
cp -f LICENSE $(DARWIN_AMD_DIR)/LICENSE
68+
cp pg_exporter $(DARWIN_AMD_DIR)/pg_exporter
69+
cp pg_exporter.yml $(DARWIN_AMD_DIR)/pg_exporter.yml
70+
cp LICENSE $(DARWIN_AMD_DIR)/LICENSE
7171
tar -czf dist/$(VERSION)/pg_exporter-$(VERSION).darwin-amd64.tar.gz -C dist/$(VERSION) pg_exporter-$(VERSION).darwin-amd64
7272
rm -rf $(DARWIN_AMD_DIR)
7373

7474
darwin-arm64: clean build-darwin-arm64
7575
rm -rf $(DARWIN_ARM_DIR) && mkdir -p $(DARWIN_ARM_DIR)
76-
cp -r pg_exporter $(DARWIN_ARM_DIR)/pg_exporter
77-
cp -f pg_exporter.yml $(DARWIN_ARM_DIR)/pg_exporter.yml
78-
cp -f LICENSE $(DARWIN_ARM_DIR)/LICENSE
76+
cp pg_exporter $(DARWIN_ARM_DIR)/pg_exporter
77+
cp pg_exporter.yml $(DARWIN_ARM_DIR)/pg_exporter.yml
78+
cp LICENSE $(DARWIN_ARM_DIR)/LICENSE
7979
tar -czf dist/$(VERSION)/pg_exporter-$(VERSION).darwin-arm64.tar.gz -C dist/$(VERSION) pg_exporter-$(VERSION).darwin-arm64
8080
rm -rf $(DARWIN_ARM_DIR)
8181

@@ -99,6 +99,37 @@ release-dir:
9999
release-clean:
100100
rm -rf dist/$(VERSION)
101101

102+
###############################################################
103+
# GoReleaser #
104+
###############################################################
105+
# Install goreleaser if not present
106+
goreleaser-install:
107+
@which goreleaser > /dev/null || (echo "Installing goreleaser..." && go install github.com/goreleaser/goreleaser/v2@latest)
108+
109+
# Build snapshot release (without publishing)
110+
goreleaser-snapshot: goreleaser-install
111+
goreleaser release --snapshot --clean --skip=publish
112+
113+
# Build release locally (without git tag)
114+
goreleaser-build: goreleaser-install
115+
goreleaser build --snapshot --clean
116+
117+
# Build release locally without snapshot suffix (requires clean git)
118+
goreleaser-local: goreleaser-install
119+
goreleaser release --clean --skip=publish
120+
121+
# Release with goreleaser (requires git tag)
122+
goreleaser-release: goreleaser-install
123+
goreleaser release --clean
124+
125+
# Check goreleaser configuration
126+
goreleaser-check: goreleaser-install
127+
goreleaser check
128+
129+
# New main release task using goreleaser
130+
release-new: goreleaser-release
131+
132+
102133
# build docker image
103134
docker: docker-build
104135
docker-build:
@@ -135,4 +166,5 @@ dev:
135166

136167
.PHONY: build clean build-darwin build-linux\
137168
release release-darwin release-linux release-windows docker docker-build docker-release \
138-
install uninstall debug curl upload
169+
install uninstall debug curl upload \
170+
goreleaser-install goreleaser-snapshot goreleaser-build goreleaser-release goreleaser-check release-new

docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The latest stable version of `pg_exporter` is [v1.0.2](https://github.com/pgsty/
3838

3939
- Build with Go 1.25.0 and latest dependencies
4040
- Dedicate website and homepage: https://exp.pgsty.com
41+
- Release with goreleaser
4142

4243
**Checksums**
4344

package/pg_exporter.service

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -*- mode: conf -*-
2-
31
[Unit]
42
Description=Prometheus exporter for PostgreSQL/Pgbouncer server metrics
5-
Documentation=https://github.com/pgsty/pg_exporter
3+
Documentation=https://exp.pgsty.com
64
After=network.target
75

86
[Service]

0 commit comments

Comments
 (0)