Skip to content

codegen

codegen #627

Workflow file for this run

on:
schedule:
# every one hour from 00:30 to 03:30
- cron: '30 0-3 * * *'
workflow_dispatch:
name: codegen
jobs:
discovery:
uses: googleapis/discovery-artifact-manager/.github/workflows/list-services.yml@master
total_service_size_check:
runs-on: ubuntu-20.04
needs: discovery
steps:
- uses: actions/github-script@v5
id: chunk
with:
script: |
console.log('checking size of services')
const MAX_SERVICE_SIZE = 400 // 00:30 to 03:30 implies 4 batches of size 100
const services = ${{ needs.discovery.outputs.services }}
if (services.length > MAX_SERVICE_SIZE) {
throw new Error(`Total services (${services.length}) exceed limit of ${MAX_SERVICE_SIZE}`)
}
batch:
runs-on: ubuntu-20.04
needs: discovery
outputs:
services: ${{ steps.chunk.outputs.result }}
steps:
- uses: actions/github-script@v5
id: chunk
with:
script: |
console.log('splitting service names list into batches')
const services = ${{ needs.discovery.outputs.services }}
const hour = new Date().getHours()
const MAX_BATCH_SIZE = 100
const result = {
batches: [],
hour: new Date().getHours(),
};
for (let i = 0; i < services.length; i += MAX_BATCH_SIZE) {
result.batches.push(services.slice(i, i + MAX_BATCH_SIZE))
}
return result
generate:
uses: googleapis/google-api-java-client-services/.github/workflows/generate.yaml@main
needs: batch
secrets: inherit
if: ${{!!fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour]}}
with:
services: ${{toJson(fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour])}}