You are automating the full PR workflow for the redhat-developer/rhdh-plugins monorepo. Follow every step below in order. Do not skip steps.
Check if the user invoked this command with --a (auto-approve mode).
- If
--ais present: set auto-approve mode. All approval gates (Steps 3, 7, and 8) are skipped — proceed automatically without asking the user. - If
--ais NOT present (default): where an approval gate is marked, you must ask the user before proceeding.
- Run
git diff --cached --name-onlyto list all staged files. - If no files are staged, stop and tell the user: "No staged changes found. Please stage your changes with
git addbefore running this command." - Extract the workspace(s) from the staged file paths. The workspace is the second path segment (e.g.,
workspaces/bulk-import/plugins/foo/src/index.ts→ workspace isworkspaces/bulk-import). - If staged files span multiple workspaces, inform the user: "Changes detected in N workspace(s):
<workspace-1>,<workspace-2>, … Are you sure you want to proceed? (Yes/No)". Wait for confirmation before continuing. If the user declines, stop. - Store the list of workspace names (e.g.,
["bulk-import", "lightspeed"]) and workspace paths (e.g.,["workspaces/bulk-import", "workspaces/lightspeed"]) for use in later steps.
Run git status --porcelain and save the full output as the baseline snapshot. This captures all files that were already dirty or untracked before any build commands run. You will need this in Step 7 to filter out pre-existing changes.
- Run
git branch --show-currentto determine the current branch. - If the current branch is
main: a. Analyze the staged diff (git diff --cached) to understand the nature of the changes. b. Generate a descriptive branch name in the format:feat/<workspace-name>-<short-description>(usefix/prefix for bug fixes). If multiple workspaces are affected, use a general description instead of a single workspace name. c. If NOT in auto-approve mode: ask the user for approval before proceeding. Present the proposed branch name and a one-line summary of the changes. If in auto-approve mode (--a): skip approval and proceed immediately. d. Run:git checkout -b <branch-name> - If the current branch is NOT
main: skip branch creation and continue on the current branch. Inform the user: "Already on branch<branch-name>, skipping branch creation."
For each workspace detected in Step 1, run the following commands sequentially inside that workspace's directory (e.g., workspaces/bulk-import). If any command fails, stop immediately and report the error to the user with the failing command, workspace, and its output.
Repeat this block for every workspace:
-
Pre-build cleanup — remove stale
dist/directories that may contain root-owned files from previous Docker or sudo builds. Run:rm -rf plugins/*/dist packages/*/distIf this fails with a permission error (
EACCES), automatically escalate to:sudo rm -rf plugins/*/dist packages/*/distThis is safe because the glob is scoped strictly to plugin/package dist directories within the workspace — it never touches
node_modules. Never usefind -name distor any broad recursive search that could deletedist/insidenode_modules. -
yarn— install dependencies -
yarn prettier:fix— format code -
yarn tsc:full— full TypeScript type check -
yarn build:all— build all packages -
yarn test --watchAll=false— run tests (disable Jest watch mode so it exits after running) -
yarn build:api-reports:only— generate/update API reports
For each workspace detected in Step 1, generate a separate changeset:
- From the staged diff (
git diff --cached), determine:- Which plugins under this workspace are affected. Only look at
plugins/*directories — ignorepackages/*entirely (those are private app/backend packages that are never published and never need changesets). - Within each plugin, only include it if it has changes inside
src/or other published paths (e.g., root-levelindex.ts,config.d.ts,package.json). Changes that are only in non-published paths likedev/,tests/,__fixtures__/, or storybook stories do NOT require a changeset for that plugin — skip it. - Read each affected plugin's
package.jsonto get its npm package name (e.g.,@red-hat-developer-hub/backstage-plugin-bulk-import). - The semver bump type: use
patchfor bug fixes,minorfor new features or enhancements,majorfor breaking changes. Infer from the nature of the diff. - If no plugins in the workspace have published-source changes, skip changeset generation for that workspace entirely.
- Which plugins under this workspace are affected. Only look at
- Generate a short, human-readable summary of the change for this workspace (1-2 sentences).
- Generate a random changeset ID (lowercase letters, 5-8 characters, e.g.,
happy-pens-smile). Use a pattern of<adjective>-<noun>-<verb>with random words. Each workspace must get a unique ID. - Write the changeset file directly to
<workspace>/.changeset/<random-id>.md:
---
'<package-name>': <bump-type>
---
<generated summary>
If multiple packages within the same workspace are affected, list each on its own line in the YAML front matter.
Do NOT run yarn changeset interactively. The files must be created programmatically with zero user prompts.
- Run
git status --porcelainto get the current snapshot of dirty/untracked files. - Compare the current snapshot against the baseline snapshot captured in Step 2.
- Files that appear only in the current snapshot (not in the baseline) are build-generated files — these were created or modified by the build commands in Step 4 or the changeset in Step 5.
- Files that were already in the baseline must be excluded — they are pre-existing local changes (e.g.,
app-config.yamloverrides, test fixtures, dev-only files) and should NOT be staged.
- Present the filtered list of build-generated files (from Step 6) to the user.
- If NOT in auto-approve mode: ask the user for approval before staging. If in auto-approve mode (
--a): skip approval and stage all build-generated files automatically. - Run
git addfor each approved/auto-approved file.
- Run
git diff --cached --statto review all staged changes (original + build-generated). - Generate a commit message based on the full staged diff. Follow conventional commit format:
<type>(<workspace>): <short description>(e.g.,feat(bulk-import): add support for batch repository imports). - If NOT in auto-approve mode: ask the user for approval. Present the proposed commit message and a summary of staged files. If in auto-approve mode (
--a): skip approval and commit immediately with the generated message. - Commit with the
-sflag (Signed-off-by):
git commit -s -m "<approved-message>"
- Push the branch to origin:
git push -u origin HEAD
- Generate a PR title from the commit message / change summary.
- Create the PR against the
mainbranch ofredhat-developer/rhdh-pluginsusinggh pr create. Use the following body template (pass via HEREDOC):
gh pr create --repo redhat-developer/rhdh-plugins --base main --title "<pr-title>" --body "$(cat <<'EOF'
## Description
<generated description of the feature/change — 2-4 sentences explaining what changed and why>
## Fixed
- <Jira link — ask the user for the Jira ticket URL, or leave as TODO if not provided>
## ✔️ Checklist
- [x] A changeset describing the change and affected packages. ([more info](https://github.com/redhat-developer/rhdh-plugins/blob/main/CONTRIBUTING.md#creating-changesets))
- [ ] Added or Updated documentation
- [ ] Tests for new functionality and regression tests for bug fixes
- [ ] Screenshots attached (for UI changes)
EOF
)"
- If the PR is created successfully, clearly display the PR URL to the user as the final output so they can open it directly.