Skip to content

Check and Generate Updates #60

Check and Generate Updates

Check and Generate Updates #60

name: Check and Generate Updates
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run - check only without generating'
required: false
type: boolean
default: false
jobs:
check-for-updates:
name: Check for CAPI updates
runs-on: ubuntu-latest
outputs:
has_updates: ${{ steps.check.outputs.has_updates }}
new_versions: ${{ steps.check.outputs.new_versions }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.38'
- name: Install dependencies
run: |
cpanm --quiet --notest LWP::UserAgent JSON::XS XML::Simple File::Slurp Term::ANSIColor
- name: Check current versions
id: current
run: |
# Get list of already processed versions
PROCESSED_VERSIONS=$(ls -1 capi/ | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V)
echo "processed_versions<<EOF" >> $GITHUB_OUTPUT
echo "$PROCESSED_VERSIONS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Get the latest processed version
LATEST=$(echo "$PROCESSED_VERSIONS" | tail -1)
echo "latest_version=$LATEST" >> $GITHUB_OUTPUT
- name: Check for new CAPI releases
id: check
run: |
# Check CAPI releases page
CAPI_RELEASES=$(curl -s https://api.github.com/repos/cloudfoundry/cloud_controller_ng/releases | \
jq -r '.[].tag_name' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V)
# Find new versions
NEW_VERSIONS=""
for version in $CAPI_RELEASES; do
if ! echo "${{ steps.current.outputs.processed_versions }}" | grep -q "^$version$"; then
NEW_VERSIONS="$NEW_VERSIONS $version"
fi
done
# Trim whitespace
NEW_VERSIONS=$(echo $NEW_VERSIONS | xargs)
if [[ -n "$NEW_VERSIONS" ]]; then
echo "has_updates=true" >> $GITHUB_OUTPUT
# Convert to JSON array
JSON_VERSIONS=$(echo $NEW_VERSIONS | tr ' ' '\n' | jq -R . | jq -s .)
echo "new_versions=$JSON_VERSIONS" >> $GITHUB_OUTPUT
echo "Found new versions: $NEW_VERSIONS"
else
echo "has_updates=false" >> $GITHUB_OUTPUT
echo "new_versions=[]" >> $GITHUB_OUTPUT
echo "No new versions found"
fi
generate-and-test:
name: Generate and test new versions
needs: check-for-updates
if: needs.check-for-updates.outputs.has_updates == 'true' && inputs.dry_run != true
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJson(needs.check-for-updates.outputs.new_versions) }}
max-parallel: 1 # Process versions sequentially
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate OpenAPI spec and SDK
id: generate
uses: ./.github/workflows/generate.yml
with:
version: ${{ matrix.version }}
skip-tests: false
- name: Run comprehensive tests
uses: ./.github/workflows/test-comprehensive.yml
with:
version: ${{ matrix.version }}
- name: Create feature branch
id: branch
run: |
BRANCH_NAME="capi-update-${{ matrix.version }}"
git checkout -b $BRANCH_NAME
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Commit generated files
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# Add generated files
git add capi/${{ matrix.version }}/
git add sdk/${{ matrix.version }}/
# Create commit message
COMMIT_MSG="feat: Add CAPI v${{ matrix.version }} OpenAPI specification and SDK
- Generated OpenAPI specification from CAPI documentation
- Generated Go SDK using oapi-codegen
- Validated specification and examples
- Generated API documentation
This update was automatically generated by the check-and-generate workflow."
git commit -m "$COMMIT_MSG"
- name: Push branch
run: |
git push origin ${{ steps.branch.outputs.branch_name }}
- name: Create pull request
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `feat: Add CAPI v${{ matrix.version }} support`,
head: '${{ steps.branch.outputs.branch_name }}',
base: 'main',
body: `## Summary
This PR adds support for CAPI v${{ matrix.version }}.
## Changes
- πŸ“„ Generated OpenAPI specification from CAPI v${{ matrix.version }} documentation
- πŸ”§ Generated Go SDK using oapi-codegen
- βœ… Validated specification, examples, and schemas
- πŸ“š Generated API documentation
## Validation
All automated tests have passed:
- OpenAPI specification validation βœ…
- Example validation βœ…
- Schema testing βœ…
- SDK generation testing βœ…
## Next Steps
1. Review the generated OpenAPI specification
2. Review the generated Go SDK
3. Merge this PR
4. Publish the Go client to [capi-openapi-go-client](https://github.com/cloudfoundry-community/capi-openapi-go-client)
---
*This PR was automatically generated by the check-and-generate workflow.*`,
labels: ['capi-update', 'automated']
});
console.log(`Created PR: ${pr.html_url}`);
// Add reviewers if configured
const reviewers = process.env.PR_REVIEWERS?.split(',').filter(r => r);
if (reviewers && reviewers.length > 0) {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
reviewers: reviewers
});
}
create-summary-issue:
name: Create summary issue
needs: [check-for-updates, generate-and-test]
if: needs.check-for-updates.outputs.has_updates == 'true'
runs-on: ubuntu-latest
steps:
- name: Create or update tracking issue
uses: actions/github-script@v7
with:
script: |
const versions = ${{ needs.check-for-updates.outputs.new_versions }};
const isDryRun = ${{ inputs.dry_run || false }};
// Check for existing open issue
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'capi-updates-tracking',
state: 'open'
});
let body = `## CAPI Updates Summary
**Date**: ${new Date().toISOString().split('T')[0]}
**New versions detected**: ${versions.join(', ')}
### Status
`;
if (isDryRun) {
body += `
⚠️ **Dry run mode** - No files were generated or PRs created.
To process these updates, run the workflow again without dry run mode.`;
} else {
body += `
βœ… Generation and testing completed for all versions.
### Pull Requests Created
`;
for (const version of versions) {
body += `- [ ] CAPI v${version}: PR pending (check PRs tab)\n`;
}
body += `
### Next Steps
1. Review each PR for accuracy
2. Merge approved PRs
3. Run the publish-go-client workflow for each merged version
`;
}
body += `
---
*This issue was automatically generated by the check-and-generate workflow.*`;
if (issues.length > 0) {
// Update existing issue
const issue = issues[0];
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: body
});
// Add comment about new updates
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `πŸ”„ Updated with new CAPI versions: ${versions.join(', ')}`
});
} else {
// Create new issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `CAPI Updates Available: ${versions.join(', ')}`,
body: body,
labels: ['capi-updates-tracking', 'automated']
});
}
summary:
name: Workflow Summary
needs: [check-for-updates, generate-and-test]
if: always()
runs-on: ubuntu-latest
steps:
- name: Create workflow summary
run: |
echo "## Check and Generate Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.check-for-updates.outputs.has_updates }}" == "true" ]]; then
echo "### πŸ†• New Versions Found" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
VERSIONS='${{ needs.check-for-updates.outputs.new_versions }}'
echo "The following new CAPI versions were detected:" >> $GITHUB_STEP_SUMMARY
echo "$VERSIONS" | jq -r '.[]' | while read version; do
echo "- v$version" >> $GITHUB_STEP_SUMMARY
done
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Dry run mode** - No actions were taken." >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "### βœ… Actions Taken" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Generated OpenAPI specifications" >> $GITHUB_STEP_SUMMARY
echo "2. Generated Go SDKs" >> $GITHUB_STEP_SUMMARY
echo "3. Ran comprehensive tests" >> $GITHUB_STEP_SUMMARY
echo "4. Created pull requests for review" >> $GITHUB_STEP_SUMMARY
fi
else
echo "### βœ… No Updates Required" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All CAPI versions are up to date." >> $GITHUB_STEP_SUMMARY
fi