Skip to content

Commit 3fd0339

Browse files
Prepare CodeAnt CI Scan action for testing
0 parents  commit 3fd0339

File tree

3 files changed

+396
-0
lines changed

3 files changed

+396
-0
lines changed

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# CodeAnt CI Scan Action
2+
3+
This GitHub Action runs CodeAnt CI security and code quality analysis on your repository. It integrates seamlessly with your CI/CD pipeline to provide automated code scanning and security insights.
4+
5+
## Features
6+
7+
- 🔒 Security vulnerability detection
8+
- 📊 Code quality analysis
9+
- 🚀 Fast and efficient scanning
10+
- 🔄 Seamless CI/CD integration
11+
- 📈 Detailed reports and insights
12+
13+
## Inputs
14+
15+
| Name | Description | Required | Default |
16+
|---------------|--------------------------------------------------|----------|--------------------------|
17+
| access_token | GitHub PAT or repository token for authentication | Yes | - |
18+
| api_base | Base URL for CodeAnt API | No | https://api.codeant.ai |
19+
20+
## Usage
21+
22+
### Basic Example
23+
24+
```yaml
25+
name: CodeAnt CI Scan
26+
27+
on:
28+
push:
29+
branches: [ main, develop ]
30+
pull_request:
31+
branches: [ main ]
32+
33+
jobs:
34+
scan:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Run CodeAnt Scan
38+
uses: your-username/codeant-ci-scan@v1
39+
with:
40+
access_token: ${{ secrets.GITHUB_TOKEN }}
41+
```
42+
43+
### Custom API Base URL
44+
45+
```yaml
46+
- name: Run CodeAnt Scan
47+
uses: your-username/codeant-ci-scan@v1
48+
with:
49+
access_token: ${{ secrets.ACCESS_TOKEN_GITHUB }}
50+
api_base: https://custom.codeant.ai
51+
```
52+
53+
## Testing from Another Repository
54+
55+
To test this action before publishing to the GitHub Marketplace:
56+
57+
1. **Push this action to a GitHub repository** (e.g., `your-username/codeant-ci-scan`)
58+
59+
2. **In another repository**, reference it using the repository path:
60+
61+
```yaml
62+
- name: Test CodeAnt Scan
63+
uses: your-username/codeant-ci-scan@main # or use a specific branch/tag
64+
with:
65+
access_token: ${{ secrets.GITHUB_TOKEN }}
66+
```
67+
68+
3. **For testing specific commits or branches:**
69+
```yaml
70+
uses: your-username/codeant-ci-scan@feature-branch
71+
# or
72+
uses: your-username/codeant-ci-scan@abc1234 # commit SHA
73+
```
74+
75+
## Required Permissions
76+
77+
The `access_token` requires the following permissions:
78+
- `repo` - Full control of private repositories (for reading code)
79+
- `contents: read` - Read access to repository contents
80+
81+
## Publishing to GitHub Marketplace
82+
83+
Before publishing:
84+
85+
1. ✅ Create a release with semantic versioning (e.g., v1.0.0)
86+
2. ✅ Add a LICENSE file
87+
3. ✅ Test thoroughly from another repository
88+
4. ✅ Ensure action.yml has proper branding and metadata
89+
90+
## Support
91+
92+
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/your-username/codeant-ci-scan).
93+
94+
## License
95+
96+
[Add your license here]

README_LOCAL.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# GitHub Action Development - Best Practices Used
2+
3+
This document outlines the best practices we implemented while creating the CodeAnt CI Scan GitHub Action.
4+
5+
## 1. Action Metadata (action.yml)
6+
7+
### ✅ Proper Action Definition
8+
- **Clear naming**: Used descriptive `name` and `description` fields
9+
- **Author identification**: Set proper `author` field
10+
- **Branding**: Added `icon` and `color` for marketplace visibility
11+
```yaml
12+
branding:
13+
icon: "shield"
14+
color: "blue"
15+
```
16+
17+
### ✅ Input Configuration
18+
- **Clear descriptions**: Each input has a detailed description
19+
- **Required vs Optional**: Properly marked required inputs
20+
- **Default values**: Provided sensible defaults (e.g., `api_base`)
21+
- **Documentation**: Included examples in descriptions
22+
23+
## 2. Composite Action Best Practices
24+
25+
### ✅ Shell Specification
26+
**Critical for composite actions**: Always specify `shell` in run steps
27+
```yaml
28+
- name: Step name
29+
shell: bash
30+
run: |
31+
# commands here
32+
```
33+
34+
### ✅ Error Handling
35+
- **Fail fast**: Used `set -e` to exit on any error
36+
- **Explicit error messages**: Added conditional checks with helpful error messages
37+
```bash
38+
if ! curl -fsSL ...; then
39+
echo "Error: Failed to fetch scan script"
40+
exit 1
41+
fi
42+
```
43+
44+
### ✅ Informative Logging
45+
- Added echo statements to track progress
46+
- Clear messages at each step for debugging
47+
48+
## 3. Dependency Management
49+
50+
### ✅ Version Pinning
51+
- Updated to `actions/checkout@v4` (latest stable version)
52+
- Avoid using `@master` or `@latest` in production
53+
54+
### ✅ Minimal External Dependencies
55+
- Used standard tools available in GitHub runners (curl, base64, bash)
56+
- No need for additional setup steps
57+
58+
## 4. Security Best Practices
59+
60+
### ✅ Token Handling
61+
- Never hardcode tokens
62+
- Use inputs with clear security requirements
63+
- Document required permissions in README
64+
65+
### ✅ Secure Script Handling
66+
- Validate downloaded scripts before execution
67+
- Check curl exit codes
68+
- Verify base64 decoding success
69+
70+
### ✅ Fail-Safe Execution
71+
- Use `curl -fsSL` flags:
72+
- `-f`: Fail on HTTP errors
73+
- `-s`: Silent mode
74+
- `-S`: Show errors
75+
- `-L`: Follow redirects
76+
77+
## 5. Documentation Best Practices
78+
79+
### ✅ Comprehensive README
80+
- Clear feature list
81+
- Input/output documentation in table format
82+
- Multiple usage examples (basic and advanced)
83+
- Testing instructions before marketplace publication
84+
- Required permissions documentation
85+
- Publishing checklist
86+
87+
### ✅ Usage Examples
88+
- Provided complete workflow examples
89+
- Showed both simple and complex use cases
90+
- Included testing from another repository instructions
91+
92+
## 6. Code Organization
93+
94+
### ✅ Clean Repository Structure
95+
```
96+
codeant-ci-scan/
97+
├── action.yml # Action definition
98+
├── README.md # User documentation
99+
├── README_LOCAL.md # Development documentation
100+
└── LICENSE # License file (recommended)
101+
```
102+
103+
### ✅ No Unnecessary Files
104+
- Removed boilerplate code (main.py)
105+
- Keep only essential files
106+
107+
## 7. Action Steps Structure
108+
109+
### ✅ Logical Step Separation
110+
1. **Checkout**: Get repository code
111+
2. **Fetch**: Download scan script
112+
3. **Prepare**: Decode and make executable
113+
4. **Execute**: Run the analysis
114+
115+
### ✅ Clear Step Naming
116+
- Use descriptive names for each step
117+
- Avoid generic names like "Run script"
118+
119+
## 8. Testing Strategy
120+
121+
### ✅ Before Publishing
122+
1. **Local testing**: Test in another repository using branch reference
123+
```yaml
124+
uses: username/repo@branch-name
125+
```
126+
127+
2. **Commit testing**: Test specific commits
128+
```yaml
129+
uses: username/repo@commit-sha
130+
```
131+
132+
3. **Tag testing**: Create and test release tags
133+
```yaml
134+
uses: username/repo@v1.0.0
135+
```
136+
137+
### ✅ Test Scenarios
138+
- Test with minimal required inputs
139+
- Test with all optional inputs
140+
- Test error conditions (invalid tokens, unreachable API)
141+
- Test on different runners (ubuntu, macos, windows if applicable)
142+
143+
## 9. Marketplace Preparation
144+
145+
### ✅ Pre-Publication Checklist
146+
- [ ] Add LICENSE file (required for marketplace)
147+
- [ ] Create semantic version release (v1.0.0)
148+
- [ ] Test thoroughly from another repository
149+
- [ ] Verify branding displays correctly
150+
- [ ] Ensure README has no placeholder text
151+
- [ ] Add repository topics/tags
152+
- [ ] Configure repository description
153+
- [ ] Add GitHub repository metadata
154+
155+
### ✅ Release Strategy
156+
- Use semantic versioning (MAJOR.MINOR.PATCH)
157+
- Create major version tags (v1) pointing to latest minor/patch
158+
- Document breaking changes in release notes
159+
160+
## 10. Common Pitfalls Avoided
161+
162+
### ❌ Missing Shell Specification
163+
Composite actions MUST specify shell for run steps
164+
165+
### ❌ No Error Handling
166+
Always handle potential failures gracefully
167+
168+
### ❌ Outdated Action Versions
169+
Keep dependencies up-to-date (checkout@v4, not v2)
170+
171+
### ❌ Poor Input Documentation
172+
Users need to know what each input does and requires
173+
174+
### ❌ No Branding
175+
Actions without branding are less discoverable in marketplace
176+
177+
### ❌ Incomplete README
178+
Missing usage examples make actions hard to adopt
179+
180+
### ❌ No Testing Instructions
181+
Users should know how to test before publishing
182+
183+
## 11. GitHub Actions Specific Features Used
184+
185+
### ✅ Context Variables
186+
```yaml
187+
${{ github.repository }} # Current repository
188+
${{ github.sha }} # Commit SHA
189+
${{ github.ref_name }} # Branch/tag name
190+
${{ secrets.GITHUB_TOKEN }} # Auto-generated token
191+
```
192+
193+
### ✅ Environment Variables
194+
```yaml
195+
env:
196+
API_BASE: ${{ inputs.api_base }}
197+
```
198+
199+
### ✅ Input References
200+
```yaml
201+
${{ inputs.access_token }}
202+
${{ inputs.api_base }}
203+
```
204+
205+
## 12. Performance Considerations
206+
207+
### ✅ Efficient Script Fetching
208+
- Single API call to fetch script
209+
- No unnecessary downloads or processing
210+
211+
### ✅ Minimal Checkout
212+
- Uses default checkout settings (fast)
213+
- Only checks out when needed
214+
215+
## 13. Maintainability
216+
217+
### ✅ Clear Code Comments
218+
- Self-documenting step names
219+
- Informative echo messages
220+
221+
### ✅ Version Control
222+
- Proper git usage
223+
- Clean commit history
224+
- Semantic versioning for releases
225+
226+
### ✅ Documentation
227+
- Both user-facing (README.md) and developer-facing (README_LOCAL.md)
228+
- Inline documentation in action.yml
229+
230+
## Summary
231+
232+
This action follows GitHub's official best practices for:
233+
- Composite action structure
234+
- Security and token handling
235+
- Error handling and logging
236+
- Documentation and examples
237+
- Testing and marketplace publication
238+
239+
Following these practices ensures a reliable, secure, and maintainable GitHub Action that users can trust and easily integrate into their workflows.

action.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "CodeAnt CI Scan"
2+
description: "Runs CodeAnt CI security and code quality analysis on your GitHub repository"
3+
author: "CodeAnt AI"
4+
5+
branding:
6+
icon: "shield"
7+
color: "blue"
8+
9+
inputs:
10+
access_token:
11+
description: "GitHub PAT or repository token for authentication"
12+
required: true
13+
api_base:
14+
description: "Base URL for CodeAnt API (e.g., https://api.codeant.ai)"
15+
required: true
16+
default: "https://api.codeant.ai"
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Fetch CodeAnt scan script
25+
shell: bash
26+
env:
27+
API_BASE: ${{ inputs.api_base }}
28+
run: |
29+
set -e
30+
echo "Fetching CodeAnt scan script from ${API_BASE}..."
31+
if ! curl -fsSL -X GET "${API_BASE}/analysis/ci/scan/script/get" --output start_scan.sh.b64; then
32+
echo "Error: Failed to fetch scan script from ${API_BASE}"
33+
exit 1
34+
fi
35+
echo "Successfully fetched scan script"
36+
37+
- name: Prepare scan script
38+
shell: bash
39+
run: |
40+
set -e
41+
if ! base64 -d start_scan.sh.b64 > start_scan.sh; then
42+
echo "Error: Failed to decode scan script"
43+
exit 1
44+
fi
45+
chmod +x start_scan.sh
46+
echo "Scan script prepared successfully"
47+
48+
- name: Run CodeAnt analysis
49+
shell: bash
50+
run: |
51+
set -e
52+
echo "Starting CodeAnt analysis..."
53+
bash start_scan.sh \
54+
-a "${{ inputs.access_token }}" \
55+
-r "${{ github.repository }}" \
56+
-c "${{ github.sha }}" \
57+
-b "${{ github.ref_name }}" \
58+
-s github \
59+
-i "" \
60+
-e ""
61+
echo "CodeAnt analysis completed"

0 commit comments

Comments
 (0)