From e65fc49b8efb3cfc9502cce0541fe5e1c8fb1336 Mon Sep 17 00:00:00 2001 From: Rene Nochebuena Date: Sat, 12 Apr 2025 16:51:32 -0600 Subject: [PATCH] Add initial project setup with Go modules and CI/CD workflows This commit initializes the project with Go module support and a basic `StoneError` struct. It also introduces .gitignore, SonarQube configuration, and multiple CI/CD workflows for branch, tag, and protected branch scenarios to automate testing, static analysis, and builds. --- .gitea/workflows/ci-basic.yml | 50 ++++++++++++++++++++++++ .gitea/workflows/ci-protected.yml | 50 ++++++++++++++++++++++++ .gitea/workflows/ci-tag.yml | 43 +++++++++++++++++++++ .gitignore | 64 +++++++++++++++++++++++++++++++ error.go | 13 +++++++ go.mod | 3 ++ sonar-project.properties | 10 +++++ 7 files changed, 233 insertions(+) create mode 100644 .gitea/workflows/ci-basic.yml create mode 100644 .gitea/workflows/ci-protected.yml create mode 100644 .gitea/workflows/ci-tag.yml create mode 100644 .gitignore create mode 100644 error.go create mode 100644 go.mod create mode 100644 sonar-project.properties diff --git a/.gitea/workflows/ci-basic.yml b/.gitea/workflows/ci-basic.yml new file mode 100644 index 0000000..b17134d --- /dev/null +++ b/.gitea/workflows/ci-basic.yml @@ -0,0 +1,50 @@ +name: Go CI/CD +run-name: ${{ github.actor }} is running CI/CD basic + +on: + push: + branches-ignore: + - main + - release/** + - develop + pull_request: + branches-ignore: + - main + - release/** + - develop + +jobs: + go-ci: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + + - name: Download dependencies + shell: bash + run: | + go mod tidy -x + + - name: Run tests + shell: bash + run: | + go test -json > test-report.out + go test -coverprofile=coverage.out + + - name: SonarQube Analysis + uses: SonarSource/sonarqube-scan-action@v5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} + + - name: Build binary + shell: bash + run: | + go build ./... \ No newline at end of file diff --git a/.gitea/workflows/ci-protected.yml b/.gitea/workflows/ci-protected.yml new file mode 100644 index 0000000..35994eb --- /dev/null +++ b/.gitea/workflows/ci-protected.yml @@ -0,0 +1,50 @@ +name: Go CI/CD +run-name: ${{ github.actor }} is running CI/CD protected + +on: + push: + branches: + - main + - release/** + - develop + pull_request: + branches: + - main + - release/** + - develop + +jobs: + go-ci: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + + - name: Download dependencies + shell: bash + run: | + go mod tidy -x + + - name: Run tests + shell: bash + run: | + go test -json > test-report.out + go test -coverprofile=coverage.out + + - name: SonarQube Analysis + uses: SonarSource/sonarqube-scan-action@v5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} + + - name: Build binary + shell: bash + run: | + go build ./... \ No newline at end of file diff --git a/.gitea/workflows/ci-tag.yml b/.gitea/workflows/ci-tag.yml new file mode 100644 index 0000000..7fcf0ea --- /dev/null +++ b/.gitea/workflows/ci-tag.yml @@ -0,0 +1,43 @@ +name: Go CI/CD +run-name: ${{ github.actor }} is running CI/CD Tag + +on: + push: + tags: + - '*' + +jobs: + go-ci: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + + - name: Download dependencies + shell: bash + run: | + go mod tidy -x + + - name: Run tests + shell: bash + run: | + go test -json > test-report.out + go test -coverprofile=coverage.out + + - name: SonarQube Analysis + uses: SonarSource/sonarqube-scan-action@v5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} + + - name: Build binary + shell: bash + run: | + go build ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a820c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,64 @@ +# Binaries for programs and plugins +bin +*.exe +*.dll +*.so +*.dylib +*.test + +# Output of the 'go tool cover' command +*.out +coverage.xml +test-report.xml + +# Directory for Go modules +/vendor/ + +# Go workspace file +go.work +go.work.sum + +# Editor configs +*.swp +*.swo +*.bak +*.tmp +*.log +*.viminfo +*.un~ +Session.vim + +# JetBrains Rider specific +.idea/ +*.iml +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/shelf/ + +# Sublime Text specific +*.sublime-workspace +*.sublime-project + +# VSCode specific +.vscode/ +.vscode/settings.json +.vscode/tasks.json +.vscode/launch.json + +# Emacs specific +*~ +\#*\# +.#* + +# MacOS specific +.DS_Store +.AppleDouble +.LSOverride + +# Node modules (in case of tools/scripts) +node_modules/ + +# Python virtual environments (for dev tools/scripts) +venv/ +*.pyc +__pycache__/ \ No newline at end of file diff --git a/error.go b/error.go new file mode 100644 index 0000000..208d409 --- /dev/null +++ b/error.go @@ -0,0 +1,13 @@ +package stoneerror + +import ( + "time" +) + +type StoneError struct { + Code int `json:"code"` + Message string `json:"message"` + Time time.Time `json:"time"` + Metadata map[string]interface{} `json:"metadata"` + Err error `json:"-"` +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5dfdcc5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module stoneerror + +go 1.24 diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..24edbac --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,10 @@ +sonar.projectKey=f91c1ade-619a-4d18-b7c9-5143b0c7bd47 +sonar.projectName=stone-utils/stoneerror +sonar.language=go +sonar.sources=. +sonar.exclusions=**/*_test.go +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.tests.reportPaths=test-report.out +sonar.go.coverage.reportPaths=coverage.out +sonar.qualitygate.wait=true \ No newline at end of file