-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: update roomotes.yml to checkout PR branch before running translation check #6539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine. I've reviewed the changes and left some suggestions inline to improve robustness.
| echo "Checking out PR branch: $GITHUB_HEAD_REF" | ||
| git fetch origin "$GITHUB_HEAD_REF" | ||
| git checkout -B "$GITHUB_HEAD_REF" "origin/$GITHUB_HEAD_REF" | ||
| elif [ -n "$GITHUB_REF" ] && [[ "$GITHUB_REF" =~ ^refs/pull/([0-9]+)/ ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional to use bash-specific syntax without explicitly requiring bash? The [[ operator and BASH_REMATCH array are bash-specific features that won't work in sh or other shells. Consider either:
- Adding a shebang line at the start of the script section
- Using POSIX-compliant alternatives
- Ensuring the execution environment always uses bash
This could cause the script to fail silently in non-bash environments.
| # Try to get PR info from various possible environment variables | ||
| if [ -n "$GITHUB_HEAD_REF" ]; then | ||
| echo "Checking out PR branch: $GITHUB_HEAD_REF" | ||
| git fetch origin "$GITHUB_HEAD_REF" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add error handling here? If the git fetch or checkout commands fail (network issues, permission problems, etc.), the script will continue and potentially run the translation check on the wrong branch. Consider:
| git fetch origin "$GITHUB_HEAD_REF" | |
| git fetch origin "$GITHUB_HEAD_REF" || { echo "Failed to fetch branch $GITHUB_HEAD_REF"; exit 1; } | |
| git checkout -B "$GITHUB_HEAD_REF" "origin/$GITHUB_HEAD_REF" || { echo "Failed to checkout branch $GITHUB_HEAD_REF"; exit 1; } |
| elif [ -n "$GITHUB_REF" ] && [[ "$GITHUB_REF" =~ ^refs/pull/([0-9]+)/ ]]; then | ||
| PR_NUMBER="${BASH_REMATCH[1]}" | ||
| echo "Fetching PR #$PR_NUMBER" | ||
| git fetch origin "pull/$PR_NUMBER/head:pr-$PR_NUMBER" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same error handling concern here - these git commands could fail silently. Adding error checks would make failures more visible.
| echo "Could not determine PR number from event data" | ||
| fi | ||
| else | ||
| echo "No PR information found in environment, using current branch" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this fallback message more informative? It would be helpful to know which branch is actually being used:
| echo "No PR information found in environment, using current branch" | |
| echo "No PR information found in environment, using current branch: $(git branch --show-current)" |
This PR fixes an issue where the roomotes automation was running translation checks on the main branch instead of the PR branch that triggered the pull_request.opened event.
Changes
.roo/roomotes.ymlto add commands that fetch and checkout the PR branch before running any other commandsGITHUB_HEAD_REFenvironment variableGITHUB_REFwith PR number patternWhy this is needed
Previously, when a PR was opened, the translation check script would run on the main branch code instead of the PR changes. This meant that:
Testing
The solution handles various CI/CD environments by checking multiple standard environment variables that are typically available in GitHub Actions and similar systems.
Important
Updates
.roo/roomotes.ymlto fetch and checkout the PR branch for accurate translation checks..roo/roomotes.ymlto fetch and checkout the PR branch before running translation checks.GITHUB_HEAD_REF,GITHUB_REF, or GitHub event JSON.This description was created by
for 21e8682. You can customize this summary. It will automatically update as commits are pushed.