| 
 | 1 | +name: Ollama template update  | 
 | 2 | +on:  | 
 | 3 | +  # push: # for debugging  | 
 | 4 | +  workflow_dispatch:  | 
 | 5 | +  schedule:  | 
 | 6 | +    - cron: "0 7 * * 1" # every monday at 7am, so I'll review it after having a 🥐  | 
 | 7 | + | 
 | 8 | +permissions:  | 
 | 9 | +  pull-requests: write # for creating PR  | 
 | 10 | +  issues: write # for adding labels to the created PR  | 
 | 11 | +  contents: write # for git push new branch  | 
 | 12 | + | 
 | 13 | +jobs:  | 
 | 14 | +  update-ollama-templates:  | 
 | 15 | +    runs-on: ubuntu-latest  | 
 | 16 | +    steps:  | 
 | 17 | +      - uses: actions/checkout@v3  | 
 | 18 | +        if: github.repository == 'huggingface/huggingface.js'  | 
 | 19 | + | 
 | 20 | +      - name: Prepare  | 
 | 21 | +        id: prepare  | 
 | 22 | +        if: github.repository == 'huggingface/huggingface.js'  | 
 | 23 | +        shell: bash  | 
 | 24 | +        run: |  | 
 | 25 | +          git config --global user.name machineuser  | 
 | 26 | +          git config --global user.email [email protected]  | 
 | 27 | +          git config --global --add safe.directory "$GITHUB_WORKSPACE"  | 
 | 28 | +          npm install -g pnpm  | 
 | 29 | +          CURRENT_DATE=$(date -u +"%Y-%m-%d")  | 
 | 30 | +          echo "CURRENT_DATE=$CURRENT_DATE"  | 
 | 31 | +          echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_OUTPUT  | 
 | 32 | +
  | 
 | 33 | +      - name: Install dependencies  | 
 | 34 | +        if: github.repository == 'huggingface/huggingface.js'  | 
 | 35 | +        shell: bash  | 
 | 36 | +        run: |  | 
 | 37 | +          cd packages/ollama-utils  | 
 | 38 | +          pnpm install --frozen-lockfile  | 
 | 39 | +
  | 
 | 40 | +      - name: Run update script  | 
 | 41 | +        if: github.repository == 'huggingface/huggingface.js'  | 
 | 42 | +        shell: bash  | 
 | 43 | +        run: |  | 
 | 44 | +          cd packages/ollama-utils  | 
 | 45 | +          pnpm run build:automap  | 
 | 46 | +
  | 
 | 47 | +      - name: Check for changed files  | 
 | 48 | +        id: changes  | 
 | 49 | +        if: github.repository == 'huggingface/huggingface.js'  | 
 | 50 | +        shell: bash  | 
 | 51 | +        env:  | 
 | 52 | +          CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }}  | 
 | 53 | +        run: |  | 
 | 54 | +          set -x  | 
 | 55 | +
  | 
 | 56 | +          FILE_TO_ADD="packages/ollama-utils/src/chat-template-automap.ts"  | 
 | 57 | +
  | 
 | 58 | +          git status  | 
 | 59 | +          modified_files="$(git status -s)"  | 
 | 60 | +          echo "Modified files: ${modified_files}"  | 
 | 61 | +          if [ -n "${modified_files}" ]; then  | 
 | 62 | +            NEW_BRANCH="ollama-${CURRENT_DATE}"  | 
 | 63 | +            echo "NEW_BRANCH=${NEW_BRANCH}"  | 
 | 64 | +            echo "Changes detected, will create a new branch:"  | 
 | 65 | +            echo "${modified_files}"  | 
 | 66 | +            git add "${FILE_TO_ADD}"  | 
 | 67 | +            git commit -m "ollama update ${CURRENT_DATE}"  | 
 | 68 | +            git checkout -b "${NEW_BRANCH}"  | 
 | 69 | +            git push -f origin "${NEW_BRANCH}"  | 
 | 70 | +            echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT  | 
 | 71 | +            echo "NEW_BRANCH=${NEW_BRANCH}" >> $GITHUB_OUTPUT  | 
 | 72 | +          else  | 
 | 73 | +            echo "No files changed, skipping..."  | 
 | 74 | +            echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT  | 
 | 75 | +          fi  | 
 | 76 | +
  | 
 | 77 | +      - name: Create PR  | 
 | 78 | +        if: steps.changes.outputs.HAS_CHANGES == 'true' && github.repository == 'huggingface/huggingface.js'  | 
 | 79 | +        uses: actions/github-script@v6  | 
 | 80 | +        env:  | 
 | 81 | +          CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }}  | 
 | 82 | +          NEW_BRANCH: ${{ steps.changes.outputs.NEW_BRANCH }}  | 
 | 83 | +        with:  | 
 | 84 | +          github-token: ${{ secrets.HUGGINGFACE_JS_AUTOMATIC_PR }}  | 
 | 85 | +          script: |  | 
 | 86 | +            const { repo, owner } = context.repo;  | 
 | 87 | +            const currDate = process.env.CURRENT_DATE;  | 
 | 88 | +            const newBranch = process.env.NEW_BRANCH;  | 
 | 89 | +
  | 
 | 90 | +            const result = await github.rest.pulls.create({  | 
 | 91 | +              title: '[ollama-utils] 🤖 Auto-update chat templates (' + currDate + ')',  | 
 | 92 | +              owner,  | 
 | 93 | +              repo,  | 
 | 94 | +              head: newBranch,  | 
 | 95 | +              base: 'main',  | 
 | 96 | +              body: [  | 
 | 97 | +                'This PR is auto-generated by',  | 
 | 98 | +                '[generate-automap.ts](https://github.com/huggingface/huggingface.js/blob/main/packages/ollama-utils/scripts/generate-automap.ts).'  | 
 | 99 | +              ].join('\n')  | 
 | 100 | +            });  | 
 | 101 | +
  | 
 | 102 | +            console.log({ result });  | 
 | 103 | +            // github.rest.issues.addLabels({  | 
 | 104 | +            //   owner,  | 
 | 105 | +            //   repo,  | 
 | 106 | +            //   issue_number: result.data.number,  | 
 | 107 | +            //   labels: ['feature', 'automated pr']  | 
 | 108 | +            // });  | 
0 commit comments