codegen #2241
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
schedule: | |
# Runs at 12:30, 1:30 and 2:30. | |
- cron: '30 0-2 * * *' | |
workflow_dispatch: | |
name: codegen | |
jobs: | |
discovery: | |
# As of November 2023, it returns 269 service names. | |
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: | |
# As of November 2023, the output of batch job is a 3-element array, which contains a chunk of 100 service names | |
# at the index 0, a chunk of other 100 service names at the index 1, and a chunk of remaining 69 service names | |
# at the index 2. | |
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 excludedServices = ['contentwarehouse'] | |
const filteredServices = services.filter(service => !excludedServices.includes(service)) | |
const hour = new Date().getHours() | |
const MAX_BATCH_SIZE = 100 | |
const result = { | |
batches: [], | |
hour: new Date().getHours(), | |
}; | |
for (let i = 0; i < filteredServices.length; i += MAX_BATCH_SIZE) { | |
result.batches.push(filteredServices.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 size of the batch is implicitly decided by the hour of the day. | |
# For example, a job starting at "1:30" uses the chunk at the index 1 in the array. | |
# If you manually invoke the workflow other hours than 0:00 - 2:59 and the array's length is 3, | |
# this job is skipped because there's no element at the index in the array. | |
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])}} |