apx-toolkit
Version:
Automatically discover APIs and generate complete integration packages: code in 12 languages, TypeScript types, test suites, SDK packages, API documentation, mock servers, performance reports, and contract tests. Saves 2-4 weeks of work in seconds.
142 lines (126 loc) • 4.43 kB
JavaScript
/**
* GitHub Actions Generator
* Generates GitHub Actions workflow files for automated API discovery
*/
/**
* Generate GitHub Actions workflow for API discovery
*/
export function generateGitHubActionsWorkflow(config = {}) {
const { schedule = '0 0 * * *', // Daily at midnight
apiUrlSecret = 'API_URL', autoCommit = true, autoPR = true, branch = 'apx/auto-update', outputPath = './apx-output', apifyTokenSecret = 'APIFY_TOKEN', actorId = '2eXbQISXqhTnIxWNJ', } = config;
return `name: APX API Discovery
on:
schedule:
# Run daily at midnight UTC
- cron: '${schedule}'
workflow_dispatch: # Allow manual trigger
inputs:
api_url:
description: 'API URL to discover'
required: false
type: string
jobs:
discover-api:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: \${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install APX Toolkit
run: npm install -g apx-toolkit
- name: Discover API
env:
API_URL: \${{ inputs.api_url || secrets.${apiUrlSecret} }}
APIFY_TOKEN: \${{ secrets.${apifyTokenSecret} }}
run: |
if [ -z "$API_URL" ]; then
echo "Error: API_URL not set"
exit 1
fi
# Run APX discovery
apx --url "$API_URL" --output ${outputPath}
# Or use Apify Actor
# apify call ${actorId} --input-file=.github/apx-input.json
- name: Check for changes
id: changes
run: |
if [ -n "$(git status --porcelain ${outputPath})" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
${autoCommit ? ` - name: Commit changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ${outputPath}
git commit -m "chore: auto-update API discovery [skip ci]"
git push` : ''}
${autoPR ? ` - name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: \${{ secrets.GITHUB_TOKEN }}
branch: ${branch}
title: '🤖 Auto-update: API Discovery Results'
body: |
## Automated API Discovery Update
This PR contains automatically discovered API changes.
**Generated by:** APX Toolkit
**Date:** \${{ github.event.head_commit.timestamp }}
### Changes
- Updated API documentation
- Updated code snippets
- Updated TypeScript types
- Updated test suites
- Updated SDK packages
### Review
Please review the changes and merge if everything looks good.
commit-message: 'chore: auto-update API discovery'
delete-branch: true` : ''}
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: apx-output
path: ${outputPath}
retention-days: 30
`;
}
/**
* Generate input JSON for Apify Actor
*/
export function generateApifyInput(apiUrl, options = {}) {
return JSON.stringify({
startUrls: [{ url: apiUrl }],
maxPages: options.maxPages || 100,
maxConcurrency: options.maxConcurrency || 5,
generateDocumentation: options.generateDocumentation !== false,
exportFormats: options.exportFormats || ['openapi', 'postman', 'curl'],
enableInteractionSimulation: options.enableInteractionSimulation !== false,
...options,
}, null, 2);
}
/**
* Generate complete GitHub Actions setup
*/
export function generateGitHubActionsSetup(apiUrl, config = {}) {
return {
workflow: generateGitHubActionsWorkflow({
...config,
apiUrl,
}),
input: generateApifyInput(apiUrl, config),
};
}
//# sourceMappingURL=github-actions-generator.js.map