Skip to content

Merge pull request #14 from MetroStar/enhance-settings #1

Merge pull request #14 from MetroStar/enhance-settings

Merge pull request #14 from MetroStar/enhance-settings #1

Workflow file for this run

# .github/workflows/update-api-docs.yml
name: Update API Documentation
on:
# Trigger on pushes to main branch (when API changes)
push:
branches: [main]
paths:
- "app/**"
workflow_dispatch: # Allow manual triggering of the workflow
jobs:
update-docs:
runs-on: ubuntu-latest
permissions:
contents: write
services:
# Start your API service (adjust based on your setup)
api:
image: your-api-image:latest # Replace with your API Docker image
ports:
- 5000:5000
options: >-
--health-cmd "curl -f http://localhost:5000/health || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If you need to build and start your API locally instead of using a service
- name: Setup Node.js (if needed)
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
# Alternative: Start API locally (uncomment if not using services above)
# - name: Install dependencies and start API
# run: |
# npm install
# npm run start &
# # Wait for API to be ready
# sleep 30
# curl --retry 10 --retry-delay 5 --retry-connrefused http://localhost:5000/health
- name: Wait for API to be ready
run: |
echo "Waiting for API to be ready..."
timeout 60 bash -c 'until curl -f http://localhost:5000/redoc; do sleep 2; done'
- name: Download OpenAPI spec
run: |
# Create docs directory if it doesn't exist
mkdir -p comet-api/docs
# Download the OpenAPI spec
curl -o comet-api/docs/openapi.json http://localhost:5000/openapi.json
# Verify the file was downloaded and is valid JSON
if [ ! -f "comet-api/docs/openapi.json" ]; then
echo "Error: Failed to download openapi.json"
exit 1
fi
# Basic JSON validation
if ! python -m json.tool comet-api/docs/openapi.json > /dev/null; then
echo "Error: Downloaded file is not valid JSON"
exit 1
fi
echo "Successfully downloaded OpenAPI spec"
- name: Install redoc-cli
run: npm install -g redoc-cli
- name: Generate HTML documentation
run: |
npx redoc-cli build comet-api/docs/openapi.json --output comet-api/docs/index.html
# Verify HTML was generated
if [ ! -f "comet-api/docs/index.html" ]; then
echo "Error: Failed to generate HTML documentation"
exit 1
fi
echo "Successfully generated HTML documentation"
- name: Check for changes
id: check_changes
run: |
# Check if there are any changes to commit
if git diff --quiet comet-api/docs/; then
echo "No changes detected in documentation"
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in documentation"
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.check_changes.outputs.changes == 'true'
run: |
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add and commit changes
git add comet-api/docs/openapi.json comet-api/docs/index.html
git commit -m "docs: update API documentation [automated]
- Updated OpenAPI specification
- Regenerated HTML documentation
Generated by GitHub Actions on $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
# Push changes
git push origin main
- name: Create summary
run: |
echo "## API Documentation Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_changes.outputs.changes }}" == "true" ]; then
echo "✅ Documentation updated successfully" >> $GITHUB_STEP_SUMMARY
echo "- OpenAPI spec downloaded from API" >> $GITHUB_STEP_SUMMARY
echo "- HTML documentation regenerated" >> $GITHUB_STEP_SUMMARY
echo "- Changes committed and pushed to main branch" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ No changes detected in documentation" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Documentation URL:** [View Docs](https://your-username.github.io/your-repo/comet-api/docs/)" >> $GITHUB_STEP_SUMMARY