Skip to content

Commit 5a460f0

Browse files
authored
ci(librarian): allow manual run on branches to commit/push generated diffs (#13568)
Updates the librarian generation check workflow to support manual triggers (workflow_dispatch) on branches and adds a step to commit and push any generated diffs back to the triggering branch when manually run. Fixes googleapis/librarian#6568
1 parent ca5ff79 commit 5a460f0

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

.github/workflows/librarian_generation_check.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
name: Librarian - Generate diff check on main
14+
15+
# This workflow runs a check to ensure that all generated libraries are up-to-date with
16+
# the latest configuration.
17+
#
18+
# Triggers:
19+
# 1. Push to main: Generates the libraries, checks for git diffs, and fails (creating
20+
# a Buganizer/GitHub issue) if any changes are detected.
21+
# 2. Manual trigger (workflow_dispatch) on a branch (except main): Generates the
22+
# libraries and commits the resulting diff directly back to the triggering branch.
23+
name: Librarian - Generate libraries check / update
1524
on:
1625
push:
1726
branches:
@@ -22,9 +31,14 @@ jobs:
2231
library_generation:
2332
runs-on: ubuntu-24.04
2433
permissions:
25-
contents: read
34+
contents: write
2635
issues: write
2736
steps:
37+
- name: Prevent running manually on main branch
38+
if: ${{ github.event_name == 'workflow_dispatch' && github.ref_name == 'main' }}
39+
run: |
40+
echo "Error: Running this workflow manually on the main branch is not allowed."
41+
exit 1
2842
- uses: actions/checkout@v4
2943
with:
3044
fetch-depth: 0
@@ -70,6 +84,7 @@ jobs:
7084
run: |
7185
librarian generate --all
7286
- name: Check for generated code changes
87+
if: ${{ github.event_name != 'workflow_dispatch' }}
7388
run: |
7489
if [ -n "$(git status --porcelain)" ]; then
7590
git status
@@ -79,8 +94,20 @@ jobs:
7994
echo "Regeneration produced code changes! Please run 'librarian generate --all' to update the generated files."
8095
exit 1
8196
fi
97+
- name: Commit and push changes (manual run only)
98+
if: ${{ github.event_name == 'workflow_dispatch' }}
99+
run: |
100+
if [ -n "$(git status --porcelain)" ]; then
101+
git config --global user.name 'github-actions[bot]'
102+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
103+
git add -A
104+
git commit -m "chore: regenerate libraries"
105+
git push
106+
else
107+
echo "No changes to commit"
108+
fi
82109
- name: Create issue if previous step fails
83-
if: ${{ failure() && github.ref == 'refs/heads/main' }}
110+
if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
84111
uses: googleapis/librarian/.github/actions/create-issue-on-failure@main
85112
with:
86113
title: "Librarian generate diff check failed on main branch"

0 commit comments

Comments
 (0)