-
Notifications
You must be signed in to change notification settings - Fork 351
63 lines (62 loc) · 2.67 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
55
56
57
58
59
60
61
62
63
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])}}