Ollama template update #36
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: Ollama template update | |
on: | |
# push: # for debugging | |
workflow_dispatch: | |
schedule: | |
- cron: "0 7 * * 1" # every monday at 7am, so I'll review it after having a π₯ | |
permissions: | |
pull-requests: write # for creating PR | |
issues: write # for adding labels to the created PR | |
contents: write # for git push new branch | |
jobs: | |
update-ollama-templates: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
if: github.repository == 'huggingface/huggingface.js' | |
- name: Prepare | |
id: prepare | |
if: github.repository == 'huggingface/huggingface.js' | |
shell: bash | |
run: | | |
git config --global user.name machineuser | |
git config --global user.email [email protected] | |
git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
npm install -g pnpm | |
CURRENT_DATE=$(date -u +"%Y-%m-%d") | |
echo "CURRENT_DATE=$CURRENT_DATE" | |
echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_OUTPUT | |
- name: Install dependencies | |
if: github.repository == 'huggingface/huggingface.js' | |
shell: bash | |
run: | | |
cd packages/ollama-utils | |
pnpm install --frozen-lockfile | |
- name: Run update script | |
if: github.repository == 'huggingface/huggingface.js' | |
shell: bash | |
run: | | |
cd packages/ollama-utils | |
pnpm run build:automap | |
- name: Check for changed files | |
id: changes | |
if: github.repository == 'huggingface/huggingface.js' | |
shell: bash | |
env: | |
CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }} | |
run: | | |
set -x | |
FILE_TO_ADD="packages/ollama-utils/src/chat-template-automap.ts" | |
git status | |
modified_files="$(git status -s)" | |
echo "Modified files: ${modified_files}" | |
if [ -n "${modified_files}" ]; then | |
NEW_BRANCH="ollama-${CURRENT_DATE}" | |
echo "NEW_BRANCH=${NEW_BRANCH}" | |
echo "Changes detected, will create a new branch:" | |
echo "${modified_files}" | |
git add "${FILE_TO_ADD}" | |
git commit -m "ollama update ${CURRENT_DATE}" | |
git checkout -b "${NEW_BRANCH}" | |
git push -f origin "${NEW_BRANCH}" | |
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT | |
echo "NEW_BRANCH=${NEW_BRANCH}" >> $GITHUB_OUTPUT | |
else | |
echo "No files changed, skipping..." | |
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create PR | |
if: steps.changes.outputs.HAS_CHANGES == 'true' && github.repository == 'huggingface/huggingface.js' | |
uses: actions/github-script@v6 | |
env: | |
CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }} | |
NEW_BRANCH: ${{ steps.changes.outputs.NEW_BRANCH }} | |
with: | |
github-token: ${{ secrets.HUGGINGFACE_JS_AUTOMATIC_PR }} | |
script: | | |
const { repo, owner } = context.repo; | |
const currDate = process.env.CURRENT_DATE; | |
const newBranch = process.env.NEW_BRANCH; | |
const result = await github.rest.pulls.create({ | |
title: '[ollama-utils] π€ Auto-update chat templates (' + currDate + ')', | |
owner, | |
repo, | |
head: newBranch, | |
base: 'main', | |
body: [ | |
'This PR is auto-generated by', | |
'[generate-automap.ts](https://github.com/huggingface/huggingface.js/blob/main/packages/ollama-utils/scripts/generate-automap.ts).' | |
].join('\n') | |
}); | |
console.log({ result }); | |
// github.rest.issues.addLabels({ | |
// owner, | |
// repo, | |
// issue_number: result.data.number, | |
// labels: ['feature', 'automated pr'] | |
// }); |