Skip to content

Commit b60a08d

Browse files
fix: generate batches at separate times (#16448)
* fix: generate batches at separate times * fix: correct workflow reference * fix: add organization to workflow reference * fix: checkout code before referencing local workflow * fix: use size-100 batches * fix: correct workflow reference at top level * fix: pass services as string * test: don't skip at testing moment * fix: serialize service list * chore: setup for production * fix: have generate.yaml to only be called from another workflow or dispatch * fix: use generate.yaml from master branch * feat: add check for total services exceeding max size (400 atm)
1 parent 636525c commit b60a08d

File tree

2 files changed

+78
-82
lines changed

2 files changed

+78
-82
lines changed

.github/workflows/codegen.yaml

Lines changed: 27 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
on:
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

77
name: codegen
88
jobs:
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])}}

.github/workflows/generate.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
services:
5+
required: true
6+
type: string
7+
workflow_call:
8+
inputs:
9+
services:
10+
required: true
11+
type: string
12+
13+
name: generate
14+
jobs:
15+
generate_one:
16+
runs-on: ubuntu-20.04
17+
strategy:
18+
fail-fast: false
19+
max-parallel: 4
20+
matrix:
21+
service: ${{fromJson(inputs.services)}}
22+
steps:
23+
- run: echo generating ${{ matrix.service }}
24+
- uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 1
27+
path: google-api-java-client-services
28+
- uses: actions/checkout@v2
29+
with:
30+
repository: googleapis/discovery-artifact-manager
31+
fetch-depth: 1
32+
path: discovery-artifact-manager
33+
- uses: actions/setup-python@v4
34+
with:
35+
python-version: 2.7.18
36+
- run: ./google-api-java-client-services/.github/workflows/generate.sh ${{ matrix.service }}
37+
- uses: googleapis/code-suggester@v2 # takes the changes from git directory
38+
env:
39+
ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
40+
with:
41+
command: pr
42+
upstream_owner: ${{ github.repository_owner }}
43+
upstream_repo: google-api-java-client-services
44+
description: 'Generated in GitHub action: https://github.com/${{ github.repository_owner }}/${{ github.repository }}/actions/workflows/codegen.yaml'
45+
title: 'chore: regenerate ${{ matrix.service }} client'
46+
message: 'chore: regenerate ${{ matrix.service }} client'
47+
branch: regenerate-${{ matrix.service }}
48+
git_dir: 'google-api-java-client-services/clients/google-api-services-${{ matrix.service }}'
49+
primary: main
50+
force: true
51+
fork: true

0 commit comments

Comments
 (0)