chore: update bailian-docs-llm-wiki (2026-07-30) #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: auto-merge-to-main | |
| # The FC crawler pushes skill updates to feat/bailian-docs-update. | |
| # On each such push, create (or reuse) a PR to main and merge it. | |
| # The resulting push to main then triggers publish-skills.yml, | |
| # which pokes the remote FC to sync main -> OSS. | |
| on: | |
| push: | |
| branches: [feat/bailian-docs-update] | |
| paths: ['skills/**'] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: auto-merge-to-main | |
| cancel-in-progress: false | |
| jobs: | |
| merge: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Sync main back into branch (prevent merge conflicts) | |
| run: | | |
| # Snapshot-based sync, no merge and therefore no conflicts ever: | |
| # build the desired tree directly — | |
| # - skills/bailian-docs-llm-wiki : exactly the crawler branch (HEAD) | |
| # - everything else : exactly origin/main | |
| # then record it as a two-parent merge commit (HEAD + origin/main) | |
| # so the branch history stays joined with main and the PR is clean. | |
| # Pushing with GITHUB_TOKEN does NOT retrigger this workflow | |
| # (recursive triggers are suppressed by default), so no loop. | |
| BRANCH="${{ github.ref_name }}" | |
| OWNED="skills/bailian-docs-llm-wiki" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git fetch origin main | |
| # index := main's tree exactly (includes deletions) | |
| git read-tree origin/main | |
| # drop main's copy of the crawler-owned dir, graft ours instead | |
| git rm -r --cached -f --ignore-unmatch -q -- "$OWNED" | |
| if git rev-parse -q --verify "HEAD:$OWNED" >/dev/null; then | |
| git read-tree "--prefix=$OWNED/" "HEAD:$OWNED" | |
| fi | |
| TREE=$(git write-tree) | |
| if [ "$TREE" = "$(git rev-parse 'HEAD^{tree}')" ] \ | |
| && git merge-base --is-ancestor origin/main HEAD; then | |
| echo "Branch already matches main + crawler dir, nothing to sync." | |
| git read-tree HEAD | |
| exit 0 | |
| fi | |
| COMMIT=$(git commit-tree "$TREE" -p HEAD -p origin/main \ | |
| -m "chore: sync main into ${BRANCH} (crawler owns ${OWNED})") | |
| git reset --hard "$COMMIT" | |
| git push origin "HEAD:${BRANCH}" | |
| - name: Create or update PR to main | |
| id: pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GIT_TOKEN }} | |
| run: | | |
| BRANCH="${{ github.ref_name }}" | |
| # Use the latest commit subject as the PR title (fallback to default title) | |
| TITLE=$(git log -1 --pretty=%s "${{ github.sha }}") | |
| [ -n "$TITLE" ] || TITLE="chore: update bailian-docs-llm-wiki ($(TZ=Asia/Shanghai date +%Y-%m-%d))" | |
| EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR #$EXISTING_PR already exists, updating..." | |
| # gh pr edit uses GraphQL and needs read:org scope; the REST | |
| # endpoint only needs repo scope, which GIT_TOKEN has. | |
| gh api "repos/${{ github.repository }}/pulls/$EXISTING_PR" \ | |
| -X PATCH -f title="$TITLE" --silent | |
| PR_NUMBER="$EXISTING_PR" | |
| else | |
| echo "Creating new PR..." | |
| PR_URL=$(gh pr create \ | |
| --base main \ | |
| --head "$BRANCH" \ | |
| --title "$TITLE" \ | |
| --body "Automated PR created on push to \`${BRANCH}\`." \ | |
| --no-maintainer-edit) | |
| # gh pr create prints the PR URL; keep only the trailing number | |
| PR_NUMBER="${PR_URL##*/}" | |
| fi | |
| echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT" | |
| - name: Auto-merge PR | |
| env: | |
| # GIT_TOKEN is a classic PAT (repo scope, no expiration) so that | |
| # the merge commit fires publish-skills.yml on main. | |
| GH_TOKEN: ${{ secrets.GIT_TOKEN }} | |
| run: | | |
| PR_NUMBER="${{ steps.pr.outputs.number }}" | |
| echo "Merging PR #$PR_NUMBER..." | |
| gh pr merge "$PR_NUMBER" --merge --delete-branch=false | |
| echo "### PR #$PR_NUMBER merged" >> "$GITHUB_STEP_SUMMARY" | |
| echo "Branch \`${{ github.ref_name }}\` has been merged into \`main\`." >> "$GITHUB_STEP_SUMMARY" |