11on :
22 schedule :
3- # daily at 12 :30 am
4- - cron : ' 30 0 * * *'
3+ # every one hour from 00 :30 to 03:30
4+ - cron : ' 30 0-3 * * *'
55 workflow_dispatch :
66
77name : codegen
88jobs :
99 discovery :
1010 uses : googleapis/discovery-artifact-manager/.github/workflows/list-services.yml@master
11+ total_service_size_check :
12+ runs-on : ubuntu-20.04
13+ needs : discovery
14+ steps :
15+ - uses : actions/github-script@v5
16+ id : chunk
17+ with :
18+ script : |
19+ console.log('checking size of services')
20+ const MAX_SERVICE_SIZE = 400 // 00:30 to 03:30 implies 4 batches of size 100
21+ const services = ${{ needs.discovery.outputs.services }}
22+ if (services.length > MAX_SERVICE_SIZE) {
23+ throw new Error(`Total services (${services.length}) exceed limit of ${MAX_SERVICE_SIZE}`)
24+ }
1125 batch :
1226 runs-on : ubuntu-20.04
1327 needs : discovery
@@ -20,88 +34,19 @@ jobs:
2034 script : |
2135 console.log('splitting service names list into batches')
2236 const services = ${{ needs.discovery.outputs.services }}
37+ const hour = new Date().getHours()
38+ const MAX_BATCH_SIZE = 100
2339 const result = {
24- "one" : [],
25- "two": [] ,
40+ batches : [],
41+ hour: new Date().getHours() ,
2642 };
27- for (let i = 0; i < services.length; i++) {
28- resultBatchKey = i % 2 ? "one" : "two";
29- result[resultBatchKey].push(services[i])
43+ for (let i = 0; i < services.length; i += MAX_BATCH_SIZE) {
44+ result.batches.push(services.slice(i, i + MAX_BATCH_SIZE))
3045 }
3146 return result
32- generate_one :
33- runs-on : ubuntu-20.04
34- needs : batch
35- strategy :
36- fail-fast : false
37- max-parallel : 4
38- matrix :
39- service : ${{fromJson(needs.batch.outputs.services).one}}
40- steps :
41- - run : echo generating ${{ matrix.service }}
42- - uses : actions/checkout@v2
43- with :
44- fetch-depth : 1
45- path : google-api-java-client-services
46- - uses : actions/checkout@v2
47- with :
48- repository : googleapis/discovery-artifact-manager
49- fetch-depth : 1
50- path : discovery-artifact-manager
51- - uses : actions/setup-python@v4
52- with :
53- python-version : 2.7.18
54- - run : ./google-api-java-client-services/.github/workflows/generate.sh ${{ matrix.service }}
55- - uses : googleapis/code-suggester@v2 # takes the changes from git directory
56- env :
57- ACCESS_TOKEN : ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
58- with :
59- command : pr
60- upstream_owner : ${{ github.repository_owner }}
61- upstream_repo : google-api-java-client-services
62- description : ' Generated in GitHub action: https://github.com/${{ github.repository_owner }}/${{ github.repository }}/actions/workflows/codegen.yaml'
63- title : ' chore: regenerate ${{ matrix.service }} client'
64- message : ' chore: regenerate ${{ matrix.service }} client'
65- branch : regenerate-${{ matrix.service }}
66- git_dir : ' google-api-java-client-services/clients/google-api-services-${{ matrix.service }}'
67- primary : main
68- force : true
69- fork : true
70- generate_two :
71- runs-on : ubuntu-20.04
47+ generate :
48+ uses : googleapis/google-api-java-client-services/.github/workflows/generate.yaml@master
7249 needs : batch
73- strategy :
74- fail-fast : false
75- max-parallel : 4
76- matrix :
77- service : ${{fromJson(needs.batch.outputs.services).two}}
78- steps :
79- - run : echo generating ${{ matrix.service }}
80- - uses : actions/checkout@v2
81- with :
82- fetch-depth : 1
83- path : google-api-java-client-services
84- - uses : actions/checkout@v2
85- with :
86- repository : googleapis/discovery-artifact-manager
87- fetch-depth : 1
88- path : discovery-artifact-manager
89- - uses : actions/setup-python@v4
90- with :
91- python-version : 2.7.18
92- - run : ./google-api-java-client-services/.github/workflows/generate.sh ${{ matrix.service }}
93- - uses : googleapis/code-suggester@v2 # takes the changes from git directory
94- env :
95- ACCESS_TOKEN : ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
96- with :
97- command : pr
98- upstream_owner : ${{ github.repository_owner }}
99- upstream_repo : google-api-java-client-services
100- description : ' Generated in GitHub action: https://github.com/${{ github.repository_owner }}/${{ github.repository }}/actions/workflows/codegen.yaml'
101- title : ' chore: regenerate ${{ matrix.service }} client'
102- message : ' chore: regenerate ${{ matrix.service }} client'
103- branch : regenerate-${{ matrix.service }}
104- git_dir : ' google-api-java-client-services/clients/google-api-services-${{ matrix.service }}'
105- primary : main
106- force : true
107- fork : true
50+ if : ${{!!fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour]}}
51+ with :
52+ services : ${{toJson(fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour])}}
0 commit comments