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.
data/scripts/README.md ADDED
@@ -0,0 +1,258 @@
1
+ # ๐Ÿงช gem-ci Testing Scripts
2
+
3
+ This directory contains helper scripts for testing gem-ci workflows locally using the `act` CLI tool.
4
+
5
+ ## ๐Ÿ“‹ Scripts Overview
6
+
7
+ | Script | Purpose | Usage |
8
+ |--------|---------|-------|
9
+ | **`test-local`** | Test main workflows with different events | `./scripts/test-local [EVENT]` |
10
+ | **`test-workflows`** | Run validation tests in `.github/workflows/tests/` | `./scripts/test-workflows` |
11
+
12
+ ## ๐Ÿš€ Quick Start
13
+
14
+ ### **1. Setup**
15
+ ```bash
16
+ # Copy example files
17
+ cp .secrets.example .secrets
18
+ cp .env.example .env.test
19
+
20
+ # Edit with your actual secrets
21
+ nano .secrets
22
+ nano .env.test
23
+
24
+ # Check setup
25
+ ./scripts/test-local --setup
26
+ ./scripts/test-workflows --setup
27
+ ```
28
+
29
+ ### **2. Test Main Workflows**
30
+ ```bash
31
+ # Test push workflows (CI, Security, Quality)
32
+ ./scripts/test-local
33
+
34
+ # Test pull request workflows
35
+ ./scripts/test-local pull_request
36
+
37
+ # Test specific workflow
38
+ ./scripts/test-local ci
39
+
40
+ # Test all workflows
41
+ ./scripts/test-local all
42
+
43
+ # List available workflows
44
+ ./scripts/test-local --list
45
+ ```
46
+
47
+ ### **3. Run Validation Tests**
48
+ ```bash
49
+ # Run all validation tests
50
+ ./scripts/test-workflows
51
+
52
+ # Run specific validation test
53
+ ./scripts/test-workflows -t github-app
54
+
55
+ # List available tests
56
+ ./scripts/test-workflows --list
57
+ ```
58
+
59
+ ## ๐ŸŽฏ test-local Script
60
+
61
+ Tests main gem-ci workflows using different GitHub events.
62
+
63
+ ### **Events**
64
+ - `push` - Test push workflows (CI, Security, Quality) [default]
65
+ - `pull_request` - Test pull request workflows
66
+ - `schedule` - Test scheduled workflows (Community, Ecosystem, Monitoring)
67
+ - `workflow_dispatch` - Test manual workflow dispatch
68
+ - `all` - Test all main workflows
69
+
70
+ ### **Workflow-Specific Tests**
71
+ - `ci` - Test CI workflow (02-ci.yml)
72
+ - `security` - Test Security workflow (03-security.yml)
73
+ - `quality` - Test Quality workflow (04-quality.yml)
74
+ - `community` - Test Community workflow (05-community.yml)
75
+ - `release` - Test Release workflow (06-release.yml) - **SAFE MODE**
76
+ - `ecosystem` - Test Ecosystem workflow (07-ecosystem.yml)
77
+ - `monitoring` - Test Monitoring workflow (08-monitoring.yml)
78
+ - `bot-commands` - Test Bot Commands workflow (09-bot-commands.yml)
79
+
80
+ ### **Options**
81
+ - `-v, --verbose` - Enable verbose output
82
+ - `-d, --dry-run` - Dry run mode (for release testing)
83
+ - `-j, --job JOB` - Run specific job only
84
+ - `--no-secrets` - Run without secrets file
85
+ - `--runner IMAGE` - Use specific runner image
86
+
87
+ ### **Examples**
88
+ ```bash
89
+ # Basic usage
90
+ ./scripts/test-local # Test push event
91
+ ./scripts/test-local pull_request # Test PR workflows
92
+ ./scripts/test-local ci # Test CI workflow only
93
+
94
+ # Advanced usage
95
+ ./scripts/test-local ci -j test-ruby # Run specific job
96
+ ./scripts/test-local release --dry-run # Safely test release
97
+ ./scripts/test-local -v # Verbose output
98
+
99
+ # Check status
100
+ ./scripts/test-local --setup # Check setup
101
+ ./scripts/test-local --list # List workflows
102
+ ```
103
+
104
+ ## ๐Ÿ” test-workflows Script
105
+
106
+ Runs validation tests from `.github/workflows/tests/` directory.
107
+
108
+ ### **Available Tests**
109
+ - `github-app` - Test GitHub App authentication
110
+ - `labels-sync` - Test labels synchronization
111
+ - `slack-integration` - Test Slack integration
112
+ - `repository-rules` - Test repository rulesets
113
+
114
+ ### **Options**
115
+ - `-t, --test TEST` - Run specific test workflow
116
+ - `-v, --verbose` - Enable verbose output
117
+ - `--no-secrets` - Run without secrets file
118
+ - `--runner IMAGE` - Use specific runner image
119
+
120
+ ### **Examples**
121
+ ```bash
122
+ # Basic usage
123
+ ./scripts/test-workflows # Run all tests
124
+ ./scripts/test-workflows -t github-app # Run specific test
125
+
126
+ # Advanced usage
127
+ ./scripts/test-workflows -v # Verbose output
128
+ ./scripts/test-workflows --list # List available tests
129
+ ./scripts/test-workflows --setup # Check setup
130
+ ```
131
+
132
+ ## ๐Ÿ” Secrets & Environment Setup
133
+
134
+ Both scripts use the same configuration files:
135
+
136
+ ### **Secrets File (.secrets)**
137
+ ```bash
138
+ # Copy and edit
139
+ cp .secrets.example .secrets
140
+ nano .secrets
141
+ ```
142
+
143
+ Required secrets:
144
+ - `GITHUB_TOKEN` - GitHub personal access token
145
+ - `APP_ID` - GitHub App ID
146
+ - `PRIVATE_KEY` - GitHub App private key
147
+
148
+ Optional secrets:
149
+ - `SLACK_BOT_TOKEN` - For Slack notifications
150
+ - `SLACK_CHANNEL_ID` - Slack channel ID
151
+ - `RUBYGEMS_API_KEY` - For gem publishing tests
152
+
153
+ ### **Environment File (.env.test)**
154
+ ```bash
155
+ # Copy and edit
156
+ cp .env.example .env.test
157
+ nano .env.test
158
+ ```
159
+
160
+ Common environment variables:
161
+ - `RUBY_VERSION=3.3` - Ruby version override
162
+ - `DRY_RUN=true` - Prevent actual publishing
163
+ - `DEBUG=true` - Enable debug output
164
+
165
+ ## ๐ŸŽญ Runner Images
166
+
167
+ Both scripts support different runner images:
168
+
169
+ | Size | Image | Description |
170
+ |------|-------|-------------|
171
+ | **Small** | `node:16-buster-slim` | ~200MB, basic Node.js |
172
+ | **Medium** | `catthehacker/ubuntu:act-latest` | ~500MB, balanced [default] |
173
+ | **Large** | `catthehacker/ubuntu:full-latest` | Full Ubuntu environment |
174
+
175
+ ```bash
176
+ # Use different runner
177
+ ./scripts/test-local --runner catthehacker/ubuntu:full-latest
178
+ ./scripts/test-workflows --runner node:16-buster-slim
179
+ ```
180
+
181
+ ## ๐Ÿ”ง Troubleshooting
182
+
183
+ ### **Setup Issues**
184
+ ```bash
185
+ # Check requirements
186
+ ./scripts/test-local --setup
187
+ ./scripts/test-workflows --setup
188
+
189
+ # Common fixes
190
+ brew install act # Install act
191
+ open -a Docker # Start Docker (macOS)
192
+ cp .secrets.example .secrets # Create secrets file
193
+ ```
194
+
195
+ ### **First Run Performance**
196
+ The first time you run tests, it may take several minutes because:
197
+ - Docker images need to be downloaded (~500MB for medium runner)
198
+ - Ruby dependencies need to be installed
199
+ - Actions need to be cached
200
+
201
+ Subsequent runs will be much faster due to caching.
202
+
203
+ ### **Test Failures**
204
+ ```bash
205
+ # Debug with verbose output
206
+ ./scripts/test-local ci -v
207
+ ./scripts/test-workflows -t github-app -v
208
+
209
+ # Test without secrets (if secrets are the issue)
210
+ ./scripts/test-local --no-secrets
211
+ ./scripts/test-workflows --no-secrets
212
+ ```
213
+
214
+ ### **Performance Issues**
215
+ ```bash
216
+ # Use smaller runner image
217
+ ./scripts/test-local --runner node:16-buster-slim
218
+
219
+ # Test specific jobs only
220
+ ./scripts/test-local ci -j test-ruby
221
+ ```
222
+
223
+ ## ๐Ÿ’ก Pro Tips
224
+
225
+ 1. **Use .actrc for permanent configuration:**
226
+ ```bash
227
+ cat > ~/.actrc << 'EOF'
228
+ -P ubuntu-latest=catthehacker/ubuntu:act-latest
229
+ --secret-file .secrets
230
+ EOF
231
+ ```
232
+
233
+ 2. **Test before pushing:**
234
+ ```bash
235
+ ./scripts/test-local # Test push workflows
236
+ ./scripts/test-workflows # Validate setup
237
+ ```
238
+
239
+ 3. **Safe release testing:**
240
+ ```bash
241
+ ./scripts/test-local release --dry-run
242
+ ```
243
+
244
+ 4. **Quick validation:**
245
+ ```bash
246
+ ./scripts/test-workflows -t github-app
247
+ ```
248
+
249
+ ## ๐Ÿšจ Security Notes
250
+
251
+ - Never commit `.secrets` file to repository
252
+ - Use test Slack channels for local testing
253
+ - Release workflows run in dry-run mode by default
254
+ - Consider using separate secrets for testing vs production
255
+
256
+ ---
257
+
258
+ **Need help?** Check the [local testing guide](../docs/guides/local-testing.md) for detailed setup instructions.
@@ -0,0 +1,315 @@
1
+ #!/usr/bin/env bash
2
+ # gem-ci Local Testing Script
3
+ # Test GitHub Actions workflows locally using act
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
+ SECRETS_FILE=".secrets"
16
+ ENV_FILE=".env.test"
17
+ RUNNER_IMAGE="catthehacker/ubuntu:act-latest"
18
+
19
+ # Display usage information
20
+ usage() {
21
+ cat << EOF
22
+ ${BLUE}gem-ci Local Testing Script${NC}
23
+
24
+ Usage: ./scripts/test-local [EVENT] [OPTIONS]
25
+
26
+ ${YELLOW}Events:${NC}
27
+ push Test push workflows (CI, Security, Quality) [default]
28
+ pull_request Test pull request workflows
29
+ schedule Test scheduled workflows (Community, Ecosystem, Monitoring)
30
+ workflow_dispatch Test manual workflow dispatch
31
+ all Test all main workflows
32
+
33
+ ${YELLOW}Workflow-specific tests:${NC}
34
+ ci Test CI workflow (02-ci.yml)
35
+ security Test Security workflow (03-security.yml)
36
+ quality Test Quality workflow (04-quality.yml)
37
+ community Test Community workflow (05-community.yml)
38
+ release Test Release workflow (06-release.yml) - CAREFUL!
39
+ ecosystem Test Ecosystem workflow (07-ecosystem.yml)
40
+ monitoring Test Monitoring workflow (08-monitoring.yml)
41
+ bot-commands Test Bot Commands workflow (09-bot-commands.yml)
42
+
43
+ ${YELLOW}Options:${NC}
44
+ -h, --help Show this help message
45
+ -v, --verbose Enable verbose output
46
+ -l, --list List available workflows and jobs
47
+ -d, --dry-run Dry run mode (for release testing)
48
+ -j, --job JOB Run specific job only
49
+ -s, --setup Check setup and requirements
50
+ --no-secrets Run without secrets file
51
+ --runner IMAGE Use specific runner image
52
+
53
+ ${YELLOW}Examples:${NC}
54
+ ./scripts/test-local # Test push event (default)
55
+ ./scripts/test-local pull_request # Test PR workflows
56
+ ./scripts/test-local ci # Test CI workflow only
57
+ ./scripts/test-local release --dry-run # Safely test release workflow
58
+ ./scripts/test-local -j test-ruby # Run specific job
59
+ ./scripts/test-local --list # List available workflows
60
+ ./scripts/test-local --setup # Check setup
61
+
62
+ ${YELLOW}Setup:${NC}
63
+ 1. Copy example files: cp .secrets.example .secrets && cp .env.example .env.test
64
+ 2. Edit secrets: nano .secrets
65
+ 3. Edit environment: nano .env.test
66
+ 4. Run tests: ./scripts/test-local
67
+
68
+ EOF
69
+ }
70
+
71
+ # Check if act is installed
72
+ check_act() {
73
+ if ! command -v act &> /dev/null; then
74
+ echo -e "${RED}Error: 'act' is not installed${NC}"
75
+ echo "Install with: brew install act"
76
+ echo "Or see: https://nektosact.com/installation/"
77
+ exit 1
78
+ fi
79
+ }
80
+
81
+ # Check if Docker is running
82
+ check_docker() {
83
+ if ! docker info &> /dev/null; then
84
+ echo -e "${RED}Error: Docker is not running${NC}"
85
+ echo "Please start Docker and try again"
86
+ exit 1
87
+ fi
88
+ }
89
+
90
+ # Check setup requirements
91
+ check_setup() {
92
+ echo -e "${BLUE}Checking setup requirements...${NC}"
93
+
94
+ # Check act
95
+ if command -v act &> /dev/null; then
96
+ echo -e "${GREEN}โœ“${NC} act is installed ($(act --version))"
97
+ else
98
+ echo -e "${RED}โœ—${NC} act is not installed"
99
+ return 1
100
+ fi
101
+
102
+ # Check Docker
103
+ if docker info &> /dev/null; then
104
+ echo -e "${GREEN}โœ“${NC} Docker is running"
105
+ else
106
+ echo -e "${RED}โœ—${NC} Docker is not running"
107
+ return 1
108
+ fi
109
+
110
+ # Check secrets file
111
+ if [[ -f "$SECRETS_FILE" ]]; then
112
+ echo -e "${GREEN}โœ“${NC} Secrets file exists ($SECRETS_FILE)"
113
+ else
114
+ echo -e "${YELLOW}!${NC} Secrets file not found ($SECRETS_FILE)"
115
+ echo " Copy example: cp .secrets.example .secrets"
116
+ fi
117
+
118
+ # Check environment file
119
+ if [[ -f "$ENV_FILE" ]]; then
120
+ echo -e "${GREEN}โœ“${NC} Environment file exists ($ENV_FILE)"
121
+ else
122
+ echo -e "${YELLOW}!${NC} Environment file not found ($ENV_FILE)"
123
+ echo " Copy example: cp .env.example .env.test"
124
+ fi
125
+
126
+ # Check workflows directory
127
+ if [[ -d ".github/workflows" ]]; then
128
+ local workflow_count=$(find .github/workflows -name "*.yml" -not -path "*/tests/*" -not -path "*/shared/*" | wc -l)
129
+ echo -e "${GREEN}โœ“${NC} Found $workflow_count workflow files"
130
+ else
131
+ echo -e "${RED}โœ—${NC} .github/workflows directory not found"
132
+ return 1
133
+ fi
134
+
135
+ echo -e "${GREEN}Setup check complete!${NC}"
136
+ }
137
+
138
+ # Build act command with common options
139
+ build_act_command() {
140
+ local cmd="act"
141
+
142
+ # Add runner image
143
+ cmd="$cmd -P ubuntu-latest=$RUNNER_IMAGE"
144
+
145
+ # Add secrets file if it exists and not disabled
146
+ if [[ "$USE_SECRETS" == "true" && -f "$SECRETS_FILE" ]]; then
147
+ cmd="$cmd --secret-file $SECRETS_FILE"
148
+ fi
149
+
150
+ # Add environment file if it exists
151
+ if [[ -f "$ENV_FILE" ]]; then
152
+ cmd="$cmd --env-file $ENV_FILE"
153
+ fi
154
+
155
+ # Add verbose flag if requested
156
+ if [[ "$VERBOSE" == "true" ]]; then
157
+ cmd="$cmd -v"
158
+ fi
159
+
160
+ # Add dry-run for release testing
161
+ if [[ "$DRY_RUN" == "true" ]]; then
162
+ cmd="$cmd --env DRY_RUN=true --env SKIP_PUBLISH=true"
163
+ fi
164
+
165
+ # Add specific job if requested
166
+ if [[ -n "$JOB" ]]; then
167
+ cmd="$cmd -j $JOB"
168
+ fi
169
+
170
+ echo "$cmd"
171
+ }
172
+
173
+ # Run specific workflow file
174
+ run_workflow() {
175
+ local workflow_file="$1"
176
+ local workflow_name="$2"
177
+
178
+ if [[ ! -f "$workflow_file" ]]; then
179
+ echo -e "${RED}Error: Workflow file not found: $workflow_file${NC}"
180
+ exit 1
181
+ fi
182
+
183
+ echo -e "${BLUE}Testing $workflow_name workflow...${NC}"
184
+ local cmd=$(build_act_command)
185
+ cmd="$cmd -W $workflow_file"
186
+
187
+ echo -e "${YELLOW}Running: $cmd${NC}"
188
+ eval "$cmd"
189
+ }
190
+
191
+ # Main function
192
+ main() {
193
+ # Default values
194
+ EVENT="push"
195
+ VERBOSE="false"
196
+ DRY_RUN="false"
197
+ USE_SECRETS="true"
198
+ JOB=""
199
+
200
+ # Parse arguments
201
+ while [[ $# -gt 0 ]]; do
202
+ case $1 in
203
+ -h|--help)
204
+ usage
205
+ exit 0
206
+ ;;
207
+ -v|--verbose)
208
+ VERBOSE="true"
209
+ shift
210
+ ;;
211
+ -l|--list)
212
+ check_act
213
+ act -l
214
+ exit 0
215
+ ;;
216
+ -d|--dry-run)
217
+ DRY_RUN="true"
218
+ shift
219
+ ;;
220
+ -j|--job)
221
+ JOB="$2"
222
+ shift 2
223
+ ;;
224
+ -s|--setup)
225
+ check_setup
226
+ exit 0
227
+ ;;
228
+ --no-secrets)
229
+ USE_SECRETS="false"
230
+ shift
231
+ ;;
232
+ --runner)
233
+ RUNNER_IMAGE="$2"
234
+ shift 2
235
+ ;;
236
+ push|pull_request|schedule|workflow_dispatch|all)
237
+ EVENT="$1"
238
+ shift
239
+ ;;
240
+ ci)
241
+ run_workflow ".github/workflows/02-ci.yml" "CI"
242
+ exit 0
243
+ ;;
244
+ security)
245
+ run_workflow ".github/workflows/03-security.yml" "Security"
246
+ exit 0
247
+ ;;
248
+ quality)
249
+ run_workflow ".github/workflows/04-quality.yml" "Quality"
250
+ exit 0
251
+ ;;
252
+ community)
253
+ run_workflow ".github/workflows/05-community.yml" "Community"
254
+ exit 0
255
+ ;;
256
+ release)
257
+ DRY_RUN="true" # Force dry-run for release
258
+ run_workflow ".github/workflows/06-release.yml" "Release"
259
+ exit 0
260
+ ;;
261
+ ecosystem)
262
+ run_workflow ".github/workflows/07-ecosystem.yml" "Ecosystem"
263
+ exit 0
264
+ ;;
265
+ monitoring)
266
+ run_workflow ".github/workflows/08-monitoring.yml" "Monitoring"
267
+ exit 0
268
+ ;;
269
+ bot-commands)
270
+ run_workflow ".github/workflows/09-bot-commands.yml" "Bot Commands"
271
+ exit 0
272
+ ;;
273
+ *)
274
+ echo -e "${RED}Error: Unknown option or event: $1${NC}"
275
+ echo "Use --help for usage information"
276
+ exit 1
277
+ ;;
278
+ esac
279
+ done
280
+
281
+ # Check requirements
282
+ check_act
283
+ check_docker
284
+
285
+ # Build and run act command
286
+ local cmd=$(build_act_command)
287
+
288
+ if [[ "$EVENT" == "all" ]]; then
289
+ echo -e "${BLUE}Testing all main workflows...${NC}"
290
+ echo -e "${YELLOW}Running push, pull_request, and schedule events${NC}"
291
+
292
+ # Test push workflows
293
+ echo -e "\n${BLUE}1. Testing push workflows (CI, Security, Quality)...${NC}"
294
+ eval "$cmd push"
295
+
296
+ # Test PR workflows
297
+ echo -e "\n${BLUE}2. Testing pull request workflows...${NC}"
298
+ eval "$cmd pull_request"
299
+
300
+ # Test scheduled workflows
301
+ echo -e "\n${BLUE}3. Testing scheduled workflows (Community, Ecosystem, Monitoring)...${NC}"
302
+ eval "$cmd schedule"
303
+
304
+ else
305
+ echo -e "${BLUE}Testing $EVENT workflows...${NC}"
306
+ cmd="$cmd $EVENT"
307
+ echo -e "${YELLOW}Running: $cmd${NC}"
308
+ eval "$cmd"
309
+ fi
310
+
311
+ echo -e "${GREEN}Testing complete!${NC}"
312
+ }
313
+
314
+ # Run main function
315
+ main "$@"