-
Notifications
You must be signed in to change notification settings - Fork 351
54 lines (53 loc) · 1.93 KB
/
codegen.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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])}}