Skip to content

Generate OpenAPI Spec #17

Generate OpenAPI Spec

Generate OpenAPI Spec #17

name: Generate OpenAPI Spec
on:
workflow_run:
workflows: ["Publish Postman Collection & Environment"]
types:
- completed
jobs:
generate-openapi:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pyyaml ruamel.yaml
- name: Wait for Postman collection update
run: |
# Get the latest release tag from the repository
TAG=$(curl -s -H "Authorization: Bearer ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name' | sed 's/^v//')
echo "Current tag: $TAG"
# Function to check if collection is updated
check_collection() {
RESPONSE=$(curl -s -H "X-API-Key: ${{ secrets.POSTMAN_API_KEY }}" \
"https://api.getpostman.com/collections/${{ secrets.POSTMAN_COLLECTION_ID }}")
COLLECTION_NAME=$(echo "$RESPONSE" | jq -r '.collection.info.name')
echo "Collection name: $COLLECTION_NAME"
# Extract version using a more robust pattern
VERSION=$(echo "$COLLECTION_NAME" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/v//')
echo "Extracted version: $VERSION"
echo "Expected version: $TAG"
if [ "$VERSION" = "$TAG" ]; then
echo "Versions match!"
return 0
else
echo "Versions don't match"
return 1
fi
}
# Try up to 10 times with 5 second delay between attempts
for i in {1..10}; do
if check_collection; then
echo "Collection version matches tag $TAG"
exit 0
fi
echo "Collection not yet updated, attempt $i of 10"
sleep 5
done
echo "Failed to verify collection version after 10 attempts"
exit 1
- name: Generate OpenAPI spec
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
POSTMAN_COLLECTION_ID: ${{ secrets.POSTMAN_COLLECTION_ID }}
run: |
python scripts/ptoa_postprocess.py
- name: Configure Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Commit and push OpenAPI spec
run: |
TAG=$(curl -s -H "Authorization: Bearer ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name' | sed 's/^v//')
git add spec/udns_openapi.yml
git commit -m "chore: update OpenAPI spec for version $TAG"
git push