-
Notifications
You must be signed in to change notification settings - Fork 0
ci: add reviewed upstream sync workflow #6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| name: Upstream Sync PR | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every 4 hours, offset from top-of-hour GitHub Actions congestion. | ||
| - cron: '17 */4 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: upstream-sync-pr | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| sync: | ||
| name: Create reviewed upstream sync PR | ||
| if: github.repository == 'pai-scaffolde/hermes-agent' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
|
|
||
| steps: | ||
| # Use the repository GitHub App credentials instead of GITHUB_TOKEN so | ||
| # branch pushes/PR updates trigger the normal pull_request CI gates. | ||
| - name: Generate GitHub App token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@7bfa3a4717ef143a604ee0a99d859b8886a96d00 # v1.9.3 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout fork main | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| ref: main | ||
| fetch-depth: 0 | ||
| token: ${{ steps.app-token.outputs.token }} | ||
|
|
||
| - name: Create or update upstream sync PR | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| BRANCH: automation/upstream-sync | ||
| UPSTREAM_URL: https://github.com/NousResearch/hermes-agent.git | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| git config user.name 'github-actions[bot]' | ||
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | ||
|
|
||
| git remote add upstream "$UPSTREAM_URL" | ||
| git fetch origin main | ||
| git fetch upstream main | ||
|
|
||
| if git merge-base --is-ancestor upstream/main origin/main; then | ||
| echo "Fork main already contains upstream/main; nothing to sync." | ||
| exit 0 | ||
| fi | ||
|
|
||
| git checkout -B "$BRANCH" origin/main | ||
| git merge --no-ff --no-edit upstream/main | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With Useful? React with 👍 / 👎. |
||
|
|
||
| git push --force-with-lease origin "HEAD:$BRANCH" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The workflow force-pushes with Useful? React with 👍 / 👎. |
||
|
|
||
| cat > /tmp/upstream-sync-pr-body.md <<'EOF' | ||
| Automated upstream sync from NousResearch/hermes-agent into pai-scaffolde/hermes-agent. | ||
|
|
||
| Policy: | ||
| - This PR is review-gated. | ||
| - Do not auto-merge blindly. | ||
| - Existing CI/checks must pass before merging. | ||
| - If conflicts occur, resolve manually on this branch. | ||
|
|
||
| Source: | ||
| - upstream: NousResearch/hermes-agent main | ||
| - fork base: pai-scaffolde/hermes-agent main | ||
| EOF | ||
|
|
||
| PR_NUMBER="$(gh pr list \ | ||
| --repo "$GITHUB_REPOSITORY" \ | ||
| --head "$BRANCH" \ | ||
| --base main \ | ||
|
Comment on lines
+82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| --state open \ | ||
| --json number \ | ||
| --jq '.[0].number // empty')" | ||
|
|
||
| if [ -n "$PR_NUMBER" ]; then | ||
| gh pr edit "$PR_NUMBER" \ | ||
| --repo "$GITHUB_REPOSITORY" \ | ||
| --title "chore: sync from NousResearch/hermes-agent upstream" \ | ||
| --body-file /tmp/upstream-sync-pr-body.md | ||
| else | ||
| gh pr create \ | ||
| --repo "$GITHUB_REPOSITORY" \ | ||
| --base main \ | ||
| --head "$BRANCH" \ | ||
| --title "chore: sync from NousResearch/hermes-agent upstream" \ | ||
| --body-file /tmp/upstream-sync-pr-body.md | ||
| fi | ||
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.
git checkout -B "$BRANCH" origin/mainresetsautomation/upstream-synctoorigin/mainon each execution, and the subsequentgit merge --no-ff --no-edit upstream/mainthen creates a fresh merge commit even if upstream has not moved since the last run. In the common case where an upstream-sync PR is still open, this causes branch rewrites every 4 hours (retriggering CI repeatedly) and can overwrite manual conflict-resolution commits pushed to that branch. The workflow should preserve/reuse the existing sync branch (or detect that it already containsupstream/main) instead of forcibly recreating it each run.Useful? React with 👍 / 👎.