Skip to content

Commit f5d6a8e

Browse files
committed
refine README.md, separate the CICD manuals into more isolated pages
1 parent 39f3e50 commit f5d6a8e

File tree

5 files changed

+305
-148
lines changed

5 files changed

+305
-148
lines changed

.golangci.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,5 @@ run:
33

44
linters:
55
enable:
6-
- gofmt
7-
- goimports
8-
- govet
9-
- errcheck
10-
- staticcheck
11-
- unused
12-
- gosec
13-
- revive
14-
15-
linters-settings:
16-
gocyclo:
17-
min-complexity: 15
18-
19-
revive:
20-
severity: warning
21-
22-
issues:
23-
exclude-rules:
24-
- path: _test\.go
25-
linters:
26-
- errcheck
27-
- gosec
6+
- goimports # Handles formatting and import organization
7+
- govet # Basic static analysis for common bugs

README.md

Lines changed: 19 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -6,143 +6,34 @@ For each problem, I focus on the thought process rather than providing a full, f
66

77
Solutions may not be optimal, but they serve as a starting point for further improvement and learning.
88

9-
# CI/CD setup
9+
# CI/CD Setup
1010

11-
This repository uses GitHub Actions for automated testing with a **modular workflow architecture**. Instead of putting everything in one large workflow file, we separate concerns into multiple focused workflows:
11+
This repository uses GitHub Actions with a **modular workflow architecture** for automated testing, code quality checks, security scanning, and builds.
1212

13-
## Workflow Architecture
13+
## Quick Overview
1414

15-
### **🧪 [test.yml](.github/workflows/test.yml)** - Testing
16-
- Unit tests with `go test -v`
17-
- Race condition detection with `-race` flag
18-
- Coverage reporting
15+
- **🧪 [test.yml](.github/workflows/test.yml)** - Unit tests and race detection
16+
- **[code-quality.yml](.github/workflows/code-quality.yml)** - Linting and formatting
17+
- **🔒 [security.yml](.github/workflows/security.yml)** - Vulnerability scanning
18+
- **🏗️ [build.yml](.github/workflows/build.yml)** - Cross-platform compilation
1919

20-
### **[code-quality.yml](.github/workflows/code-quality.yml)** - Code Standards
21-
- Comprehensive linting via `golangci-lint` (includes formatting, static analysis, style checks)
22-
- Configured via [`.golangci.yml`](.golangci.yml) with 8 essential linters
23-
- Single unified tool for all code quality checks
20+
TODO: releasing workflow needed to be built
2421

25-
### **🔒 [security.yml](.github/workflows/security.yml)** - Security
26-
- Vulnerability scanning (`govulncheck`)
27-
- Dependency security analysis
22+
All workflows trigger on pushes to `main`/`develop` and pull requests to `main`.
2823

29-
### **🏗️ [build.yml](.github/workflows/build.yml)** - Cross-compilation
30-
- Linux x64, Windows x64, macOS x64/ARM64 builds
31-
- Ensures code compiles across platforms
24+
## Documentation
3225

33-
## Benefits of Separation
26+
📖 **Detailed documentation available in [`docs/`](docs/):**
3427

35-
**🎯 Single Responsibility**: Each workflow has one clear purpose
36-
**⚡ Parallel Execution**: All workflows run simultaneously for faster feedback
37-
**🔧 Easy Maintenance**: Modify one aspect without affecting others
38-
**📊 Clear GitHub UI**: Each appears as separate status check
39-
**👥 Team Scalability**: Different team members can own different workflows
28+
**🚀 START HERE FOR CICD USAGE:** [**Configuration Manual**](docs/configuration-manual.md) - Setup, customization, and troubleshooting
4029

41-
## Triggers
42-
All workflows trigger on:
43-
- **Pushes** to `main`/`develop` branches
44-
- **Pull requests** targeting `main` branch
30+
**Additional docs:**
31+
- [**Workflow Architecture**](docs/workflow-architecture.md) - How workflows are organized and why
32+
- [**CI/CD Concepts**](docs/cicd-concepts.md) - GitHub Actions fundamentals and best practices
4533

46-
## Auto-discovery
47-
Each workflow automatically finds and processes all directories containing `go.mod` files, making the setup scalable for multi-module repositories.
4834

49-
## Configuration
5035

51-
### Go Version Management
52-
To maintain consistency across all workflows, set up a repository variable:
53-
54-
1. Go to **Repository Settings****Secrets and variables****Actions****Variables** tab
55-
2. Create new variable: `GO_VERSION` with value `1.25.6` (or your desired version)
56-
3. All workflows reference this via `${{ vars.GO_VERSION }}`
57-
58-
This ensures **single source of truth** for Go version - change once in repository settings, applies everywhere automatically.
59-
60-
### Code Quality Configuration
61-
The [`.golangci.yml`](.golangci.yml) file configures which linters run and their behavior:
62-
63-
- **Essential linters**: `gofmt`, `goimports`, `govet`, `errcheck`, `staticcheck`, `unused`, `gosec`, `revive`
64-
- **Algorithm-friendly**: Allows reasonable complexity for coding problems
65-
- **Test exceptions**: Relaxed rules for test files
66-
- **Unified reporting**: All code quality issues in one place
67-
68-
Modify `.golangci.yml` to customize which checks run - no workflow changes needed!
69-
70-
**Configuration Reference:**
71-
- [golangci-lint Configuration Guide](https://golangci-lint.run/usage/configuration/)
72-
- [Available Linters](https://golangci-lint.run/usage/linters/)
73-
- [Example configurations](https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml)
74-
75-
76-
77-
# Notes on CI/CD
78-
79-
I only used gitlab before so this note will mention some reference to gitlab but still trying to offer the concept of how CI/CD is setup in github acitons.
80-
81-
Please also check [text](https://docs.github.com/en/actions/tutorials/build-and-test-code/go) where it has a good starting example for go.
82-
83-
## Key Concepts
84-
85-
**GitHub Actions Basics:**
86-
- **`uses`**: Runs pre-built actions instead of custom shell commands, good to check in [text](https://github.com/marketplace?query=checkout&type=actions)
87-
- **`runs-on`**: Specifies what machine/VM to run the job on (like GitHub's free EC2)
88-
- **`actions/checkout@v4`**: Downloads repository source code to the runner like running clone - cd - checkout
89-
- **`.github/workflows/*.yml`**: GitHub's config location (vs GitLab's single `.gitlab-ci.yml`)
90-
91-
**Matrix Strategy (Parallel Jobs):**
92-
- **`strategy` + `matrix`**: Creates parallel jobs with different configurations (like GitLab's parallel:matrix)
93-
- **Cross-platform testing**: Simply use multiple OS runners (ubuntu/windows/macos)
94-
95-
**Caching (Speed Optimization):**
96-
- **`actions/cache@v4`**: Speeds up workflows by saving/restoring files between CI/CD runs
97-
- **`path`**: What directory/files to cache (~/go/pkg/mod for Go modules)
98-
- **`key`**: Unique identifier for the cache (includes OS, Go version, dependency hash)
99-
- **`restore-keys`**: Fallback cache keys to try if exact match not found
100-
- **Cache timing**: Restore happens on the step of actions/cache, save happens automatically at job end. go actions has its own caching mechanism, this repo use the custom cache just to show one of the machanism for caching.
101-
- **Cache fallback**: Uses partial matches when dependencies change incrementally, but still try to get the previous installed packages
102-
103-
**Go Commands:**
104-
- **`go test -v`**: Runs tests with verbose output showing individual test names
105-
- **`go build`**: Compiles Go source code into executables (compilation verification)
106-
- **`find . -name "go.mod" -execdir`**: Finds all Go modules and runs commands in their directories
107-
108-
## Best Practice: Workflow Separation
109-
110-
### **Anti-pattern: Monolithic Workflow**
111-
```yaml
112-
# DON'T: Everything in one job
113-
jobs:
114-
everything:
115-
steps:
116-
- name: Test
117-
- name: Lint
118-
- name: Security scan
119-
- name: Build
120-
- name: Deploy
121-
```
122-
123-
### ✅ **Best Practice: Modular Workflows**
124-
```yaml
125-
# DO: Separate files for different concerns
126-
.github/workflows/
127-
├── test.yml # Testing only
128-
├── code-quality.yml # Linting & formatting
129-
├── security.yml # Vulnerability scanning
130-
├── build.yml # Cross-compilation
131-
└── deploy.yml # Deployment (if needed)
132-
```
133-
134-
### **Why Separation Matters:**
135-
136-
1. **🚀 Faster Feedback**: Get quality issues immediately without waiting for all tests
137-
2. **🔄 Independent Scaling**: Add more test scenarios without affecting code quality checks
138-
3. **🎯 Focused Debugging**: When a workflow fails, you know exactly which aspect broke
139-
4. **👥 Team Ownership**: Different team members can maintain different workflows
140-
5. **📊 Better Metrics**: Track success rates for testing vs. code quality vs. security separately
141-
6. **🔧 Selective Execution**: Disable specific checks (e.g., security scanning) without affecting core testing
142-
143-
This modular approach follows the **Single Responsibility Principle** in CI/CD design, making your development process more maintainable and scalable.
144-
145-
## Local testing
36+
## Local Testing
14637

14738
To run tests locally for a specific problem:
14839

@@ -155,4 +46,6 @@ To run tests with race detection:
15546

15647
```bash
15748
go test -race -v ./...
158-
```
49+
```
50+
51+
For complete CI/CD setup instructions and concepts, see the [CI/CD documentation](docs/).

docs/cicd-concepts.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# CI/CD Concepts
2+
3+
This document explains key CI/CD concepts, particularly focusing on GitHub Actions compared to other systems like GitLab CI.
4+
5+
*Note: I only used GitLab before so this note will mention some reference to GitLab but still trying to offer the concept of how CI/CD is setup in GitHub Actions.*
6+
7+
Please also check [GitHub's Go tutorial](https://docs.github.com/en/actions/tutorials/build-and-test-code/go) where it has a good starting example for Go.
8+
9+
## GitHub Actions Basics
10+
11+
### Core Concepts
12+
13+
**Workflows vs Jobs vs Steps:**
14+
- **Workflow**: A complete CI/CD process defined in `.github/workflows/*.yml`
15+
- **Job**: A set of steps that run on the same runner machine
16+
- **Step**: Individual commands or actions within a job
17+
18+
**Key Components:**
19+
- **`uses`**: Runs pre-built actions instead of custom shell commands, good to check in [GitHub Marketplace](https://github.com/marketplace?query=checkout&type=actions)
20+
- **`runs-on`**: Specifies what machine/VM to run the job on (like GitHub's free EC2)
21+
- **`actions/checkout@v4`**: Downloads repository source code to the runner like running `git clone && cd repo && git checkout`
22+
- **`.github/workflows/*.yml`**: GitHub's config location (vs GitLab's single `.gitlab-ci.yml`)
23+
24+
### Comparison with GitLab CI (check only if you know gitlab)
25+
26+
| GitHub Actions | GitLab CI | Purpose |
27+
|----------------|-----------|---------|
28+
| `uses: actions/checkout@v4` | `git clone` (automatic) | Get source code |
29+
| `runs-on: ubuntu-latest` | `image: ubuntu:latest` | Specify runner |
30+
| `.github/workflows/` | `.gitlab-ci.yml` | Config location |
31+
| Multiple workflow files | Single config file | Organization |
32+
33+
## Caching (Speed Optimization)
34+
35+
Caching dramatically improves workflow performance by reusing dependencies between runs.
36+
37+
### How Caching Works
38+
39+
**Cache Lifecycle:**
40+
1. **Restore**: Happens during `actions/cache@v4` step
41+
2. **Use**: Cached files are available for the job
42+
3. **Save**: Happens automatically at job end
43+
44+
### Cache Configuration
45+
46+
```yaml
47+
- uses: actions/cache@v4
48+
with:
49+
path: ~/go/pkg/mod # What to cache
50+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} # Unique ID
51+
restore-keys: | # Fallback keys
52+
${{ runner.os }}-go-
53+
```
54+
55+
**Key Components:**
56+
- **`path`**: What directory/files to cache (e.g., `~/go/pkg/mod` for Go modules)
57+
- **`key`**: Unique identifier for the cache (includes OS, Go version, dependency hash)
58+
- **`restore-keys`**: Fallback cache keys to try if exact match not found
59+
60+
### Cache Strategy
61+
62+
**Exact Match**: Uses cached dependencies when `go.sum` hasn't changed
63+
**Partial Match**: Uses fallback when some dependencies change
64+
**Cache Miss**: Downloads all dependencies fresh (slowest)
65+
66+
**Note**: Go Actions has its own caching mechanism, this repo uses custom cache just to demonstrate one caching approach.
67+
68+
## Exit Codes and Failure Handling
69+
70+
### Understanding Exit Codes
71+
72+
**Success**: Exit code `0`
73+
- Step shows green checkmark ✓
74+
- Workflow continues
75+
76+
**Failure**: Exit code `1` (or any non-zero)
77+
- Step shows red X ✗
78+
- Workflow stops (unless configured otherwise)
79+
- Triggers failure notifications
80+
81+
### Tool Behavior Examples
82+
83+
| Tool | Success (Exit 0) | Failure (Exit 1) |
84+
|------|-----------------|-------------------|
85+
| `go test` | All tests pass | Any test fails |
86+
| `golangci-lint` | No issues found | Linting issues detected |
87+
| `govulncheck` | No vulnerabilities | Vulnerabilities found |
88+
| `go build` | Compilation successful | Compilation errors |
89+
90+
## Best Practices
91+
92+
### Workflow Organization
93+
94+
1. **Separate Concerns**: Different workflows for different purposes
95+
2. **Clear Naming**: Use descriptive job and step names
96+
97+
### Performance Optimization
98+
99+
1. **Use Caching**: Cache dependencies and build artifacts
100+
2. **Minimal Runners**: Use appropriate runner sizes (don't over-provision), they have all kinds of cost (money, and save some carbon output if you care!)
101+
102+
### ⚠️ Security Considerations
103+
104+
1. **Secrets Management**: Use GitHub Secrets for sensitive data
105+
2. **Dependency Scanning**: Regular vulnerability checks upon the packages you use, the vulnerability reports are maintained by trustworthy officials. For Go, this uses:
106+
- **Go Vulnerability Database**: https://vuln.go.dev/ - Official database maintained by Go security team
107+
- **Documentation fpr `govulncheck`**: https://go.dev/security/vuln/ - Go's official vulnerability management
108+
3. **Supply Chain Security**: Pin action versions (`@v4` not `@main`) and all dependencies, use specific version if you know that is more stable and meets the requirement rather than `@main` or `latest`!

0 commit comments

Comments
 (0)