Skip to content

codegen

codegen #1196

Workflow file for this run

on:
schedule:
# Runs at 12:30, 1:30 and 2:30.
- cron: '30 0-2 * * *'
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 = 300 // 00:30 to 02:30 implies 3 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
# The number of batch is implicitly decided by the hour of the day
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])}}