From f6ecbceba9be0f041e9cd9c8ea66317a201d88f0 Mon Sep 17 00:00:00 2001 From: John Williams Date: Mon, 30 Mar 2026 18:35:16 -0700 Subject: [PATCH] fix: sync workflow creates PR instead of pushing directly to main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Branch protection rules require changes via pull request, but the workflow was doing a direct git push to main — failing every daily run since March 23. Now creates a timestamped branch and opens a PR. Made-with: Cursor --- .github/workflows/sync-upstream-docs.yml | 25 +++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync-upstream-docs.yml b/.github/workflows/sync-upstream-docs.yml index e401286..2ef0d84 100644 --- a/.github/workflows/sync-upstream-docs.yml +++ b/.github/workflows/sync-upstream-docs.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + pull-requests: write steps: - uses: actions/checkout@v4 @@ -19,10 +20,28 @@ jobs: C7=$(curl -s https://api.github.com/repos/upstash/context7/releases/latest | jq -r '.tag_name // "no-release"') echo "{ \"context-hub\": \"$CHUB\", \"context7\": \"$C7\", \"updated\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\" }" > docs/upstream-versions.json - - name: Commit if changed + - name: Create PR if changed + env: + GH_TOKEN: ${{ github.token }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add docs/upstream-versions.json - git diff --staged --quiet || git commit -m "chore: sync upstream versions [automated]" - git push + if git diff --staged --quiet; then + echo "No changes detected — upstream versions unchanged." + exit 0 + fi + BRANCH="chore/sync-upstream-$(date +%Y%m%d)" + git checkout -b "$BRANCH" + git commit -m "chore: sync upstream versions [automated]" + git push origin "$BRANCH" + EXISTING=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number') + if [ -z "$EXISTING" ]; then + gh pr create \ + --title "chore: sync upstream versions [automated]" \ + --body "Automated daily sync of upstream release versions. Auto-generated by the Sync Upstream Doc Sources workflow." \ + --head "$BRANCH" \ + --base main + else + echo "PR #$EXISTING already exists for this branch." + fi