Skip to content

Commit e622f53

Browse files
committedJan 29, 2024
add GHA CI
1 parent a6f58e9 commit e622f53

16 files changed

+360
-81
lines changed
 

‎.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Created by .ignore support plugin (hsz.mobi)
22
.idea/
33
*.iml
4-
.git/
4+
.git/

‎.github/dependabot.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
reviewers:
8+
- "Hsn723"
9+
- package-ecosystem: "docker"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
reviewers:
14+
- "Hsn723"
15+
- package-ecosystem: "github-actions"
16+
directory: "/"
17+
schedule:
18+
interval: "daily"
19+
reviewers:
20+
- "Hsn723"

‎.github/mergify.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pull_request_rules:
2+
- name: Automatic merge
3+
conditions:
4+
- "#approved-reviews-by>=1"
5+
- "#review-requested=0"
6+
- "#changes-requested-reviews-by=0"
7+
actions:
8+
merge:
9+
method: squash
10+
- name: Automatic merge for dependabot
11+
conditions:
12+
- author~=^dependabot\[bot\]$
13+
- title~=^Bump [^\s]+ from ([\d]+)\.([\d]+)\..+ to \1\.
14+
actions:
15+
review:
16+
type: APPROVE
17+
merge:
18+
method: squash

‎.github/release.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
changelog:
2+
categories:
3+
- title: Breaking Changes
4+
labels:
5+
- breaking-change
6+
- title: New Features
7+
labels:
8+
- feature
9+
- title: Bug Fixes
10+
labels:
11+
- bug
12+
- title: Dependencies and Chore
13+
labels:
14+
- dependencies
15+
- title: Other Changes
16+
labels:
17+
- "*"

‎.github/workflows/main.yml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: main
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
tags-ignore:
7+
- '*'
8+
env:
9+
go-version: stable
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Setup Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: ${{ env.go-version }}
20+
- name: Build
21+
run: make build
22+
lint:
23+
name: Lint
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-python@v5
28+
- name: Setup Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: ${{ env.go-version }}
32+
- name: Lint
33+
run: make lint
34+
- name: Lint
35+
run: make lint
36+
test:
37+
name: Test
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- name: Setup Go
42+
uses: actions/setup-go@v5
43+
with:
44+
go-version: ${{ env.go-version }}
45+
- name: Test
46+
run: make test
47+
check-goreleaser-config:
48+
name: Check goreleaser.yml
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- name: Setup go
53+
uses: actions/setup-go@v5
54+
with:
55+
go-version: ${{ env.go-version }}
56+
- uses: goreleaser/goreleaser-action@v5
57+
with:
58+
version: latest
59+
args: check -f .goreleaser.yml
60+
dry-run:
61+
name: Dry-run release
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
- uses: docker/setup-qemu-action@v3
69+
- uses: docker/setup-buildx-action@v3
70+
- uses: anchore/sbom-action/download-syft@v0.15.5
71+
- name: Setup go
72+
uses: actions/setup-go@v5
73+
with:
74+
go-version: ${{ env.go-version }}
75+
- name: Setup latest version tag
76+
run: |
77+
echo "GORELEASER_CURRENT_TAG=$(git describe --tags --abbrev=0 --match "v*" || echo v0.0.0)" >> $GITHUB_ENV
78+
- name: GoReleaser
79+
uses: goreleaser/goreleaser-action@v5
80+
with:
81+
version: latest
82+
args: --snapshot --skip=sign,publish --clean
83+
- name: Test built containers
84+
run: make container-structure-test
85+
tag:
86+
name: Tag release
87+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
88+
needs: [build, lint, check-goreleaser-config, test, dry-run]
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/checkout@v4
92+
with:
93+
token: ${{ secrets.PAT }}
94+
- name: Tag release
95+
run: |
96+
TAG="v$(cat VERSION)"
97+
git tag ${TAG}
98+
git push origin ${TAG} || true

‎.github/workflows/release.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- 'v[0-9]+.[0-9]+.[0-9]+'
6+
permissions:
7+
contents: write
8+
id-token: write
9+
packages: write
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
env:
14+
DOCKER_CLI_EXPERIMENTAL: "enabled"
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- uses: docker/setup-qemu-action@v3
21+
- uses: docker/setup-buildx-action@v3
22+
- uses: sigstore/cosign-installer@v3.3.0
23+
- uses: anchore/sbom-action/download-syft@v0.15.5
24+
- name: GHCR Login
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.repository_owner }}
29+
password: ${{ secrets.PAT }}
30+
- name: Setup go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: stable
34+
- name: GoReleaser
35+
uses: goreleaser/goreleaser-action@v5
36+
with:
37+
version: latest
38+
args: release --clean
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ postfix_exporter
1010

1111
*.iml
1212
vendor/
13+
dist/

‎.golangci.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
linters:
2+
enable:
3+
- dupl
4+
- ginkgolinter
5+
- gocheckcompilerdirectives
6+
- gocognit
7+
- goconst
8+
- gocyclo
9+
- godot
10+
- gofmt
11+
- revive
12+
- typecheck
13+
- unparam
14+
run:
15+
timeout: 5m
16+
linters-settings:
17+
revive:
18+
rules:
19+
- name: dot-imports
20+
disabled: true

‎.goreleaser.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
project_name: postfix_exporter
2+
before:
3+
hooks:
4+
- go mod download
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
flags:
9+
- -tags=nosystemd,nodocker
10+
goos:
11+
- linux
12+
goarch:
13+
- amd64
14+
- arm64
15+
dockers:
16+
- image_templates:
17+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-amd64"
18+
use: buildx
19+
dockerfile: Dockerfile
20+
extra_files:
21+
- LICENSE
22+
build_flag_templates:
23+
- "--platform=linux/amd64"
24+
- "--label=org.opencontainers.image.created={{.Date}}"
25+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
26+
- "--label=org.opencontainers.image.version={{.Version}}"
27+
- image_templates:
28+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-arm64"
29+
use: buildx
30+
goarch: arm64
31+
dockerfile: Dockerfile
32+
extra_files:
33+
- LICENSE
34+
build_flag_templates:
35+
- "--platform=linux/arm64"
36+
- "--label=org.opencontainers.image.created={{.Date}}"
37+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
38+
- "--label=org.opencontainers.image.version={{.Version}}"
39+
docker_manifests:
40+
- name_template: "ghcr.io/hsn723/{{.ProjectName}}:latest"
41+
image_templates:
42+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-amd64"
43+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-arm64"
44+
- name_template: "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}"
45+
image_templates:
46+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-amd64"
47+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-arm64"
48+
- name_template: "ghcr.io/hsn723/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}"
49+
image_templates:
50+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-amd64"
51+
- "ghcr.io/hsn723/{{.ProjectName}}:{{ .Version }}-arm64"
52+
checksum:
53+
name_template: 'checksums.txt'
54+
snapshot:
55+
name_template: "{{ .Tag }}-next"
56+
changelog:
57+
use: github-native
58+
source:
59+
enabled: true
60+
sboms:
61+
- id: archive
62+
artifacts: archive
63+
- id: source
64+
artifacts: source
65+
signs:
66+
- cmd: cosign
67+
certificate: '${artifact}.pem'
68+
args:
69+
- sign-blob
70+
- '--yes'
71+
- '--output-certificate=${certificate}'
72+
- '--output-signature=${signature}'
73+
- '${artifact}'
74+
artifacts: all
75+
output: true
76+
docker_signs:
77+
- cmd: cosign
78+
artifacts: all
79+
output: true
80+
args:
81+
- 'sign'
82+
- '--yes'
83+
- '${artifact}'

‎.pre-commit-config.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
default_stages: [commit]
2+
repos:
3+
- repo: https://github.com/golangci/golangci-lint
4+
rev: v1.55.2
5+
hooks:
6+
- id: golangci-lint
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.5.0
9+
hooks:
10+
- id: check-merge-conflict
11+
- id: check-yaml
12+
args: ["--allow-multiple-documents"]
13+
- id: end-of-file-fixer
14+
- id: mixed-line-ending
15+
args: ["--fix=lf"]

‎.travis.yml

-42
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.