Skip to content

Commit e004e7c

Browse files
authored
build: create regenerate.sh (#334)
1 parent 4f4f7b9 commit e004e7c

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

tools/regenerate.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# @license
4+
# Copyright 2026 Google Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -e
8+
9+
# 1. Verify git working directory is clean before we start
10+
if [ -n "$(git status --porcelain)" ]; then
11+
echo "Error: Your git working directory is not clean." >&2
12+
echo "Please commit, stash, or discard your changes before running this script." >&2
13+
exit 1
14+
fi
15+
16+
# 2. Check requirements
17+
if ! command -v gh &> /dev/null; then
18+
echo "Error: 'gh' CLI is required but not installed." >&2
19+
echo "Please install it first (e.g. 'brew install gh')." >&2
20+
exit 1
21+
fi
22+
23+
if ! gh auth status &> /dev/null; then
24+
echo "Error: You are not authenticated with 'gh' CLI." >&2
25+
echo "Please run 'gh auth login' first." >&2
26+
exit 1
27+
fi
28+
if command -v cddlconv &> /dev/null; then
29+
CDDLCONV_VERSION=$(cddlconv --version 2>&1 | awk '{print $2}')
30+
if [ "$CDDLCONV_VERSION" != "0.1.7" ]; then
31+
echo "Warning: 'cddlconv' version is $CDDLCONV_VERSION, but 0.1.7 is required." >&2
32+
echo "You can install the correct version using: cargo install cddlconv@0.1.7" >&2
33+
fi
34+
else
35+
echo "Warning: 'cddlconv' is not installed or not in PATH." >&2
36+
echo "The build step might fail. You can install it using: cargo install cddlconv@0.1.7" >&2
37+
fi
38+
39+
# 3. Run build/regeneration steps
40+
echo "Running build and regeneration..."
41+
npm test
42+
43+
# 4. Check if any changes were produced
44+
CHANGES=$(git status --porcelain)
45+
if [ -z "$CHANGES" ]; then
46+
echo "No changes detected. Webdriver BiDi types are up to date!"
47+
exit 0
48+
fi
49+
50+
echo "Changes detected:"
51+
echo "$CHANGES"
52+
53+
# 5. Check out a branch for regeneration
54+
BRANCH_NAME="regenerate"
55+
CURRENT_BRANCH=$(git branch --show-current)
56+
57+
echo "Creating and switching to branch '$BRANCH_NAME'..."
58+
git checkout -B "$BRANCH_NAME"
59+
60+
# 6. Commit the changes
61+
echo "Committing changes..."
62+
# Stage all changes (including untracked/newly generated files)
63+
git add -A
64+
65+
# Commit using the user's configured git user
66+
git commit -m "fix: re-generate types based on spec updates"
67+
68+
# 7. Push the branch
69+
echo "Pushing '$BRANCH_NAME' branch to remote..."
70+
git push -f origin "$BRANCH_NAME"
71+
72+
# 8. Create or update the Pull Request
73+
echo "Creating/updating Pull Request..."
74+
75+
PR_TITLE="fix: re-generate types based on spec updates"
76+
PR_BODY="Automatically generated by tools/regenerate.sh"
77+
78+
# Check if a PR already exists for this head branch
79+
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number')
80+
81+
if [ -n "$EXISTING_PR" ]; then
82+
PR_URL=$(gh pr view "$EXISTING_PR" --json url --jq '.url')
83+
echo "Pull Request #$EXISTING_PR already exists for branch '$BRANCH_NAME'."
84+
echo "The branch has been force-pushed and the PR is now updated."
85+
echo "PR URL: $PR_URL"
86+
else
87+
# Create a new PR
88+
PR_URL=$(gh pr create \
89+
--title "$PR_TITLE" \
90+
--body "$PR_BODY" \
91+
--head "$BRANCH_NAME" \
92+
--base main)
93+
echo "Created Pull Request: $PR_URL"
94+
fi
95+
96+
# 9. Switch back to original branch
97+
if [ -n "$CURRENT_BRANCH" ] && [ "$CURRENT_BRANCH" != "$BRANCH_NAME" ]; then
98+
echo "Switching back to your original branch: $CURRENT_BRANCH..."
99+
git checkout "$CURRENT_BRANCH"
100+
fi
101+
102+
echo "Regeneration automation complete!"

0 commit comments

Comments
 (0)