class-metrix 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,318 @@
1
+ # Release Guide
2
+
3
+ This guide explains how to release new versions of the ClassMetrix gem.
4
+
5
+ ## 🚀 Quick Release
6
+
7
+ For a simple patch release:
8
+
9
+ ```bash
10
+ # Using the release script (recommended)
11
+ ./bin/release --type patch --push
12
+
13
+ # Or manually
14
+ ./bin/release --type patch
15
+ # Then follow the printed instructions to commit and push
16
+ ```
17
+
18
+ ## 📋 Prerequisites
19
+
20
+ Before creating a release, ensure you have:
21
+
22
+ 1. **RubyGems API Key**: Set up in GitHub repository secrets as `RUBYGEMS_API_KEY`
23
+ 2. **Slack Integration** (optional): Set up `SLACK_WEBHOOK_URL` for release notifications
24
+ 3. **Clean working directory**: All changes committed to `master` branch
25
+ 4. **Tests passing**: Run `bundle exec rake` to verify
26
+ 5. **Updated documentation**: Ensure README and docs are current
27
+
28
+ ## 🛠️ Release Process
29
+
30
+ ### 1. Using the Release Script (Recommended)
31
+
32
+ The `bin/release` script automates version bumping and changelog updates:
33
+
34
+ ```bash
35
+ # Patch release (0.1.0 → 0.1.1)
36
+ ./bin/release --type patch
37
+
38
+ # Minor release (0.1.0 → 0.2.0)
39
+ ./bin/release --type minor
40
+
41
+ # Major release (0.1.0 → 1.0.0)
42
+ ./bin/release --type major
43
+
44
+ # Dry run to see what would happen
45
+ ./bin/release --type patch --dry-run
46
+
47
+ # Automatic commit and push
48
+ ./bin/release --type patch --push
49
+ ```
50
+
51
+ ### 2. Manual Release Process
52
+
53
+ If you prefer to do it manually:
54
+
55
+ 1. **Update Version**:
56
+
57
+ ```ruby
58
+ # lib/class_metrix/version.rb
59
+ module ClassMetrix
60
+ VERSION = "0.1.1" # Increment appropriately
61
+ end
62
+ ```
63
+
64
+ 2. **Update CHANGELOG.md**:
65
+
66
+ ```markdown
67
+ ## [Unreleased]
68
+
69
+ ## [0.1.1] - 2024-01-15
70
+
71
+ ### Fixed
72
+
73
+ - Bug fixes and improvements
74
+ ```
75
+
76
+ 3. **Commit and Tag**:
77
+
78
+ ```bash
79
+ git add -A
80
+ git commit -m "Release v0.1.1"
81
+ git tag v0.1.1
82
+ git push origin master
83
+ git push origin v0.1.1
84
+ ```
85
+
86
+ ## 🤖 Automated Release Workflow
87
+
88
+ ### Release Triggers
89
+
90
+ The release workflow can be triggered in two ways:
91
+
92
+ 1. **Tag Push** (recommended): Push a version tag (e.g., `v0.1.1`)
93
+ 2. **Manual Dispatch**: Use GitHub Actions UI for manual releases
94
+
95
+ ### Tag-Based Release (Recommended)
96
+
97
+ When you push a tag (e.g., `v0.1.1`), GitHub Actions automatically:
98
+
99
+ 1. **Validates Release**: Checks version format and consistency
100
+ 2. **Runs Tests**: Comprehensive tests across Ruby 3.2 and 3.3
101
+ 3. **Security Scan**: Brakeman security analysis
102
+ 4. **Quality Check**: RuboCop code quality verification
103
+ 5. **Builds Gem**: Creates and tests the gem package
104
+ 6. **Publishes to RubyGems**: Uploads to the gem repository
105
+ 7. **Creates GitHub Release**: With installation instructions and links
106
+ 8. **Slack Notification**: Success/failure alerts to `#cicd-notifications`
107
+
108
+ ### Manual Release via GitHub Actions
109
+
110
+ For more control, use the manual release option:
111
+
112
+ 1. Go to **Actions** → **Release Gem** → **Run workflow**
113
+ 2. Enter the version number (e.g., `1.0.2`)
114
+ 3. Optionally enable **Dry run** to test without publishing
115
+ 4. Click **Run workflow**
116
+
117
+ ### Workflow Features
118
+
119
+ - **Version Validation**: Ensures semantic versioning format
120
+ - **Consistency Check**: Verifies tag matches `lib/class_metrix/version.rb`
121
+ - **Duplicate Protection**: Prevents releasing existing versions
122
+ - **Dry Run Mode**: Test releases without publishing
123
+ - **Rich Notifications**: Detailed Slack alerts with links and context
124
+ - **Artifact Storage**: Saves gem files for 90 days
125
+
126
+ ### Workflow Files
127
+
128
+ - **`.github/workflows/main.yml`**: CI pipeline for PRs and `master` pushes
129
+ - **`.github/workflows/release.yml`**: Release automation for tags and manual dispatch
130
+
131
+ ## 🔑 Required GitHub Secrets
132
+
133
+ ### Essential Secrets
134
+
135
+ 1. **`RUBYGEMS_API_KEY`** (Required):
136
+
137
+ ```bash
138
+ # Generate your API key
139
+ gem signin
140
+ # Get your API key from ~/.gem/credentials
141
+ ```
142
+
143
+ 2. **`SLACK_WEBHOOK_URL`** (Optional):
144
+ - Set up for release notifications
145
+ - See [Slack Integration Guide](./SLACK_INTEGRATION.md) for details
146
+
147
+ ### Adding Secrets to GitHub
148
+
149
+ 1. Go to your repository → **Settings** → **Secrets and variables** → **Actions**
150
+ 2. Click **New repository secret**
151
+ 3. Add the secret name and value
152
+ 4. Click **Add secret**
153
+
154
+ ## 📊 Release Checklist
155
+
156
+ ### Pre-Release Verification
157
+
158
+ - [ ] All tests pass (`bundle exec rake`)
159
+ - [ ] Security scan clean (`bundle exec brakeman`)
160
+ - [ ] Code quality good (`bundle exec rubocop`)
161
+ - [ ] Documentation is updated
162
+ - [ ] CHANGELOG.md reflects new changes
163
+ - [ ] Version is bumped appropriately in `lib/class_metrix/version.rb`
164
+ - [ ] No TODO items in gemspec
165
+ - [ ] Working on clean `master` branch
166
+
167
+ ### GitHub Configuration
168
+
169
+ - [ ] `RUBYGEMS_API_KEY` secret is configured
170
+ - [ ] `SLACK_WEBHOOK_URL` secret is configured (optional)
171
+ - [ ] Repository permissions allow workflow execution
172
+ - [ ] You have push permissions for the gem on RubyGems
173
+
174
+ ### Post-Release Verification
175
+
176
+ - [ ] Release appears on [RubyGems](https://rubygems.org/gems/class-metrix)
177
+ - [ ] GitHub Release was created with proper notes
178
+ - [ ] Slack notification received (if configured)
179
+ - [ ] Gem installs correctly: `gem install class-metrix -v X.X.X`
180
+
181
+ ## 🐛 Troubleshooting
182
+
183
+ ### Common Release Issues
184
+
185
+ #### Version Mismatch Error
186
+
187
+ ```
188
+ ❌ Version mismatch! Gemspec: 0.1.0, Release: 0.1.1
189
+ ```
190
+
191
+ **Solution**: Ensure the version in `lib/class_metrix/version.rb` matches your git tag exactly.
192
+
193
+ #### RubyGems Publishing Failed
194
+
195
+ **Possible causes**:
196
+
197
+ - `RUBYGEMS_API_KEY` secret is incorrect or expired
198
+ - You don't have push permissions for the gem
199
+ - The version already exists on RubyGems
200
+ - Network connectivity issues
201
+
202
+ **Solutions**:
203
+
204
+ 1. Regenerate and update the RubyGems API key
205
+ 2. Check gem ownership: `gem owner class-metrix`
206
+ 3. Verify version doesn't exist: `gem list class-metrix --remote`
207
+
208
+ #### GitHub Release Creation Failed
209
+
210
+ **Possible causes**:
211
+
212
+ - Insufficient repository permissions
213
+ - Tag already exists with different content
214
+ - Network issues
215
+
216
+ **Solutions**:
217
+
218
+ 1. Check repository permissions (usually automatic for `GITHUB_TOKEN`)
219
+ 2. Delete and recreate the tag if needed
220
+ 3. Re-run the workflow
221
+
222
+ #### Workflow Validation Errors
223
+
224
+ **Common issues**:
225
+
226
+ - Non-semantic version format
227
+ - Missing CHANGELOG entries
228
+ - Failing tests or security scans
229
+
230
+ **Solutions**:
231
+
232
+ 1. Use semantic versioning format: `X.Y.Z`
233
+ 2. Update CHANGELOG.md before tagging
234
+ 3. Fix any failing tests or security issues before release
235
+
236
+ #### Slack Notifications Not Working
237
+
238
+ **Check**:
239
+
240
+ - `SLACK_WEBHOOK_URL` secret is configured
241
+ - Slack webhook is still active
242
+ - `#cicd-notifications` channel exists
243
+ - Webhook has permission to post
244
+
245
+ See [Slack Integration Guide](./SLACK_INTEGRATION.md) for detailed troubleshooting.
246
+
247
+ ### Emergency Release Recovery
248
+
249
+ If a release fails partway through:
250
+
251
+ 1. **Check RubyGems**: Verify if the gem was published
252
+ 2. **Check GitHub Releases**: See if release was created
253
+ 3. **Manual Cleanup**: Delete tags/releases if needed
254
+ 4. **Re-run**: Fix issues and re-trigger the workflow
255
+
256
+ ## 📈 Semantic Versioning
257
+
258
+ This project follows [Semantic Versioning](https://semver.org/):
259
+
260
+ - **PATCH** (`0.1.0` → `0.1.1`): Bug fixes, documentation updates
261
+ - **MINOR** (`0.1.0` → `0.2.0`): New features, backwards compatible
262
+ - **MAJOR** (`0.1.0` → `1.0.0`): Breaking changes
263
+
264
+ ## 🎯 Post-Release Tasks
265
+
266
+ ### Immediate Verification
267
+
268
+ 1. **Check RubyGems**: Verify the new version appears on [rubygems.org/gems/class-metrix](https://rubygems.org/gems/class-metrix)
269
+ 2. **Test Installation**:
270
+ ```bash
271
+ gem install class-metrix -v X.X.X
272
+ # Test in a new Ruby environment
273
+ ```
274
+ 3. **Verify GitHub Release**: Check that release notes and assets are correct
275
+ 4. **Slack Confirmation**: Ensure success notification was received
276
+
277
+ ### Follow-up Actions
278
+
279
+ 1. **Update Dependencies**: In projects using ClassMetrix
280
+
281
+ ```ruby
282
+ # Gemfile
283
+ gem 'class-metrix', '~> X.X.X'
284
+ ```
285
+
286
+ 2. **Documentation Updates**:
287
+
288
+ - Update any version-specific documentation
289
+ - Refresh installation instructions if needed
290
+ - Update examples if new features were added
291
+
292
+ 3. **Announcements**: Consider announcing on:
293
+
294
+ - Project README badges
295
+ - Relevant Ruby community channels
296
+ - Internal team notifications
297
+
298
+ 4. **Monitor**: Watch for any user reports or issues with the new version
299
+
300
+ ### Rollback Procedure
301
+
302
+ If a critical issue is discovered post-release:
303
+
304
+ 1. **Immediate**: Document the issue clearly
305
+ 2. **Quick Fix**: If possible, prepare a patch release
306
+ 3. **Communication**: Notify users via appropriate channels
307
+ 4. **Yanking** (last resort):
308
+ ```bash
309
+ gem yank class-metrix -v X.X.X
310
+ ```
311
+
312
+ ## 📚 Additional Resources
313
+
314
+ - **[Slack Integration Guide](./SLACK_INTEGRATION.md)**: Set up release notifications
315
+ - **[Architecture Guide](./ARCHITECTURE.md)**: Understanding the codebase
316
+ - **[QLTY Integration](./QLTY_INTEGRATION.md)**: Code quality monitoring
317
+ - **[Semantic Versioning](https://semver.org/)**: Version numbering guidelines
318
+ - **[RubyGems Guides](https://guides.rubygems.org/)**: Official gem publishing documentation
@@ -0,0 +1,227 @@
1
+ # Slack Integration for ClassMetrix CI/CD
2
+
3
+ This document explains how to set up Slack notifications for ClassMetrix GitHub Actions workflows.
4
+
5
+ ## Overview
6
+
7
+ ClassMetrix uses Slack notifications to keep your team informed about CI/CD pipeline status. The integration provides minimal, focused notifications:
8
+
9
+ - **CI Pipeline**: One notification when the entire CI pipeline completes (success/failure/partial)
10
+ - **Release Pipeline**: One notification for release success, one for release failure
11
+
12
+ All notifications are sent to a single channel: `#cicd-notifications`
13
+
14
+ ## Features
15
+
16
+ ### CI Notifications
17
+
18
+ - ✅ **Pipeline Status**: Overall CI result with individual job statuses
19
+ - 🔗 **Direct Links**: Links to workflow runs and repository
20
+ - 📊 **Job Breakdown**: Status of tests, security, quality, and compatibility checks
21
+ - 🎯 **Contextual Info**: Branch, trigger type, and repository details
22
+
23
+ ### Release Notifications
24
+
25
+ - 🚀 **Release Success**: Version info, installation commands, and useful links
26
+ - ❌ **Release Failure**: Detailed failure information and troubleshooting context
27
+ - 📦 **RubyGems Links**: Direct links to published gems
28
+ - 📚 **GitHub Release**: Links to release notes and documentation
29
+
30
+ ## Setup Instructions
31
+
32
+ ### 1. Create Slack Webhook
33
+
34
+ 1. Go to your Slack workspace
35
+ 2. Navigate to **Apps** → **Incoming Webhooks**
36
+ 3. Click **Add to Slack**
37
+ 4. Choose the `#cicd-notifications` channel (create it if it doesn't exist)
38
+ 5. Copy the webhook URL (starts with `https://hooks.slack.com/services/...`)
39
+
40
+ ### 2. Add GitHub Secret
41
+
42
+ 1. Go to your GitHub repository: `https://github.com/patrick204nqh/class-metrix`
43
+ 2. Navigate to **Settings** → **Secrets and variables** → **Actions**
44
+ 3. Click **New repository secret**
45
+ 4. Name: `SLACK_WEBHOOK_URL`
46
+ 5. Value: Your Slack webhook URL
47
+ 6. Click **Add secret**
48
+
49
+ ### 3. Create Slack Channel
50
+
51
+ Create a `#cicd-notifications` channel in your Slack workspace where all CI/CD notifications will be posted.
52
+
53
+ ## Notification Examples
54
+
55
+ ### CI Pipeline Complete (Success)
56
+
57
+ ```
58
+ ✅ CI Pipeline Complete
59
+ Repository: your-org/class-metrix
60
+ Branch: main
61
+ Trigger: push
62
+ Status: success
63
+ Tests: success
64
+ Security: success
65
+ Quality: success
66
+ Compatibility: success
67
+ ```
68
+
69
+ ### CI Pipeline Complete (Failure)
70
+
71
+ ```
72
+ ❌ CI Pipeline Complete
73
+ Repository: your-org/class-metrix
74
+ Branch: feature-branch
75
+ Trigger: pull_request
76
+ Status: failure
77
+ Tests: failure
78
+ Security: success
79
+ Quality: success
80
+ Compatibility: success
81
+ ```
82
+
83
+ ### Release Success
84
+
85
+ ```
86
+ 🚀 ClassMetrix Release Complete
87
+ Version: v1.2.3
88
+ Trigger: Manual
89
+ Installation: gem install class-metrix -v 1.2.3
90
+ Links: 📦 RubyGems • 📚 GitHub Release
91
+ ```
92
+
93
+ ### Release Failure
94
+
95
+ ```
96
+ ❌ ClassMetrix Release Failed
97
+ Failed Step: Build & Publish
98
+ Version: v1.2.3
99
+ Reason: Gem build or RubyGems publishing failed
100
+ Repository: your-org/class-metrix
101
+ Workflow Run: View Logs
102
+ Triggered By: username
103
+ ```
104
+
105
+ ## Workflow Integration
106
+
107
+ ### Main CI Workflow (`.github/workflows/main.yml`)
108
+
109
+ - Runs on push to main/master and pull requests
110
+ - Sends one notification after all jobs complete
111
+ - Includes status of: tests, security scan, quality checks, compatibility
112
+ - Only sends notifications if `SLACK_WEBHOOK_URL` secret is configured
113
+
114
+ ### Release Workflow (`.github/workflows/release.yml`)
115
+
116
+ - Runs on version tags or manual dispatch
117
+ - Sends success notification with installation instructions and links
118
+ - Sends failure notification with detailed troubleshooting information
119
+ - Includes RubyGems and GitHub release links
120
+
121
+ ## Testing the Integration
122
+
123
+ ### Test CI Notifications
124
+
125
+ 1. Make a small change to your code
126
+ 2. Push to a branch or create a pull request
127
+ 3. Check the `#cicd-notifications` channel for the CI completion message
128
+
129
+ ### Test Release Notifications
130
+
131
+ 1. Create a test release using workflow dispatch:
132
+ ```bash
133
+ # Go to Actions → Release Gem → Run workflow
134
+ # Enable "Dry run" to test without publishing
135
+ ```
136
+ 2. Check the channel for release notifications
137
+
138
+ ### Manual Testing Script
139
+
140
+ You can test the Slack webhook directly:
141
+
142
+ ```bash
143
+ #!/bin/bash
144
+ # Save as bin/test_slack_integration
145
+
146
+ WEBHOOK_URL="YOUR_SLACK_WEBHOOK_URL"
147
+
148
+ curl -X POST -H 'Content-type: application/json' \
149
+ --data '{
150
+ "channel": "#cicd-notifications",
151
+ "username": "GitHub Actions CI",
152
+ "icon_emoji": ":robot_face:",
153
+ "text": "🧪 Testing Slack integration for ClassMetrix CI/CD"
154
+ }' \
155
+ "$WEBHOOK_URL"
156
+ ```
157
+
158
+ ## Troubleshooting
159
+
160
+ ### No Notifications Received
161
+
162
+ 1. **Check Secret**: Verify `SLACK_WEBHOOK_URL` is set correctly in GitHub repository secrets
163
+ 2. **Check Channel**: Ensure `#cicd-notifications` channel exists and webhook has access
164
+ 3. **Check Webhook**: Test webhook URL manually using curl or Postman
165
+ 4. **Check Logs**: View workflow run logs for any Slack notification errors
166
+
167
+ ### Webhook URL Issues
168
+
169
+ - Ensure the URL starts with `https://hooks.slack.com/services/`
170
+ - Verify the webhook is still active in Slack settings
171
+ - Check that the webhook has permission to post to the channel
172
+
173
+ ### Missing Notifications
174
+
175
+ - Notifications only send if workflows complete (not cancelled mid-run)
176
+ - CI notifications require all jobs to finish (test, security, quality, compatibility)
177
+ - Release notifications only send if `dry_run` is not enabled
178
+
179
+ ## Customization
180
+
181
+ ### Changing the Channel
182
+
183
+ To send notifications to a different channel, update the `"channel"` field in both workflow files:
184
+
185
+ ```yaml
186
+ "channel": "#your-custom-channel"
187
+ ```
188
+
189
+ ### Adding More Notifications
190
+
191
+ The current setup provides minimal notifications. To add more:
192
+
193
+ 1. Review the conversation summary for previously removed notifications
194
+ 2. Add new notification steps to appropriate workflow jobs
195
+ 3. Follow the same webhook format for consistency
196
+
197
+ ### Notification Format
198
+
199
+ All notifications use Slack's rich attachment format with:
200
+
201
+ - Color coding (green for success, red for failure, yellow for warnings)
202
+ - Structured fields for easy scanning
203
+ - Direct links to relevant resources
204
+ - Contextual information (branch, trigger, repository)
205
+
206
+ ## Security Considerations
207
+
208
+ - **Webhook URL**: Keep the `SLACK_WEBHOOK_URL` secret secure
209
+ - **Channel Access**: Ensure only appropriate team members have access to the notifications channel
210
+ - **Information Exposure**: Current notifications don't expose sensitive code or secrets
211
+ - **Rate Limiting**: Slack has rate limits for webhook calls (not typically an issue with minimal notifications)
212
+
213
+ ## Support
214
+
215
+ For issues with Slack integration:
216
+
217
+ 1. Check this documentation first
218
+ 2. Review GitHub Actions workflow logs
219
+ 3. Test webhook URL manually
220
+ 4. Verify Slack workspace permissions
221
+ 5. Create an issue in the ClassMetrix repository if problems persist
222
+
223
+ ## Related Documentation
224
+
225
+ - [GitHub Actions Documentation](https://docs.github.com/en/actions)
226
+ - [Slack Incoming Webhooks](https://api.slack.com/messaging/webhooks)
227
+ - [ClassMetrix Release Guide](./RELEASE_GUIDE.md)
data/examples/README.md CHANGED
@@ -16,6 +16,7 @@ ruby examples/inheritance_and_modules.rb # Inheritance and module analysis
16
16
  ### Core Examples
17
17
 
18
18
  - **`basic_usage.rb`** - Basic constant and method extraction
19
+
19
20
  - Simple class comparison
20
21
  - Filtering and multi-type extraction
21
22
  - Hash expansion basics
@@ -122,43 +123,48 @@ ClassMetrix.extract(:constants)
122
123
  ## 📊 Example Output
123
124
 
124
125
  ### Basic Comparison
126
+
125
127
  ```markdown
126
- | Constant | User | Admin |
127
- |----------|---------|---------|
128
- | ROLE | user | admin |
129
- | TIMEOUT | 3600 | 7200 |
128
+ | Constant | User | Admin |
129
+ | -------- | ---- | ----- |
130
+ | ROLE | user | admin |
131
+ | TIMEOUT | 3600 | 7200 |
130
132
  ```
131
133
 
132
134
  ### With Inheritance
135
+
133
136
  ```markdown
134
- | Constant | DatabaseService | CacheService |
135
- |---------------|-----------------|--------------|
136
- | SERVICE_NAME | database | cache |
137
- | SERVICE_VERSION| 1.0 | 1.0 |
138
- | DEFAULT_TIMEOUT| 30 | 30 |
137
+ | Constant | DatabaseService | CacheService |
138
+ | --------------- | --------------- | ------------ |
139
+ | SERVICE_NAME | database | cache |
140
+ | SERVICE_VERSION | 1.0 | 1.0 |
141
+ | DEFAULT_TIMEOUT | 30 | 30 |
139
142
  ```
140
143
 
141
144
  ### Hash Expansion
145
+
142
146
  ```markdown
143
- | Method | Service1 | Service2 |
144
- |---------------|-----------------|-----------------|
145
- | config | {...} | {...} |
146
- | config.host | localhost | production.com |
147
- | config.port | 3000 | 443 |
148
- | config.ssl | ❌ | ✅ |
147
+ | Method | Service1 | Service2 |
148
+ | ----------- | --------- | -------------- |
149
+ | config | {...} | {...} |
150
+ | config.host | localhost | production.com |
151
+ | config.port | 3000 | 443 |
152
+ | config.ssl | ❌ | ✅ |
149
153
  ```
150
154
 
151
155
  ## 🛠️ API Reference
152
156
 
153
157
  ### Extraction Types
158
+
154
159
  - `:constants` - Class constants
155
160
  - `:class_methods` - Class methods
156
161
 
157
162
  ### Options
163
+
158
164
  - `.from(classes)` - Classes to analyze (array)
159
165
  - `.filter(pattern)` - Filter by name (regex or string)
160
166
  - `.include_inherited` - Include parent class behaviors
161
- - `.include_modules` - Include module behaviors
167
+ - `.include_modules` - Include module behaviors
162
168
  - `.include_all` - Include inherited + modules
163
169
  - `.expand_hashes` - Expand hash values (shows main rows by default)
164
170
  - `.show_only_main` - Show only main rows (collapsed hashes) - **Default**
@@ -197,6 +203,6 @@ ruby examples/inheritance_and_modules.rb
197
203
  # Advanced features
198
204
  ruby examples/advanced/hash_expansion.rb
199
205
 
200
- # Real-world scenarios
206
+ # Real-world scenarios
201
207
  ruby examples/real_world/microservices_audit.rb
202
208
  ```