Skip to content

Instantly share code, notes, and snippets.

@m3hrdadfi
Last active August 16, 2023 14:56
Show Gist options
  • Save m3hrdadfi/d4d33b273579e5451d4f6c62585c0255 to your computer and use it in GitHub Desktop.
Save m3hrdadfi/d4d33b273579e5451d4f6c62585c0255 to your computer and use it in GitHub Desktop.
Sync To Hugging Face Space
name: Sync to Hugging Face space
on:
push:
branches: [main]
# to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
sync-to-space:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Push to space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: YOUR_HF_USERNAME # m3hrdadfi
HF_SPACE: YOUR_HF_SPACE_REPO # huggingface.co/spaces/flax-community/chef-transformer
TARGET_BRANCH: main
GIT_USER_EMAIL: GIT_USER_EMAIL
GIT_USER_NAME: GIT_USER_NAME
run: |
echo "Cloning destination git repository"
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
CLONE_DIR=$(mktemp -d)
git clone "https://$HF_USERNAME:$HF_TOKEN@$HF_SPACE" "$CLONE_DIR"
ls -la "$CLONE_DIR"
echo "Copy contents to clone git repository"
cp -rf * "$CLONE_DIR"
COMMIT_MESSAGE=$(git log --oneline --format=%B -n 1 HEAD | head -n 1)
COMM=${COMM:=Sync with Github}
echo "commit message:"
echo "$COMMIT_MESSAGE"
cd "$CLONE_DIR"
echo "Files that will be pushed:"
ls -la
echo "git add:"
git add -A
echo "git status:"
git status
echo "git diff-index:"
git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"
echo "git push origin:"
git push "https://$HF_USERNAME:$HF_TOKEN@$HF_SPACE" "$TARGET_BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment