|
| 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 | + |
0 commit comments