Skip to content

Commit cd29fa9

Browse files
authored
feat: create pr after library generation (googleapis#10503)
* feat: create pr after library generation * add comment * setup branch * create or update pr * enable workflow * setup github token * select one library to verify the workflow * change format * remove head * add quote * shorten config for testsing * add a library * add head * set remote repo * commit change in configuration * update googleapis commit * test body * set x * set x for docker * set env * change env * restore generation * remove gke v1alpha2 * add apphub * add chat * add cloudcontrolspartner (commented out) * remove compute small * update committish * restore cloudcontrolspartner * update policytroubleshooter * add v2 for securitycenter * add securityposture * add workspaceevents * change step order * add variable * edit title * use partial clone * use job level env * change commit message * change workflow name * allow empty commit * extract image tag * remove owlbot:run tag * change workflow name * define bash branch * remove branch dispatcher
1 parent add8caf commit cd29fa9

File tree

3 files changed

+156
-36
lines changed

3 files changed

+156
-36
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Generate GAPIC libraries from configuration
2+
on:
3+
schedule:
4+
- cron: '0 2 * * *' # nightly at 2 am UTC
5+
workflow_dispatch:
6+
7+
8+
jobs:
9+
generate-from-configuration:
10+
runs-on: ubuntu-22.04
11+
env:
12+
# the branch into which pull request is created.
13+
base_branch: main
14+
# the branch with which the pull request is associated.
15+
branch_name: generate-libraries-main
16+
library_generation_image_tag: latest
17+
repo_volumes: "-v repo-google-cloud-java:/workspace/google-cloud-java"
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: get baseline commit
21+
id: get-baseline
22+
shell: bash
23+
run: |
24+
echo "baseline_commit=$(grep googleapis_commitish generation_config.yaml | cut -d " " -f2 | xargs)" >> "$GITHUB_ENV"
25+
- name: setup branch for pull request
26+
id: setup-branch
27+
shell: bash
28+
run: |
29+
[ -z "`git config user.email`" ] && git config --global user.email "[email protected]"
30+
[ -z "`git config user.name`" ] && git config --global user.name "cloud-java-bot"
31+
# try to find a open pull request associated with the branch
32+
pr_num=$(gh pr list -s open -H "${branch_name}" -q . --json number | jq ".[] | .number")
33+
# create a branch if there's no open pull request associated with the
34+
# branch; otherwise checkout the pull request.
35+
if [ -z "${pr_num}" ]; then
36+
git checkout -b "${branch_name}"
37+
else
38+
gh pr checkout "${pr_num}"
39+
fi
40+
echo "pr_num=${pr_num}" >> "$GITHUB_ENV"
41+
env:
42+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
43+
- name: setup docker environment
44+
shell: bash
45+
run: |
46+
# we create a volume pointing to `pwd` (google-cloud-java) that will
47+
# be referenced by the container and its children
48+
if [[ $(docker volume inspect repo-google-cloud-java) != '[]' ]]; then
49+
docker volume rm repo-google-cloud-java
50+
fi
51+
docker volume create --name "repo-google-cloud-java" --opt "type=none" --opt "device=$(pwd)" --opt "o=bind"
52+
- name: update googleapis commit to latest
53+
id: update-commit
54+
shell: bash
55+
run: |
56+
mkdir tmp-googleapis
57+
# use partial clone because only commit history is needed.
58+
git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis
59+
pushd tmp-googleapis
60+
git pull
61+
latest_commit=$(git rev-parse HEAD)
62+
popd
63+
rm -rf tmp-googleapis
64+
sed -i -e "s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit}/" generation_config.yaml
65+
- name: generate from configuration
66+
shell: bash
67+
run: |
68+
docker run --rm \
69+
${repo_volumes} \
70+
-v /tmp:/tmp \
71+
-v /var/run/docker.sock:/var/run/docker.sock \
72+
-e "RUNNING_IN_DOCKER=true" \
73+
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
74+
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
75+
python /src/generate_repo.py generate --generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml --repository-path=/workspace/google-cloud-java
76+
- name: generate pull request description
77+
id: generate-description
78+
shell: bash
79+
run: |
80+
# the pr description (body) will be available in pr-description.txt after
81+
# running this command.
82+
set -x
83+
docker run --rm \
84+
${repo_volumes} \
85+
-v /tmp:/tmp \
86+
-v /var/run/docker.sock:/var/run/docker.sock \
87+
-e "RUNNING_IN_DOCKER=true" \
88+
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \
89+
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
90+
python /src/generate_pr_description.py generate --generation-config-yaml=/workspace/google-cloud-java/generation_config.yaml --baseline-commit="${baseline_commit}"
91+
env:
92+
baseline_commit: ${{ env.baseline_commit }}
93+
- name: create or update the pull request
94+
shell: bash
95+
run: |
96+
title="chore: generate libraries at $(date)"
97+
git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt generation_config.yaml
98+
# use --allow-empty because (rarely) there's no change.
99+
git commit --allow-empty -m "${title}"
100+
if [ -z "${pr_num}" ]; then
101+
git remote add monorepo https://cloud-java-bot:${GH_TOKEN}@github.com/${{ github.repository }}.git
102+
git fetch -q --unshallow monorepo
103+
git push -f monorepo "${branch_name}"
104+
set -x
105+
gh pr create --base "${base_branch}" --title "${title}" --head "${branch_name}" --body "$(cat pr_description.txt)"
106+
else
107+
git push
108+
gh pr edit "${pr_num}" --title "${title}"
109+
gh pr edit "${pr_num}" --body "$(cat pr_description.txt)"
110+
fi
111+
env:
112+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
113+
pr_num: ${{ env.pr_num }}

.github/workflows/verify-generation-config.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

generation_config.yaml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
gapic_generator_version: 2.37.0
22
protobuf_version: '25.2'
3-
googleapis_commitish: 20c357f6f5c7b995b617b15cab61999e6574bdab
3+
googleapis_commitish: 6500290663163ba7dc6e0a35231772f5f78c3b62
44
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
55
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
66
template_excludes:
@@ -167,6 +167,14 @@ libraries:
167167
GAPICs:
168168
- proto_path: google/appengine/v1
169169

170+
- api_shortname: apphub
171+
name_pretty: App Hub API
172+
product_documentation: https://cloud.google.com/app-hub/docs/overview
173+
api_description: App Hub simplifies the process of building, running, and managing applications on Google Cloud.
174+
rpc_documentation: https://cloud.google.com/app-hub/docs/reference/rpc
175+
GAPICs:
176+
- proto_path: google/cloud/apphub/v1
177+
170178
- api_shortname: area120tables
171179
name_pretty: Area 120 Tables
172180
product_documentation: https://area120.google.com/
@@ -434,6 +442,14 @@ libraries:
434442
GAPICs:
435443
- proto_path: google/cloud/channel/v1
436444

445+
- api_shortname: chat
446+
name_pretty: Google Chat API
447+
product_documentation: https://developers.google.com/chat/concepts
448+
api_description: The Google Chat API lets you build Chat apps to integrate your services with Google Chat and manage Chat resources such as spaces, members, and messages.
449+
rest_documentation: https://developers.google.com/chat/api/reference/rest
450+
GAPICs:
451+
- proto_path: google/chat/v1
452+
437453
- api_shortname: cloudbuild
438454
name_pretty: Cloud Build
439455
product_documentation: https://cloud.google.com/cloud-build/
@@ -459,6 +475,14 @@ libraries:
459475
- proto_path: google/cloud/commerce/consumer/procurement/v1
460476
- proto_path: google/cloud/commerce/consumer/procurement/v1alpha1
461477

478+
- api_shortname: cloudcontrolspartner
479+
name_pretty: Cloud Controls Partner API
480+
product_documentation: https://cloud.google.com/sovereign-controls-by-partners/docs/sovereign-partners
481+
api_description: Provides insights about your customers and their Assured Workloads based on your Sovereign Controls by Partners offering.
482+
GAPICs:
483+
- proto_path: google/cloud/cloudcontrolspartner/v1
484+
- proto_path: google/cloud/cloudcontrolspartner/v1beta
485+
462486
- api_shortname: cloudquotas
463487
name_pretty: Cloud Quotas API
464488
product_documentation: https://cloud.google.com/cloudquotas/docs/
@@ -490,7 +514,6 @@ libraries:
490514
excluded_dependencies: grpc-google-cloud-compute-v1
491515
GAPICs:
492516
- proto_path: google/cloud/compute/v1
493-
- proto_path: google/cloud/compute/v1small
494517

495518
- api_shortname: confidentialcomputing
496519
name_pretty: Confidential Computing API
@@ -922,7 +945,6 @@ libraries:
922945
GAPICs:
923946
- proto_path: google/cloud/gkehub/v1
924947
- proto_path: google/cloud/gkehub/v1alpha
925-
- proto_path: google/cloud/gkehub/v1alpha2
926948
- proto_path: google/cloud/gkehub/v1beta
927949
- proto_path: google/cloud/gkehub/v1beta1
928950

@@ -1336,6 +1358,7 @@ libraries:
13361358
api_id: policy-troubleshooter.googleapis.com
13371359
GAPICs:
13381360
- proto_path: google/cloud/policytroubleshooter/v1
1361+
- proto_path: google/cloud/policytroubleshooter/iam/v3
13391362

13401363
- api_shortname: policysimulator
13411364
name_pretty: Policy Simulator API
@@ -1530,7 +1553,7 @@ libraries:
15301553
- proto_path: google/cloud/security/privateca/v1
15311554
- proto_path: google/cloud/security/privateca/v1beta1
15321555

1533-
# duplicated api_shortname
1556+
# duplicated api_shortname
15341557
- api_shortname: securitycenter
15351558
name_pretty: Security Command Center
15361559
product_documentation: https://cloud.google.com/security-command-center
@@ -1549,6 +1572,7 @@ libraries:
15491572
- proto_path: google/cloud/securitycenter/v1
15501573
- proto_path: google/cloud/securitycenter/v1beta1
15511574
- proto_path: google/cloud/securitycenter/v1p1beta1
1575+
- proto_path: google/cloud/securitycenter/v2
15521576

15531577
- api_shortname: securitycenter
15541578
name_pretty: Security Command Center Settings API
@@ -1570,6 +1594,13 @@ libraries:
15701594
GAPICs:
15711595
- proto_path: google/cloud/securitycentermanagement/v1
15721596

1597+
- api_shortname: securityposture
1598+
name_pretty: Security Posture API
1599+
product_documentation: https://cloud.google.com/security-command-center/docs/security-posture-overview
1600+
api_description: Security Posture is a comprehensive framework of policy sets that empowers organizations to define, assess early, deploy, and monitor their security measures in a unified way and helps simplify governance and reduces administrative toil.
1601+
GAPICs:
1602+
- proto_path: google/cloud/securityposture/v1
1603+
15731604
- api_shortname: servicecontrol
15741605
name_pretty: Service Control API
15751606
product_documentation: https://cloud.google.com/service-infrastructure/docs/overview/
@@ -1964,6 +1995,14 @@ libraries:
19641995
- proto_path: google/cloud/workflows/v1
19651996
- proto_path: google/cloud/workflows/v1beta
19661997

1998+
- api_shortname: workspaceevents
1999+
name_pretty: Google Workspace Events API
2000+
product_documentation: https://developers.google.com/workspace/events
2001+
api_description: The Google Workspace Events API lets you subscribe to events and manage change notifications across Google Workspace applications.
2002+
rest_documentation: https://developers.google.com/workspace/events/reference/rest
2003+
GAPICs:
2004+
- proto_path: google/apps/events/subscriptions/v1
2005+
19672006
- api_shortname: workstations
19682007
name_pretty: Cloud Workstations
19692008
product_documentation: https://cloud.google.com/workstations

0 commit comments

Comments
 (0)