Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

# Go files
[*.go]
indent_style = tab
indent_size = 4

# YAML files
[*.{yml,yaml}]
indent_style = space
indent_size = 2

# JSON files
[*.json]
indent_style = space
indent_size = 2

# Makefile
[Makefile]
indent_style = tab

# Markdown files
[*.md]
trim_trailing_whitespace = false

# Shell scripts
[*.sh]
indent_style = space
indent_size = 2
49 changes: 49 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: 2
updates:
# Enable version updates for Go modules
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 10
reviewers:
- "Genaker"
labels:
- "dependencies"
- "go"
commit-message:
prefix: "chore(deps)"
include: "scope"

# Enable version updates for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 5
reviewers:
- "Genaker"
labels:
- "dependencies"
- "github-actions"
commit-message:
prefix: "chore(deps)"
include: "scope"

# Enable version updates for Docker
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 5
reviewers:
- "Genaker"
labels:
- "dependencies"
- "docker"
commit-message:
prefix: "chore(deps)"
include: "scope"
144 changes: 144 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: CI

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

permissions:
contents: read

jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: magento_test
MYSQL_USER: magento
MYSQL_PASSWORD: magento
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3

redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Verify dependencies
run: |
go mod download
go mod verify

- name: Run go fmt
run: |
fmt_output=$(gofmt -l .)
if [ -n "$fmt_output" ]; then
echo "The following files are not formatted:"
echo "$fmt_output"
exit 1
fi

- name: Run go vet
run: |
# vet individual packages since we have two main packages
go vet ./api/...
go vet ./cmd/...
go vet ./config/...
go vet ./core/...
go vet ./cron/...
go vet ./html/...
go vet ./model/...
go vet ./service/...

- name: Run tests
run: |
# Test individual packages since we have two main packages
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./api/... ./cmd/... ./config/... ./core/... ./cron/... ./html/... ./model/... ./service/...
env:
MYSQL_USER: magento
MYSQL_PASS: magento
MYSQL_HOST: localhost
MYSQL_PORT: 3306
MYSQL_DB: magento_test
REDIS_ADDR: localhost:6379
API_USER: admin
API_PASS: admin123

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt
flags: unittests
name: codecov-umbrella

build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Build server binary
run: go build -v -o magento magento.go

- name: Build CLI binary
run: go build -v -o cli cli.go

lint:
name: Lint
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=5m
62 changes: 62 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Security Scan

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
schedule:
- cron: '0 0 * * 0' # Run weekly on Sundays

permissions:
contents: read
security-events: write

jobs:
gosec:
name: Security Scan (gosec)
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: '-no-fail -fmt sarif -out results.sarif ./...'

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

dependency-check:
name: Dependency Vulnerability Scan
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Run govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
47 changes: 43 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool
*.out
coverage.txt
coverage.html

# Go workspace file
go.work
go.work.sum

# Dependency directories
vendor/

# Environment files
.env
.env.local
.env.*.local

# IDE specific files
.vscode/
.idea/
*.swp
*.swo
*~

# Build output
/magento
/cli
dist/
build/

# Application specific
var/*
*.log
*.log.*
*.log.*.*
*.log.*.*.*
*.log.*.*.*.*
*.log.*.*.*.*.*

# OS specific
.DS_Store
Thumbs.db
Loading