fix(ci): scope lockfile PR lookup to repo owner

This commit is contained in:
dotta 2026-04-07 10:01:43 -05:00
parent 26ebe3b002
commit b6fe9ebcbc

View file

@ -54,10 +54,11 @@ jobs:
id: upsert-pr id: upsert-pr
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
REPO_OWNER: ${{ github.repository_owner }}
run: | run: |
if git diff --quiet -- pnpm-lock.yaml; then if git diff --quiet -- pnpm-lock.yaml; then
echo "Lockfile unchanged, nothing to do." echo "Lockfile unchanged, nothing to do."
echo "pr_created=false" >> "$GITHUB_OUTPUT" echo "pr_url=" >> "$GITHUB_OUTPUT"
exit 0 exit 0
fi fi
@ -70,28 +71,26 @@ jobs:
git commit -m "chore(lockfile): refresh pnpm-lock.yaml" git commit -m "chore(lockfile): refresh pnpm-lock.yaml"
git push --force origin "$BRANCH" git push --force origin "$BRANCH"
# Create PR if one doesn't already exist # Only reuse an open PR from this repository owner, not a fork with the same branch name.
existing=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number') pr_url="$(
if [ -z "$existing" ]; then gh pr list --state open --head "$BRANCH" --json url,headRepositoryOwner \
gh pr create \ --jq ".[] | select(.headRepositoryOwner.login == \"$REPO_OWNER\") | .url" |
head -n 1
)"
if [ -z "$pr_url" ]; then
pr_url="$(gh pr create \
--head "$BRANCH" \ --head "$BRANCH" \
--title "chore(lockfile): refresh pnpm-lock.yaml" \ --title "chore(lockfile): refresh pnpm-lock.yaml" \
--body "Auto-generated lockfile refresh after dependencies changed on master. This PR only updates pnpm-lock.yaml." --body "Auto-generated lockfile refresh after dependencies changed on master. This PR only updates pnpm-lock.yaml.")"
echo "Created new PR." echo "Created new PR: $pr_url"
else else
echo "PR #$existing already exists, branch updated via force push." echo "PR already exists: $pr_url"
fi fi
echo "pr_created=true" >> "$GITHUB_OUTPUT" echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT"
- name: Enable auto-merge for lockfile PR - name: Enable auto-merge for lockfile PR
if: steps.upsert-pr.outputs.pr_created == 'true' if: steps.upsert-pr.outputs.pr_url != ''
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
run: | run: |
pr_url="$(gh pr list --head chore/refresh-lockfile --json url --jq '.[0].url')" gh pr merge --auto --squash --delete-branch "${{ steps.upsert-pr.outputs.pr_url }}"
if [ -z "$pr_url" ]; then
echo "Error: lockfile PR was not found." >&2
exit 1
fi
gh pr merge --auto --squash --delete-branch "$pr_url"