gem-ci 0.2.1 → 0.4.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,303 @@
1
+ #!/usr/bin/env bash
2
+ # gem-ci Workflow Tests Runner
3
+ # Run all validation tests in .github/workflows/tests/
4
+
5
+ set -euo pipefail
6
+
7
+ # Colors for output
8
+ RED='\033[0;31m'
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ BLUE='\033[0;34m'
12
+ NC='\033[0m' # No Color
13
+
14
+ # Configuration
15
+ TESTS_DIR=".github/workflows/tests"
16
+ SECRETS_FILE=".secrets"
17
+ RUNNER_IMAGE="catthehacker/ubuntu:act-latest"
18
+
19
+ # Display usage information
20
+ usage() {
21
+ cat << EOF
22
+ ${BLUE}gem-ci Workflow Tests Runner${NC}
23
+
24
+ Usage: ./scripts/test-workflows [OPTIONS]
25
+
26
+ ${YELLOW}Options:${NC}
27
+ -h, --help Show this help message
28
+ -v, --verbose Enable verbose output
29
+ -l, --list List available test workflows
30
+ -t, --test TEST Run specific test workflow
31
+ -s, --setup Check setup and requirements
32
+ --no-secrets Run without secrets file
33
+ --runner IMAGE Use specific runner image
34
+
35
+ ${YELLOW}Available Tests:${NC}
36
+ github-app Test GitHub App authentication
37
+ labels-sync Test labels synchronization
38
+ slack-integration Test Slack integration
39
+ repository-rules Test repository rulesets
40
+
41
+ ${YELLOW}Examples:${NC}
42
+ ./scripts/test-workflows # Run all tests
43
+ ./scripts/test-workflows -t github-app # Run specific test
44
+ ./scripts/test-workflows --list # List available tests
45
+ ./scripts/test-workflows --setup # Check setup
46
+ ./scripts/test-workflows -v # Verbose output
47
+
48
+ ${YELLOW}Setup:${NC}
49
+ 1. Copy secrets: cp .secrets.example .secrets
50
+ 2. Edit secrets: nano .secrets
51
+ 3. Run tests: ./scripts/test-workflows
52
+
53
+ EOF
54
+ }
55
+
56
+ # Check if act is installed
57
+ check_act() {
58
+ if ! command -v act &> /dev/null; then
59
+ echo -e "${RED}Error: 'act' is not installed${NC}"
60
+ echo "Install with: brew install act"
61
+ echo "Or see: https://nektosact.com/installation/"
62
+ exit 1
63
+ fi
64
+ }
65
+
66
+ # Check if Docker is running
67
+ check_docker() {
68
+ if ! docker info &> /dev/null; then
69
+ echo -e "${RED}Error: Docker is not running${NC}"
70
+ echo "Please start Docker and try again"
71
+ exit 1
72
+ fi
73
+ }
74
+
75
+ # Check setup requirements
76
+ check_setup() {
77
+ echo -e "${BLUE}Checking setup requirements...${NC}"
78
+
79
+ # Check act
80
+ if command -v act &> /dev/null; then
81
+ echo -e "${GREEN}✓${NC} act is installed ($(act --version))"
82
+ else
83
+ echo -e "${RED}✗${NC} act is not installed"
84
+ return 1
85
+ fi
86
+
87
+ # Check Docker
88
+ if docker info &> /dev/null; then
89
+ echo -e "${GREEN}✓${NC} Docker is running"
90
+ else
91
+ echo -e "${RED}✗${NC} Docker is not running"
92
+ return 1
93
+ fi
94
+
95
+ # Check tests directory
96
+ if [[ -d "$TESTS_DIR" ]]; then
97
+ local test_count=$(find "$TESTS_DIR" -name "*.yml" | wc -l)
98
+ echo -e "${GREEN}✓${NC} Found $test_count test workflow files in $TESTS_DIR"
99
+ else
100
+ echo -e "${RED}✗${NC} Tests directory not found: $TESTS_DIR"
101
+ return 1
102
+ fi
103
+
104
+ # Check secrets file
105
+ if [[ -f "$SECRETS_FILE" ]]; then
106
+ echo -e "${GREEN}✓${NC} Secrets file exists ($SECRETS_FILE)"
107
+ else
108
+ echo -e "${YELLOW}!${NC} Secrets file not found ($SECRETS_FILE)"
109
+ echo " Copy example: cp .secrets.example .secrets"
110
+ fi
111
+
112
+ echo -e "${GREEN}Setup check complete!${NC}"
113
+ }
114
+
115
+ # List available test workflows
116
+ list_tests() {
117
+ echo -e "${BLUE}Available test workflows:${NC}"
118
+
119
+ if [[ ! -d "$TESTS_DIR" ]]; then
120
+ echo -e "${RED}Error: Tests directory not found: $TESTS_DIR${NC}"
121
+ exit 1
122
+ fi
123
+
124
+ local tests=()
125
+ while IFS= read -r -d '' file; do
126
+ local basename=$(basename "$file" .yml)
127
+ local name=$(echo "$basename" | sed 's/validate-//' | sed 's/-/ /g')
128
+ tests+=("$basename:$name")
129
+ done < <(find "$TESTS_DIR" -name "validate-*.yml" -print0 | sort -z)
130
+
131
+ if [[ ${#tests[@]} -eq 0 ]]; then
132
+ echo -e "${YELLOW}No test workflows found in $TESTS_DIR${NC}"
133
+ return
134
+ fi
135
+
136
+ for test in "${tests[@]}"; do
137
+ IFS=':' read -r basename name <<< "$test"
138
+ echo -e " ${GREEN}$basename${NC} - $name"
139
+ done
140
+ }
141
+
142
+ # Build act command with common options
143
+ build_act_command() {
144
+ local cmd="act"
145
+
146
+ # Add runner image
147
+ cmd="$cmd -P ubuntu-latest=$RUNNER_IMAGE"
148
+
149
+ # Add secrets file if it exists and not disabled
150
+ if [[ "$USE_SECRETS" == "true" && -f "$SECRETS_FILE" ]]; then
151
+ cmd="$cmd --secret-file $SECRETS_FILE"
152
+ fi
153
+
154
+ # Add verbose flag if requested
155
+ if [[ "$VERBOSE" == "true" ]]; then
156
+ cmd="$cmd -v"
157
+ fi
158
+
159
+ echo "$cmd"
160
+ }
161
+
162
+ # Run specific test workflow
163
+ run_test() {
164
+ local test_name="$1"
165
+ local workflow_file="$TESTS_DIR/validate-$test_name.yml"
166
+
167
+ if [[ ! -f "$workflow_file" ]]; then
168
+ echo -e "${RED}Error: Test workflow not found: $workflow_file${NC}"
169
+ echo "Available tests:"
170
+ list_tests
171
+ exit 1
172
+ fi
173
+
174
+ echo -e "${BLUE}Running test: $test_name${NC}"
175
+ local cmd=$(build_act_command)
176
+ cmd="$cmd -W $workflow_file"
177
+
178
+ echo -e "${YELLOW}Command: $cmd${NC}"
179
+
180
+ if eval "$cmd"; then
181
+ echo -e "${GREEN}✓ Test passed: $test_name${NC}"
182
+ return 0
183
+ else
184
+ echo -e "${RED}✗ Test failed: $test_name${NC}"
185
+ return 1
186
+ fi
187
+ }
188
+
189
+ # Run all test workflows
190
+ run_all_tests() {
191
+ echo -e "${BLUE}Running all workflow tests...${NC}"
192
+
193
+ if [[ ! -d "$TESTS_DIR" ]]; then
194
+ echo -e "${RED}Error: Tests directory not found: $TESTS_DIR${NC}"
195
+ exit 1
196
+ fi
197
+
198
+ local tests=()
199
+ while IFS= read -r -d '' file; do
200
+ local basename=$(basename "$file" .yml)
201
+ local test_name=$(echo "$basename" | sed 's/validate-//')
202
+ tests+=("$test_name")
203
+ done < <(find "$TESTS_DIR" -name "validate-*.yml" -print0 | sort -z)
204
+
205
+ if [[ ${#tests[@]} -eq 0 ]]; then
206
+ echo -e "${YELLOW}No test workflows found in $TESTS_DIR${NC}"
207
+ exit 0
208
+ fi
209
+
210
+ local passed=0
211
+ local failed=0
212
+ local failed_tests=()
213
+
214
+ echo -e "${BLUE}Found ${#tests[@]} test workflows${NC}"
215
+
216
+ for test in "${tests[@]}"; do
217
+ echo -e "\n${BLUE}Running test: $test${NC}"
218
+
219
+ if run_test "$test"; then
220
+ ((passed++))
221
+ else
222
+ ((failed++))
223
+ failed_tests+=("$test")
224
+ fi
225
+ done
226
+
227
+ # Summary
228
+ echo -e "\n${BLUE}Test Results Summary:${NC}"
229
+ echo -e "${GREEN}✓ Passed: $passed${NC}"
230
+ echo -e "${RED}✗ Failed: $failed${NC}"
231
+ echo -e "Total: ${#tests[@]}"
232
+
233
+ if [[ $failed -gt 0 ]]; then
234
+ echo -e "\n${RED}Failed tests:${NC}"
235
+ for test in "${failed_tests[@]}"; do
236
+ echo -e " - $test"
237
+ done
238
+ exit 1
239
+ else
240
+ echo -e "\n${GREEN}All tests passed!${NC}"
241
+ fi
242
+ }
243
+
244
+ # Main function
245
+ main() {
246
+ # Default values
247
+ VERBOSE="false"
248
+ USE_SECRETS="true"
249
+ SPECIFIC_TEST=""
250
+
251
+ # Parse arguments
252
+ while [[ $# -gt 0 ]]; do
253
+ case $1 in
254
+ -h|--help)
255
+ usage
256
+ exit 0
257
+ ;;
258
+ -v|--verbose)
259
+ VERBOSE="true"
260
+ shift
261
+ ;;
262
+ -l|--list)
263
+ list_tests
264
+ exit 0
265
+ ;;
266
+ -t|--test)
267
+ SPECIFIC_TEST="$2"
268
+ shift 2
269
+ ;;
270
+ -s|--setup)
271
+ check_setup
272
+ exit 0
273
+ ;;
274
+ --no-secrets)
275
+ USE_SECRETS="false"
276
+ shift
277
+ ;;
278
+ --runner)
279
+ RUNNER_IMAGE="$2"
280
+ shift 2
281
+ ;;
282
+ *)
283
+ echo -e "${RED}Error: Unknown option: $1${NC}"
284
+ echo "Use --help for usage information"
285
+ exit 1
286
+ ;;
287
+ esac
288
+ done
289
+
290
+ # Check requirements
291
+ check_act
292
+ check_docker
293
+
294
+ # Run specific test or all tests
295
+ if [[ -n "$SPECIFIC_TEST" ]]; then
296
+ run_test "$SPECIFIC_TEST"
297
+ else
298
+ run_all_tests
299
+ fi
300
+ }
301
+
302
+ # Run main function
303
+ main "$@"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-26 00:00:00.000000000 Z
11
+ date: 2025-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A showcase repository demonstrating advanced CI/CD workflows, automated
14
14
  testing, security scanning, community management, and comprehensive automation for
@@ -19,18 +19,33 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - ".env.example"
22
23
  - ".markdownlint.yml"
23
24
  - ".rspec"
24
25
  - ".rubocop.yml"
26
+ - ".secrets.example"
27
+ - ".slack/app-manifest.json"
25
28
  - CHANGELOG.md
26
29
  - LICENSE.txt
27
30
  - README.md
28
31
  - Rakefile
29
- - docs/MANUAL_WORKFLOW_TESTING.md
30
- - docs/SECRETS_SETUP_GUIDE.md
32
+ - docs/_config.yml
31
33
  - docs/diagrams/ci-workflow-overview.md
34
+ - docs/diagrams/gitflow-diagram.md
35
+ - docs/guides/gitflow.md
36
+ - docs/guides/local-testing.md
37
+ - docs/index.md
38
+ - docs/setup/github-pages.md
39
+ - docs/setup/secrets.md
40
+ - docs/workflows/overview.md
32
41
  - lib/gem_ci.rb
33
42
  - lib/gem_ci/version.rb
43
+ - public/gem-ci-transparent-bg.png
44
+ - public/gem-ci.jpeg
45
+ - public/gem-ci.svg
46
+ - scripts/README.md
47
+ - scripts/test-local
48
+ - scripts/test-workflows
34
49
  - sig/gem/ci.rbs
35
50
  homepage: https://github.com/patrick204nqh/gem-ci
36
51
  licenses:
@@ -1,190 +0,0 @@
1
- # 🧪 Manual Workflow Testing Guide
2
-
3
- This guide explains how to manually test and trigger gem-ci workflows for validation and troubleshooting.
4
-
5
- ## 🚀 Manual Workflow Triggers
6
-
7
- ### Main Workflows (01-08)
8
-
9
- Most main workflows trigger automatically on events, but some can be triggered manually:
10
-
11
- | Workflow | File | Manual Trigger | Purpose |
12
- |----------|------|----------------|---------|
13
- | 01 - Intake | `01-intake.yml` | ✅ Yes | Sync labels and configurations |
14
- | 02 - CI | `02-ci.yml` | ❌ Auto only | Push/PR testing |
15
- | 03 - Security | `03-security.yml` | ❌ Auto only | Security scans |
16
- | 04 - Quality | `04-quality.yml` | ❌ Auto only | Code quality checks |
17
- | 05 - Community | `05-community.yml` | ❌ Auto only | Stale management |
18
- | 06 - Release | `06-release.yml` | ❌ Auto only | Tag-based releases |
19
- | 07 - Ecosystem | `07-ecosystem.yml` | ❌ Auto only | Ecosystem checks |
20
- | 08 - Monitoring | `08-monitoring.yml` | ❌ Auto only | Scheduled monitoring |
21
-
22
- ### Test Workflows
23
-
24
- All validation workflows support manual triggering:
25
-
26
- | Validation Workflow | Purpose | Required Secrets |
27
- |-------------------|---------|------------------|
28
- | `validate-github-app.yml` | Test GitHub App setup | `APP_ID`, `PRIVATE_KEY` |
29
- | `validate-slack-integration.yml` | Test Slack notifications | `APP_ID`, `PRIVATE_KEY`, `SLACK_BOT_TOKEN`, `SLACK_CHANNEL_ID` |
30
- | `validate-labels-sync.yml` | Test label synchronization | `APP_ID`, `PRIVATE_KEY` |
31
- | `validate-repository-rulesets.yml` | Test repository rulesets | `APP_ID`, `PRIVATE_KEY` |
32
-
33
- ## 📋 How to Manually Trigger Workflows
34
-
35
- ### Method 1: GitHub Web Interface
36
-
37
- 1. **Navigate to Actions Tab**
38
- - Go to your repository on GitHub
39
- - Click the **"Actions"** tab
40
-
41
- 2. **Select Workflow**
42
- - Find the workflow you want to trigger
43
- - Click on the workflow name
44
-
45
- 3. **Run Workflow**
46
- - Click **"Run workflow"** button
47
- - Select branch (usually `main`)
48
- - Click **"Run workflow"** to confirm
49
-
50
- ### Method 2: GitHub CLI
51
-
52
- ```bash
53
- # Install GitHub CLI if not already installed
54
- # https://cli.github.com/
55
-
56
- # Trigger a workflow manually
57
- gh workflow run "workflow-name.yml"
58
-
59
- # Examples:
60
- gh workflow run "01-intake.yml"
61
- gh workflow run "validate-github-app.yml"
62
-
63
- # Check workflow status
64
- gh run list --workflow="workflow-name.yml"
65
- ```
66
-
67
- ### Method 3: REST API
68
-
69
- ```bash
70
- # Trigger workflow via API
71
- curl -X POST \
72
- -H "Accept: application/vnd.github.v3+json" \
73
- -H "Authorization: token YOUR_GITHUB_TOKEN" \
74
- https://api.github.com/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/dispatches \
75
- -d '{"ref":"main"}'
76
- ```
77
-
78
- ## 🔍 Testing Checklist
79
-
80
- ### Before Running Tests
81
-
82
- - [ ] All required secrets are configured
83
- - [ ] Repository has proper permissions
84
- - [ ] Configuration files exist (`.github/labels.yml`, etc.)
85
- - [ ] Branch protection rules are properly set
86
-
87
- ### GitHub App Validation
88
-
89
- ```bash
90
- # Run GitHub App validation
91
- gh workflow run "validate-github-app.yml"
92
-
93
- # Expected results:
94
- # ✅ Token generation successful
95
- # ✅ API access working
96
- # ✅ Branded bot identity confirmed
97
- ```
98
-
99
- ### Slack Integration Testing
100
-
101
- ```bash
102
- # Run Slack integration test
103
- gh workflow run "validate-slack-integration.yml"
104
-
105
- # Expected results:
106
- # ✅ Basic message sent to Slack
107
- # ✅ Rich message blocks working
108
- # ✅ Bot appears with correct identity
109
- ```
110
-
111
- ### Labels Synchronization
112
-
113
- ```bash
114
- # Run label sync validation
115
- gh workflow run "validate-labels-sync.yml"
116
-
117
- # Expected results:
118
- # ✅ Label configuration valid
119
- # ✅ All required labels present
120
- # ✅ Color scheme accessibility confirmed
121
- ```
122
-
123
- ## 📊 Monitoring Workflow Results
124
-
125
- ### Check Workflow Status
126
-
127
- ```bash
128
- # List recent workflow runs
129
- gh run list --limit 10
130
-
131
- # Get details of specific run
132
- gh run view RUN_ID
133
-
134
- # Download workflow logs
135
- gh run download RUN_ID
136
- ```
137
-
138
- ### Common Issues & Solutions
139
-
140
- | Issue | Solution |
141
- |-------|----------|
142
- | **Token generation failed** | Verify `APP_ID` and `PRIVATE_KEY` secrets |
143
- | **Slack message not sent** | Check `SLACK_BOT_TOKEN` and `SLACK_CHANNEL_ID` |
144
- | **Label sync failed** | Validate `.github/labels.yml` syntax |
145
- | **API rate limit exceeded** | Wait and retry, or use GitHub App token |
146
- | **Permission denied** | Verify GitHub App permissions and installation |
147
-
148
- ## 🛠️ Troubleshooting
149
-
150
- ### Debug Mode
151
-
152
- Enable debug logging by setting repository variables:
153
- - `ACTIONS_STEP_DEBUG`: `true`
154
- - `ACTIONS_RUNNER_DEBUG`: `true`
155
-
156
- ### Secrets Validation
157
-
158
- Use the validation workflows to test each component:
159
-
160
- 1. **Start with GitHub App validation** - This tests the foundation
161
- 2. **Run Slack validation** - If notifications are needed
162
- 3. **Test label sync** - For repository organization
163
- 4. **Validate rulesets** - For branch protection
164
-
165
- ### Common Workflow Patterns
166
-
167
- - **On Push**: Triggers CI, security, and quality workflows
168
- - **On PR**: Triggers testing and validation workflows
169
- - **On Release**: Triggers release and notification workflows
170
- - **On Schedule**: Triggers monitoring and maintenance workflows
171
- - **Manual**: Triggers setup and validation workflows
172
-
173
- ## 📞 Getting Help
174
-
175
- If workflows fail after following this guide:
176
-
177
- 1. Check workflow logs in the Actions tab
178
- 2. Verify all required secrets are set
179
- 3. Review configuration files for syntax errors
180
- 4. Test individual components using validation workflows
181
- 5. Check GitHub App permissions and installation
182
-
183
- ## 🔄 Regular Testing Schedule
184
-
185
- Recommended testing schedule:
186
-
187
- - **Weekly**: Run GitHub App validation
188
- - **Monthly**: Test Slack integration (if used)
189
- - **Before releases**: Run all validation workflows
190
- - **After configuration changes**: Test affected workflows