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