Skip to content

Commit 879071d

Browse files
committed
chore(ci): add daily librarian workflow to update googleapis commitish
1 parent 8a9fab9 commit 879071d

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Update librarian googleapis commitish
16+
on:
17+
schedule:
18+
- cron: '0 3 * * *' # Run once a day at 3:00 AM UTC
19+
workflow_dispatch: # Allow manual trigger
20+
jobs:
21+
update-librarian-googleapis:
22+
runs-on: ubuntu-24.04
23+
defaults:
24+
run:
25+
working-directory: google-cloud-java
26+
steps:
27+
- name: Checkout google-cloud-java
28+
uses: actions/checkout@v6
29+
with:
30+
repository: googleapis/google-cloud-java
31+
path: google-cloud-java
32+
fetch-depth: 0
33+
- name: Check for Open PR
34+
env:
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
set -x
38+
current_branch="update-librarian-googleapis-main"
39+
40+
# Try to find an open pull request associated with the branch
41+
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
42+
43+
if [ -n "${pr_num}" ]; then
44+
echo "Error: An open Pull Request already exists for this update: PR #${pr_num}."
45+
echo "Please merge or close the existing PR before running this workflow again."
46+
exit 1 # Fails this step and the workflow
47+
fi
48+
- name: Set up Go
49+
uses: actions/setup-go@v5
50+
with:
51+
go-version: '>=1.20.2'
52+
- name: Run librarian update
53+
run: |
54+
version=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
55+
go run "github.com/googleapis/librarian/cmd/librarian@${version}" update sources.googleapis
56+
- name: Detect Changes
57+
id: detect
58+
run: |
59+
git add librarian.yaml
60+
changed_files=$(git diff --cached --name-only)
61+
if [[ "${changed_files}" == "" ]]; then
62+
echo "has_changes=false" >> $GITHUB_OUTPUT
63+
echo "No changes in librarian.yaml"
64+
else
65+
echo "has_changes=true" >> $GITHUB_OUTPUT
66+
67+
# Get the new commit hash
68+
new_commit=$(git diff --cached librarian.yaml | grep -E '^\+ commit:' | head -n 1 | awk '{print $3}')
69+
echo "new_commit=${new_commit}" >> $GITHUB_OUTPUT
70+
71+
if [ -n "${new_commit}" ]; then
72+
echo "title=chore: update googleapis commitish to ${new_commit:0:7}" >> $GITHUB_OUTPUT
73+
echo "body=Updated googleapis commitish in librarian.yaml to https://github.com/googleapis/googleapis/commit/${new_commit}" >> $GITHUB_OUTPUT
74+
else
75+
echo "title=chore: update googleapis commitish in librarian.yaml" >> $GITHUB_OUTPUT
76+
echo "body=Updated googleapis commitish in librarian.yaml to the latest version." >> $GITHUB_OUTPUT
77+
fi
78+
fi
79+
- name: Commit and Create PR
80+
if: steps.detect.outputs.has_changes == 'true'
81+
env:
82+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}
83+
PR_TITLE: ${{ steps.detect.outputs.title }}
84+
PR_BODY: ${{ steps.detect.outputs.body }}
85+
run: |
86+
set -x
87+
[ -z "$(git config user.email)" ] && git config --global user.email "cloud-java-bot@google.com"
88+
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
89+
90+
base_branch="main"
91+
current_branch="update-librarian-googleapis-${base_branch}"
92+
93+
# Create and switch to the branch (force checkout -B to discard any local state on this branch name if it existed)
94+
git checkout -B "${current_branch}"
95+
96+
# Commit the changes (they are already staged by the Detect Changes step!)
97+
git commit -m "${PR_TITLE}"
98+
99+
# Push to remote (force push to overwrite any stale branch on remote)
100+
git remote add remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${{ github.repository }}.git" || git remote set-url remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${{ github.repository }}.git"
101+
git fetch -q remote_repo
102+
git push -f remote_repo "${current_branch}"
103+
104+
# Create the PR
105+
gh pr create --title "${PR_TITLE}" --head "${current_branch}" --body "${PR_BODY}" --base "${base_branch}"

0 commit comments

Comments
 (0)