Skip to content

Commit d1cc4c8

Browse files
committed
Action setup
0 parents  commit d1cc4c8

File tree

7 files changed

+619
-0
lines changed

7 files changed

+619
-0
lines changed

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish to Marketplace
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version tag (e.g., v1.0.0)'
10+
required: true
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Validate action.yml
20+
run: |
21+
# Basic validation
22+
if ! grep -q "name:" action.yml; then
23+
echo "❌ action.yml missing name"
24+
exit 1
25+
fi
26+
if ! grep -q "runs:" action.yml; then
27+
echo "❌ action.yml missing runs section"
28+
exit 1
29+
fi
30+
echo "✅ action.yml is valid"
31+
32+
- name: Create Release
33+
if: github.event_name == 'release'
34+
run: |
35+
echo "Release published: ${{ github.event.release.tag_name }}"
36+
echo "Release notes: ${{ github.event.release.body }}"
37+

.github/workflows/test-action.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test Action
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Test Code Discovery Action
21+
uses: ./
22+
id: discovery
23+
with:
24+
api-endpoint: ${{ secrets.API_DISCOVERY_ENDPOINT || 'https://api.example.com' }}
25+
api-token: ${{ secrets.API_DISCOVERY_TOKEN || 'test-token' }}
26+
dry-run: 'true'
27+
28+
- name: Display outputs
29+
run: |
30+
echo "Spec path: ${{ steps.discovery.outputs.spec-path }}"
31+
echo "Success: ${{ steps.discovery.outputs.success }}"
32+

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
env/
8+
venv/
9+
ENV/
10+
build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
wheels/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# IDE
27+
.vscode/
28+
.idea/
29+
*.swp
30+
*.swo
31+
*~
32+
33+
# OS
34+
.DS_Store
35+
Thumbs.db
36+
37+
# GitHub Actions
38+
.github/workflows/*.yml.bak
39+
40+
# Test files
41+
*.log
42+
test-results/
43+

IMPLEMENTATION_SUMMARY.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# GitHub Action Implementation Summary
2+
3+
## Repository Structure
4+
5+
```
6+
apisec-bolt-code-discovery-action/
7+
├── .github/
8+
│ └── workflows/
9+
│ ├── test-action.yml # Test workflow for the action
10+
│ └── publish.yml # Publishing workflow
11+
├── action.yml # Main action definition (REQUIRED)
12+
├── README.md # Documentation
13+
├── LICENSE # MIT License
14+
├── .gitignore # Git ignore rules
15+
└── IMPLEMENTATION_SUMMARY.md # This file
16+
```
17+
18+
## Key Features Implemented
19+
20+
### ✅ Simplified Inputs
21+
- **Required:** `api-endpoint`, `api-token`
22+
- **Optional:** `repo-path`, `config-path`, `pr-title`, `pr-body`, `dry-run`
23+
- **Removed:** `output-path`, `output-format`, `commit-spec`, `create-pr`, `cli-version`
24+
25+
### ✅ Hardcoded Values
26+
- **Output Path:** `apisec-bolt-code-discovery/openapi_spec.yaml`
27+
- **Output Format:** Always YAML
28+
- **CLI Version:** Pinned to `0.2.0`
29+
- **PR Creation:** Always enabled (never direct commit)
30+
31+
### ✅ State Management
32+
- State file location: `apisec-bolt-code-discovery/state.yaml`
33+
- Same directory as OpenAPI spec (no extra folders)
34+
- Automatically committed in PR
35+
36+
### ✅ Error Handling
37+
- Non-blocking: Uses `continue-on-error: true`
38+
- Warnings don't fail workflow
39+
- Graceful degradation
40+
41+
### ✅ PR Creation Flow
42+
1. Creates new branch: `code-discovery/update-openapi-{timestamp}`
43+
2. Commits generated files
44+
3. Pushes branch
45+
4. Creates PR using `gh` CLI
46+
5. Handles existing PRs (reuses if branch exists)
47+
48+
## Action Workflow Steps
49+
50+
1. **Install Code Discovery CLI**
51+
- Upgrades pip
52+
- Installs `code-discovery==0.2.0`
53+
54+
2. **Configure API Credentials**
55+
- Creates `~/.apisec` file
56+
- Sets permissions (600)
57+
58+
3. **Run API Discovery**
59+
- Executes CLI with proper arguments
60+
- Extracts outputs from state file
61+
- Sets GitHub outputs
62+
63+
4. **Create Pull Request**
64+
- Only runs if discovery succeeded and not dry-run
65+
- Creates branch, commits, pushes, creates PR
66+
- Handles edge cases (existing PRs, no changes, etc.)
67+
68+
## Outputs
69+
70+
- `spec-path`: Path to OpenAPI spec
71+
- `application-id`: From state file
72+
- `instance-id`: From state file
73+
- `pr-url`: Created PR URL
74+
- `success`: Boolean
75+
76+
## Required Permissions
77+
78+
```yaml
79+
permissions:
80+
contents: write # To commit files
81+
pull-requests: write # To create PRs
82+
```
83+
84+
## Next Steps for Publishing
85+
86+
1. **Initialize Git Repository**
87+
```bash
88+
cd /Users/mohsinniyazi/apisec-bolt-code-discovery-action
89+
git init
90+
git add .
91+
git commit -m "Initial commit: Code Discovery GitHub Action"
92+
```
93+
94+
2. **Create GitHub Repository**
95+
- Create public repository: `apisec-bolt/code-discovery-action`
96+
- Push code
97+
98+
3. **Create First Release**
99+
- Tag: `v1.0.0`
100+
- This makes the action available as `@v1` or `@v1.0.0`
101+
102+
4. **Publish to Marketplace**
103+
- Go to repository Settings → Marketplace
104+
- Click "Publish to GitHub Marketplace"
105+
- Fill in details:
106+
- Category: Security
107+
- Icon: search
108+
- Color: blue
109+
- Submit for review
110+
111+
## Testing
112+
113+
The action includes a test workflow (`.github/workflows/test-action.yml`) that can be used to test the action locally or in CI.
114+
115+
## Usage Example
116+
117+
```yaml
118+
name: API Discovery
119+
120+
on:
121+
push:
122+
branches: [main]
123+
124+
jobs:
125+
discover:
126+
runs-on: ubuntu-latest
127+
permissions:
128+
contents: write
129+
pull-requests: write
130+
steps:
131+
- uses: actions/checkout@v4
132+
- uses: apisec-bolt/code-discovery-action@v1
133+
with:
134+
api-endpoint: ${{ secrets.API_DISCOVERY_ENDPOINT }}
135+
api-token: ${{ secrets.API_DISCOVERY_TOKEN }}
136+
```
137+
138+
## Notes
139+
140+
- Action name: `apisec-bolt-code-discovery-action`
141+
- Marketplace category: Security
142+
- All files are in the same directory: `apisec-bolt-code-discovery/`
143+
- State management is automatic and default behavior
144+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 APIsec Bolt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

0 commit comments

Comments
 (0)