Skip to content

Commit 8b81c2c

Browse files
AleksanderWWWlexander023
andauthored
feat(ops, api): Prepare for the first release (#1)
* chore(ops): CI pipeline * more checks * update * update * fix * add readme * add license * probe duration metric * better pre-commit * test api * update * update * update * update * update * update --------- Co-authored-by: lexander023 <aleksander@scencei.com>
1 parent 21aa689 commit 8b81c2c

File tree

14 files changed

+523
-0
lines changed

14 files changed

+523
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build-and-push
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
build-and-push-image:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
13+
name: Checkout source code
14+
15+
- name: Log in to the Container registry
16+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
17+
with:
18+
registry: https://ghcr.io
19+
username: ${{ github.actor }}
20+
password: ${{ secrets.GHCR_TOKEN }}
21+
22+
- name: Build and push Docker image
23+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
24+
with:
25+
context: .
26+
push: true
27+
tags: ghcr.io/aleksanderwww/prometheus-gitlabci-exporter:"${GITHUB_REF#refs/tags/}"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
# Optional: allow read access to pull requests. Use with `only-new-issues` option.
11+
# pull-requests: read
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
19+
name: Checkout source code
20+
- uses: actions/setup-go@v6
21+
with:
22+
go-version: stable
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v8
25+
with:
26+
version: v2.1

.github/workflows/pre-commit.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
14+
name: Checkout source code
15+
16+
- name: Install Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.12"
20+
21+
- name: Run pre-commit
22+
uses: pre-commit/action@v3.0.1

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Upload Release Artifact
2+
3+
on:
4+
release:
5+
types: [published] # triggers when a new release is published
6+
7+
permissions:
8+
contents: write # required to upload assets to the release
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: "1.23"
22+
23+
- name: Build binary
24+
run: |
25+
mkdir -p dist
26+
go build -ldflags="-s -w" -o dist/prometheus_gitlabci_exporter .
27+
28+
- name: Package binary
29+
run: |
30+
cd dist
31+
tar -czf prometheus_gitlabci_exporter-${{ github.event.release.tag_name }}.tar.gz prometheus_gitlabci_exporter
32+
ls -lh
33+
34+
- name: Upload artifact to release
35+
uses: softprops/action-gh-release@v2
36+
with:
37+
files: dist/prometheus_gitlabci_exporter-${{ github.event.release.tag_name }}.tar.gz
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: static-checks
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
lint-dockerfile:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
16+
17+
- name: Lint Dockerfile (hadolint)
18+
run: |
19+
docker run --rm -i ghcr.io/hadolint/hadolint:v2.12.1-beta-debian < Dockerfile
20+
working-directory: .
21+
22+
run-actionlint:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
# needed for the checkout action
26+
contents: read
27+
# needed to annotate the files in a pull request with comments
28+
pull-requests: write
29+
steps:
30+
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
31+
32+
- uses: devops-actions/actionlint@c6744a34774e4e1c1df0ff66bdb07ec7ee480ca0
33+
34+
check-pr-title:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Check PR title
38+
env:
39+
PR_TITLE: ${{ github.event.pull_request.title }}
40+
run: |
41+
echo "Checking PR title: $PR_TITLE"
42+
43+
# Define the regex for Conventional Commits
44+
CONVENTIONAL_REGEX="^(feat|fix|chore|docs|style|refactor|perf|test|ci|build|revert|security)(\([^)]+\))?!?: .+$"
45+
46+
if [[ ! "$PR_TITLE" =~ $CONVENTIONAL_REGEX ]]; then
47+
echo "❌ PR title does not follow Conventional Commits format!"
48+
echo "📝 Expected format: 'type(scope): description'"
49+
echo "👉 Example: 'feat(auth): add login API'"
50+
exit 1
51+
fi
52+
53+
echo "✅ PR title is valid!"

.github/workflows/test-api.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: test-api
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test-api:
11+
name: test-api
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
15+
name: checkout source code
16+
17+
- run: |
18+
docker build -t localapi:0.1.0 .
19+
name: docker build
20+
shell: bash
21+
22+
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00
23+
with:
24+
go-version: stable
25+
26+
- run: |
27+
cid=$(docker run --rm -d -p 9115:9115 localapi:0.1.0)
28+
sleep 4
29+
go test -v
30+
docker stop "$cid"
31+
name: run tests against container
32+
env:
33+
TEST_HOST: http://localhost:9115/probe

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/dnephin/pre-commit-golang
3+
rev: v0.5.1
4+
hooks:
5+
- id: go-vet
6+
- id: go-build
7+
- id: go-mod-tidy
8+
- repo: local
9+
hooks:
10+
- id: go-fmt
11+
name: go-fmt
12+
entry: bash -c "go fmt ./..."
13+
language: system
14+
types: [go]
15+
pass_filenames: false
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.3.0
18+
hooks:
19+
- id: end-of-file-fixer
20+
- id: trailing-whitespace
21+
- id: check-added-large-files
22+
- id: check-case-conflict
23+
- id: check-merge-conflict
24+
- id: check-yaml
25+
- id: end-of-file-fixer

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Stage 1: build
2+
FROM golang:1.25.1@sha256:d7098379b7da665ab25b99795465ec320b1ca9d4addb9f77409c4827dc904211 AS builder
3+
4+
WORKDIR /app
5+
6+
# Cache dependency installation
7+
COPY go.mod go.sum ./
8+
RUN go mod download
9+
10+
COPY exporter/ ./exporter/
11+
COPY main.go .
12+
13+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o prom_exporter .
14+
15+
# Stage 2: runtime (as non-root user)
16+
FROM gcr.io/distroless/base-debian12:nonroot@sha256:10136f394cbc891efa9f20974a48843f21a6b3cbde55b1778582195d6726fa85
17+
18+
WORKDIR /app
19+
20+
COPY --from=builder /app/prom_exporter .
21+
22+
ENTRYPOINT ["/app/prom_exporter"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Aleksander Wojnarowicz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)