Upload sync-huggingface.yml
Browse files- sync-huggingface.yml +92 -0
sync-huggingface.yml
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Two-Way Sync: GitHub ↔ Hugging Face Hub
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
inputs:
|
| 9 |
+
sync_direction:
|
| 10 |
+
description: "Choose sync direction"
|
| 11 |
+
required: true
|
| 12 |
+
default: "github-to-huggingface"
|
| 13 |
+
type: choice
|
| 14 |
+
options:
|
| 15 |
+
- github-to-huggingface
|
| 16 |
+
- huggingface-to-github
|
| 17 |
+
|
| 18 |
+
permissions:
|
| 19 |
+
contents: write
|
| 20 |
+
|
| 21 |
+
concurrency:
|
| 22 |
+
group: repo-sync-${{ github.ref }}
|
| 23 |
+
cancel-in-progress: false
|
| 24 |
+
|
| 25 |
+
jobs:
|
| 26 |
+
sync-github-to-huggingface:
|
| 27 |
+
name: Sync GitHub to Hugging Face
|
| 28 |
+
if: github.event_name == 'push' || github.event.inputs.sync_direction == 'github-to-huggingface'
|
| 29 |
+
runs-on: ubuntu-latest
|
| 30 |
+
|
| 31 |
+
steps:
|
| 32 |
+
- name: Checkout GitHub repository
|
| 33 |
+
uses: actions/checkout@v4
|
| 34 |
+
with:
|
| 35 |
+
fetch-depth: 0
|
| 36 |
+
|
| 37 |
+
- name: Configure Git identity
|
| 38 |
+
run: |
|
| 39 |
+
git config --global user.name "github-actions[bot]"
|
| 40 |
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
| 41 |
+
|
| 42 |
+
- name: Add Hugging Face remote
|
| 43 |
+
env:
|
| 44 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 45 |
+
HF_USERNAME: ${{ secrets.HF_USERNAME }}
|
| 46 |
+
run: |
|
| 47 |
+
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
| 48 |
+
git remote remove huggingface 2>/dev/null || true
|
| 49 |
+
git remote add huggingface "https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}"
|
| 50 |
+
|
| 51 |
+
- name: Push to Hugging Face Hub
|
| 52 |
+
run: |
|
| 53 |
+
git push huggingface main:main --force-with-lease
|
| 54 |
+
|
| 55 |
+
sync-huggingface-to-github:
|
| 56 |
+
name: Sync Hugging Face to GitHub
|
| 57 |
+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.sync_direction == 'huggingface-to-github'
|
| 58 |
+
runs-on: ubuntu-latest
|
| 59 |
+
|
| 60 |
+
steps:
|
| 61 |
+
- name: Checkout GitHub repository
|
| 62 |
+
uses: actions/checkout@v4
|
| 63 |
+
with:
|
| 64 |
+
fetch-depth: 0
|
| 65 |
+
token: ${{ secrets.GH_PAT }}
|
| 66 |
+
|
| 67 |
+
- name: Configure Git identity
|
| 68 |
+
run: |
|
| 69 |
+
git config --global user.name "repo-sync-bot"
|
| 70 |
+
git config --global user.email "repo-sync-bot@users.noreply.github.com"
|
| 71 |
+
|
| 72 |
+
- name: Add Hugging Face remote
|
| 73 |
+
env:
|
| 74 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 75 |
+
HF_USERNAME: ${{ secrets.HF_USERNAME }}
|
| 76 |
+
run: |
|
| 77 |
+
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
| 78 |
+
git remote remove huggingface 2>/dev/null || true
|
| 79 |
+
git remote add huggingface "https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${REPO_NAME}"
|
| 80 |
+
|
| 81 |
+
- name: Fetch Hugging Face main
|
| 82 |
+
run: |
|
| 83 |
+
git fetch huggingface main
|
| 84 |
+
|
| 85 |
+
- name: Merge Hugging Face into GitHub
|
| 86 |
+
run: |
|
| 87 |
+
git checkout main
|
| 88 |
+
git merge huggingface/main --no-edit --allow-unrelated-histories
|
| 89 |
+
|
| 90 |
+
- name: Push merged state to GitHub
|
| 91 |
+
run: |
|
| 92 |
+
git push origin main
|