| name: Sync to Hugging Face Hub | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| sync-to-hub: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| - name: Configure Git user | |
| run: | | |
| git config --global user.email "alexandru.dumitrescu@gmail.com" | |
| git config --global user.name "alexdum" | |
| - name: Install Git LFS | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install git-lfs | |
| git lfs install | |
| - name: Track data folder with Git LFS | |
| run: | | |
| tracked=false | |
| if ! git lfs track --list | grep -Fq "data/**"; then | |
| git lfs track "data/**" | |
| tracked=true | |
| fi | |
| if ! git lfs track --list | grep -Fq "*.nc"; then | |
| git lfs track "*.nc" | |
| tracked=true | |
| fi | |
| if [ "$tracked" = true ]; then | |
| git add .gitattributes | |
| git commit -m "Configure Git LFS for data folder" | |
| fi | |
| - name: Rewrite history to move data files into LFS | |
| run: | | |
| git lfs migrate import --yes --include="data/**,*.txt,*.csv,*.nc" --include-ref=refs/heads/main | |
| - name: Re-add data files with LFS filters | |
| run: | | |
| git add --renormalize data || true | |
| - name: Add and commit any changes | |
| run: | | |
| git add . | |
| git diff-index --quiet HEAD || git commit -m "Sync data files for Hugging Face" | |
| - name: Verify LFS files | |
| run: git lfs ls-files | |
| - name: Push to Hugging Face | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| git push -f https://alexdum:$HF_TOKEN@huggingface.co/spaces/alexdum/dwd main | |