Train Model #50
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: Train Model | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 2 * * 0' # Run at 2AM UTC every Sunday | |
| permissions: | |
| contents: write | |
| actions: write | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| name: Train Model | |
| steps: | |
| - name: Install Git LFS | |
| run: sudo apt-get update && sudo apt-get install -y git-lfs && git lfs install | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| lfs: true | |
| - uses: oven-sh/setup-bun@v2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24.x | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Train model from READMEs | |
| run: bun scripts/train_model.mjs | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| - name: Check for changes | |
| id: git-check | |
| run: | | |
| if git diff --quiet && git diff --cached --quiet; then | |
| echo "changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit generated files | |
| if: steps.git-check.outputs.changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git lfs track "loadedVectorStore/*.json" 2>/dev/null || true | |
| git lfs track "loadedVectorStore/*.index" 2>/dev/null || true | |
| git add .gitattributes 2>/dev/null || true | |
| git add loadedVectorStore/*.json loadedVectorStore/*.index 2>/dev/null || true | |
| git add -A | |
| git commit -m "chore: update trained model" \ | |
| -m "Automated update from train-model workflow" \ | |
| -m "Run ID: ${{ github.run_id }}" | |
| git pull --rebase origin main || { | |
| echo "Rebase conflict detected, aborting and retrying..." | |
| git rebase --abort | |
| git pull --no-rebase origin main | |
| exit 1 | |
| } | |
| git push origin main | |
| gh workflow run deploy.yml --ref main | |
| working-directory: ./ | |
| - name: Report no changes | |
| if: steps.git-check.outputs.changes != 'true' | |
| run: echo "No changes to commit - trained model is up to date" |