Skip to content

Agent / Memory / Sync GitHub Artifacts #2

Agent / Memory / Sync GitHub Artifacts

Agent / Memory / Sync GitHub Artifacts #2

name: Agent / Memory / Sync GitHub Artifacts
on:
workflow_dispatch:
inputs:
since:
description: "Optional ISO timestamp override for the sync window"
required: false
default: ""
lookback_days:
description: "Fallback lookback window in days when no prior sync state exists"
required: false
default: "30"
memory_ref:
description: "Memory branch to update"
required: false
default: agent/memory
schedule:
- cron: "17 */6 * * *"
permissions:
contents: write
discussions: read
issues: read
pull-requests: read
id-token: write # required for GitHub Actions OIDC broker exchange
concurrency:
group: agent-memory-${{ github.repository }}-sync
cancel-in-progress: false
jobs:
gate:
if: vars.AGENT_ENABLED != 'false'
runs-on: ${{ fromJson(vars.AGENT_RUNS_ON || '["ubuntu-latest"]') }}
outputs:
skip: ${{ steps.gate.outputs.skip }}
mode: ${{ steps.gate.outputs.mode }}
reason: ${{ steps.gate.outputs.reason }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
token: ${{ github.token }}
- name: Resolve scheduled activity gate
id: gate
uses: ./.github/actions/scheduled-activity-gate
with:
github_token: ${{ github.token }}
schedule_policy: ${{ vars.AGENT_SCHEDULE_POLICY || '' }}
workflow: agent-memory-sync.yml
sync:
needs: gate
if: vars.AGENT_ENABLED != 'false' && needs.gate.outputs.skip != 'true'
runs-on: ${{ fromJson(vars.AGENT_RUNS_ON || '["ubuntu-latest"]') }}
env:
MEMORY_REF: ${{ inputs.memory_ref || vars.AGENT_MEMORY_REF || 'agent/memory' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
token: ${{ github.token }}
- name: Resolve GitHub auth
id: auth
uses: ./.github/actions/resolve-github-auth
with:
app_id: ${{ secrets.AGENT_APP_ID }}
app_private_key: ${{ secrets.AGENT_APP_PRIVATE_KEY }}
pat: ${{ secrets.AGENT_PAT }}
fallback_token: ${{ github.token }}
- name: Setup agent runtime
id: runtime
uses: ./.github/actions/setup-agent-runtime
- name: Read memory sync state
id: state
env:
GH_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
run: node .agent/dist/cli/memory/read-sync-state.js
- name: Resolve sync window
id: window
env:
LOOKBACK_DAYS: ${{ inputs.lookback_days || '30' }}
PREVIOUS_LAST_SYNC: ${{ steps.state.outputs.last_sync_at }}
SINCE_OVERRIDE: ${{ inputs.since || '' }}
run: |
set -euo pipefail
started_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if [ -n "$SINCE_OVERRIDE" ]; then
since="$SINCE_OVERRIDE"
elif [ -n "$PREVIOUS_LAST_SYNC" ]; then
since="$PREVIOUS_LAST_SYNC"
else
since=""
fi
echo "started_at=$started_at" >> "$GITHUB_OUTPUT"
echo "since=$since" >> "$GITHUB_OUTPUT"
- name: Download memory branch
id: memory
uses: ./.github/actions/download-agent-memory
with:
github_token: ${{ steps.auth.outputs.token }}
ref: ${{ env.MEMORY_REF }}
path: ${{ runner.temp }}/agent-memory
continue_on_missing: "true"
bootstrap_if_missing: "true"
- name: Sync GitHub artifacts into memory
id: sync
env:
GH_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
MEMORY_DIR: ${{ runner.temp }}/agent-memory
MEMORY_SYNC_LOOKBACK_DAYS: ${{ inputs.lookback_days || '30' }}
MEMORY_SYNC_SINCE: ${{ steps.window.outputs.since }}
MEMORY_SYNC_STARTED_AT: ${{ steps.window.outputs.started_at }}
REPO_SLUG: ${{ github.repository }}
run: node .agent/dist/cli/memory/sync-github-artifacts.js
- name: Commit and push memory branch
if: steps.sync.outcome == 'success'
working-directory: ${{ runner.temp }}/agent-memory
env:
BRANCH: ${{ env.MEMORY_REF }}
COMMIT_CWD: ${{ runner.temp }}/agent-memory
COMMIT_MESSAGE: "chore(memory): sync github artifacts"
GITHUB_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ steps.auth.outputs.token }}
SET_UPSTREAM: "true"
run: node ${{ github.workspace }}/.agent/dist/cli/commit.js
- name: Write memory sync state
if: steps.sync.outcome == 'success'
env:
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
REPO_SLUG: ${{ github.repository }}
SYNC_COMMIT_CURSOR: ${{ steps.sync.outputs.commit_cursor }}
SYNC_DISCUSSION_CURSOR: ${{ steps.sync.outputs.discussion_cursor }}
SYNC_ISSUE_CURSOR: ${{ steps.sync.outputs.issue_cursor }}
SYNC_LAST_ACTIVITY_AT: ${{ steps.sync.outputs.last_activity_at }}
SYNC_LAST_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SYNC_LAST_SYNC_AT: ${{ steps.window.outputs.started_at }}
SYNC_PULL_CURSOR: ${{ steps.sync.outputs.pull_cursor }}
run: node .agent/dist/cli/memory/write-sync-state.js