name: Sync to Hugging Face Hub on: push: branches: [main] workflow_dispatch: env: HF_USERNAME: jake-molnia HF_SPACE_NAME: CS_553 jobs: sync-to-hub: runs-on: ubuntu-latest environment: deployment_to_huggingface steps: - name: Checkout repository uses: actions/checkout@v3 with: fetch-depth: 0 lfs: true - name: Setup Git configuration run: | git config --global user.name "GitHub Action" git config --global user.email "action@github.com" - name: Verify Git status run: | git status git log -n 1 - name: Setup Hugging Face CLI run: pip install huggingface_hub - name: Login to Hugging Face env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: huggingface-cli login --token $HF_TOKEN - name: Sync to Hugging Face Hub env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | echo "Syncing to Hugging Face Space: ${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }}" if ! git push https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main --force; then echo "Push failed. Attempting to resolve conflicts..." git config --global pull.rebase false git pull https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main --allow-unrelated-histories git push https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main fi - name: Verify sync run: | echo "Verifying sync..." git ls-remote --exit-code https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main - name: Cleanup if: always() run: | echo "Cleaning up..." huggingface-cli logout git config --global --unset user.name git config --global --unset user.email - name: Notify Discord if: always() env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} run: | if [ "${{ job.status }}" == "success" ]; then COLOR="3066993" TITLE="🚀 Sync Successful!" DESCRIPTION="The sync to Hugging Face Hub completed successfully." EMOJI="✅" else COLOR="15158332" TITLE="💥 Sync Failed" DESCRIPTION="The sync to Hugging Face Hub encountered an error." EMOJI="❌" fi # Prepare the JSON payload PAYLOAD=$(cat <