Skip to content

Commit e4336fd

Browse files
guimoreirarclaude
andcommitted
feat: initial lib-sd implementation
Service discovery abstraction for Go backed by HashiCorp Consul. Includes Manager, Registry interface, Consul backend, config, and unit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0 parents  commit e4336fd

32 files changed

Lines changed: 2795 additions & 0 deletions

.githooks/commit-msg

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
#
3+
# Add a specific emoji to the end of the first line in every commit message
4+
# based on the conventional commits keyword.
5+
6+
if [ ! -f "$1" ] || grep -q "fixup!" "$1"; then
7+
# Exit if we didn't get a target file for some reason
8+
# or we have a fixup commit
9+
exit 0
10+
fi
11+
12+
KEYWORD=$(head -n 1 "$1" | awk '{print $1}' | sed -e 's/://')
13+
14+
case $KEYWORD in
15+
"feat"|"feat("*)
16+
EMOJI=":sparkles:"
17+
;;
18+
"fix"|"fix("*)
19+
EMOJI=":bug:"
20+
;;
21+
"docs"|"docs("*)
22+
EMOJI=":books:"
23+
;;
24+
"style"|"style("*)
25+
EMOJI=":gem:"
26+
;;
27+
"refactor"|"refactor("*)
28+
EMOJI=":hammer:"
29+
;;
30+
"perf"|"perf("*)
31+
EMOJI=":rocket:"
32+
;;
33+
"test"|"test("*)
34+
EMOJI=":rotating_light:"
35+
;;
36+
"build"|"build("*)
37+
EMOJI=":package:"
38+
;;
39+
"ci"|"ci("*)
40+
EMOJI=":construction_worker:"
41+
;;
42+
"chore"|"chore("*)
43+
EMOJI=":wrench:"
44+
;;
45+
*)
46+
EMOJI=""
47+
;;
48+
esac
49+
50+
MESSAGE=$(sed -E "1s/(.*)/\\1 $EMOJI/" <"$1")
51+
52+
echo "$MESSAGE" >"$1"

.githooks/pre-commit

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
source "$PWD"/pkg/shell/colors.sh
4+
source "$PWD"/pkg/shell/ascii.sh
5+
6+
branch=$(git rev-parse --abbrev-ref HEAD)
7+
8+
if [[ $branch == "main" || $branch == "develop" || $branch == release/* ]]; then
9+
echo "${bold}You can't commit directly to protected branches"
10+
exit 1
11+
fi
12+
13+
commit_msg_type_regex='feature|fix|refactor|style|test|docs|build'
14+
commit_msg_scope_regex='.{1,20}'
15+
commit_msg_description_regex='.{1,100}'
16+
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_description_regex})\$"
17+
merge_msg_regex="^Merge branch '.+'\$"
18+
19+
zero_commit="0000000000000000000000000000000000000000"
20+
21+
# Do not traverse over commits that are already in the repository
22+
excludeExisting="--not --all"
23+
24+
error=""
25+
while read oldrev newrev refname; do
26+
# branch or tag get deleted
27+
if [ "$newrev" = "$zero_commit" ]; then
28+
continue
29+
fi
30+
31+
# Check for new branch or tag
32+
if [ "$oldrev" = "$zero_commit" ]; then
33+
rev_span=$(git rev-list $newrev $excludeExisting)
34+
else
35+
rev_span=$(git rev-list $oldrev..$newrev $excludeExisting)
36+
fi
37+
38+
for commit in $rev_span; do
39+
commit_msg_header=$(git show -s --format=%s $commit)
40+
if ! [[ "$commit_msg_header" =~ (${commit_msg_regex})|(${merge_msg_regex}) ]]; then
41+
echo "$commit" >&2
42+
echo "ERROR: Invalid commit message format" >&2
43+
echo "$commit_msg_header" >&2
44+
error="true"
45+
fi
46+
done
47+
done
48+
49+
if [ -n "$error" ]; then
50+
exit 1
51+
fi

.githooks/pre-push

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
source "$PWD"/pkg/shell/colors.sh
4+
source "$PWD"/pkg/shell/ascii.sh
5+
6+
while read local_ref local_sha remote_ref remote_sha; do
7+
if [[ "$local_ref" =~ ^refs/heads/ ]]; then
8+
branch_name=$(echo "$local_ref" | sed 's|^refs/heads/||')
9+
10+
if [[ ! "$branch_name" =~ ^(feature|fix|hotfix|docs|refactor|build|test)/.*$ ]]; then
11+
echo "${bold}Branch names must start with 'feature/', 'fix/', 'refactor/', 'docs/', 'test/' or 'hotfix/' followed by either a task id or feature name."
12+
exit 1
13+
fi
14+
fi
15+
done
16+
17+
exit 0

.githooks/pre-receive

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
zero_commit="0000000000000000000000000000000000000000"
4+
5+
while read oldrev newrev refname; do
6+
7+
if [[ $oldrev == $zero_commit ]]; then
8+
continue
9+
fi
10+
11+
if [[ $refname == "refs/heads/main" && $newrev != $zero_commit ]]; then
12+
branch_name=$(basename $refname)
13+
14+
if [[ $branch_name == release/* ]]; then
15+
continue
16+
else
17+
echo "Error: You can only merge branches that start with 'release/' into the main branch."
18+
exit 1
19+
fi
20+
fi
21+
done

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
target-branch: "develop"

.github/pull_request_template.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Pull Request Checklist
2+
3+
## Pull Request Type
4+
[//]: # (Check the appropriate box for the type of pull request.)
5+
6+
- [ ] Pipeline
7+
- [ ] Tests
8+
- [ ] Documentation
9+
- [ ] Helm
10+
11+
## Checklist
12+
Please check each item after it's completed.
13+
14+
- [ ] I have tested these changes locally.
15+
- [ ] I have updated the documentation accordingly.
16+
- [ ] I have added necessary comments to the code, especially in complex areas.
17+
- [ ] I have ensured that my changes adhere to the project's coding standards.
18+
- [ ] I have checked for any potential security issues.
19+
- [ ] I have ensured that all tests pass.
20+
- [ ] I have updated the version appropriately (if applicable).
21+
- [ ] I have confirmed this code is ready for review.
22+
23+
## Additional Notes
24+
[//]: # (Add any additional notes, context, or explanation that could be helpful for reviewers.)
25+
## Obs: Please, always remember to target your PR to develop branch instead of main.

.github/workflows/check-branch.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Enforce Branch PR's from Develop"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- edited
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
check-branch:
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- uses: actions/create-github-app-token@v1
18+
id: app-token
19+
with:
20+
app-id: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
21+
private-key: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}
22+
23+
- name: Import GPG key
24+
uses: crazy-max/ghaction-import-gpg@v6
25+
id: import_gpg
26+
with:
27+
gpg_private_key: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY }}
28+
passphrase: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY_PASSWORD }}
29+
git_committer_name: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
30+
git_committer_email: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}
31+
git_config_global: true
32+
git_user_signingkey: true
33+
git_commit_gpgsign: true
34+
35+
- name: Check if PR is from develop or hotfix
36+
if: github.event.pull_request.head.ref != 'develop' && startsWith(github.event.pull_request.head.ref, 'hotfix/') == false
37+
env:
38+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
39+
GIT_AUTHOR_NAME: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
40+
GIT_AUTHOR_EMAIL: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}
41+
GIT_COMMITTER_NAME: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
42+
GIT_COMMITTER_EMAIL: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}
43+
run: |
44+
echo "Pull requests to main can only come from develop or hotfix branches."
45+
# Add a request for changes comment on the pull request
46+
curl -s -X POST \
47+
-H "Authorization: token $GITHUB_TOKEN" \
48+
-H "Content-Type: application/json" \
49+
-d '{"body": "Pull requests to **main** can only come from **develop** or **hotfix** branches. Please **change base**!!!", "event": "REQUEST_CHANGES"}' \
50+
"${{ github.event.pull_request.url }}/reviews"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Go Combined Analysis"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
- main
8+
types:
9+
- opened
10+
- edited
11+
- synchronize
12+
- reopened
13+
14+
permissions:
15+
id-token: write
16+
contents: read
17+
pull-requests: write
18+
actions: read
19+
security-events: write
20+
21+
#EXECUTE PRE-STEPS OF GOLANG VERIFICATION
22+
jobs:
23+
go-analysis:
24+
uses: LerianStudio/github-actions-go-pipeline-template/.github/workflows/analysis.yml@main
25+
secrets:
26+
lerian_studio_push_bot_app_id: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
27+
lerian_studio_push_bot_private_key: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}
28+
lerian_ci_cd_user_gpg_key: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY }}
29+
lerian_ci_cd_user_gpg_key_password: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY_PASSWORD }}
30+
lerian_ci_cd_user_name: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
31+
lerian_ci_cd_user_email: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
- hotfix/v*
9+
paths-ignore:
10+
- '.gitignore'
11+
- '**/*.env'
12+
- '*.env'
13+
- '**/*.md'
14+
- '*.md'
15+
- '**/*.txt'
16+
- '*.txt'
17+
tags-ignore:
18+
- '**'
19+
20+
permissions:
21+
id-token: write
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
# Publish release using the lerian-studio/github-actions-go-pipeline-template
27+
publish-release:
28+
uses: LerianStudio/github-actions-go-pipeline-template/.github/workflows/release.yml@main
29+
secrets:
30+
lerian_studio_push_bot_app_id: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
31+
lerian_studio_push_bot_private_key: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}
32+
lerian_ci_cd_user_gpg_key: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY }}
33+
lerian_ci_cd_user_gpg_key_password: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY_PASSWORD }}
34+
lerian_ci_cd_user_name: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
35+
lerian_ci_cd_user_email: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}
36+
37+
# Generate changelog with gptchangelog custom module
38+
generate_changelog:
39+
name: 📝 Generate AI-powered Changelog
40+
runs-on: ubuntu-22.04
41+
needs: publish-release
42+
steps:
43+
- uses: actions/create-github-app-token@v1
44+
id: app-token
45+
with:
46+
app-id: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
47+
private-key: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}
48+
49+
- uses: LerianStudio/github-actions-gptchangelog@main
50+
with:
51+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
52+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
LERIAN_CI_CD_USER_GPG_KEY: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY }}
55+
LERIAN_CI_CD_USER_GPG_KEY_PASSWORD: ${{ secrets.LERIAN_CI_CD_USER_GPG_KEY_PASSWORD }}
56+
LERIAN_CI_CD_USER_NAME: ${{ secrets.LERIAN_CI_CD_USER_NAME }}
57+
LERIAN_CI_CD_USER_EMAIL: ${{ secrets.LERIAN_CI_CD_USER_EMAIL }}
58+
LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
59+
LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env
26+
.idea
27+
.DS_Store
28+
.vscode
29+
scripts/node_modules
30+
.windsurf
31+
coverage.html
32+
artifacts/

0 commit comments

Comments
 (0)