cevheri's picture
first commit
8a58abc
name: Push to HuggingFace Spaces
on:
push:
branches:
- release/*
- main
env:
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAG: ${{ github.sha }}
VERSION: latest
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_ORGANIZATION: ${{ vars.HF_ORGANIZATION }}
HF_SPACE: ${{ vars.HF_SPACE }}
jobs:
push-to-hf:
runs-on: ubuntu-latest
steps:
# checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
# - name: setup git lfs
# run: |
# git lfs install
# git lfs track "*.csv"
# git add .gitattributes
# git commit -m "Add .gitattributes"
# - name: Configure Git LFS for large files
# run: |
# find . -name "*.csv" -type f -size +10M | while read file; do
# git lfs track "$file"
# git add "$file"
# done
# print environment variables
- name: Print environment variables
run: |
echo "IMAGE_NAME: $IMAGE_NAME"
echo "IMAGE_TAG: $IMAGE_TAG"
echo "VERSION: $VERSION"
echo HF_TOKEN: $HF_TOKEN
echo HF_ORGANIZATION: $HF_ORGANIZATION
echo HF_SPACE: $HF_SPACE
# extract version from branch name and set it as an environment variable when release branch is pushed
- name: Extract version from branch name
if: startsWith(github.ref, 'refs/heads/release/')
id: extract_version
run: |
echo "IMAGE_TAG=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_ENV
# print version
- name: Print version
id: print_version
run: |
echo "VERSION: $VERSION"
# build the docker image and push ghcr.io
- name: Build and push the docker image
if: startsWith(github.ref, 'refs/heads/release/')
run: |
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker tag $IMAGE_NAME:$IMAGE_TAG ghcr.io/$IMAGE_NAME:latest
docker push ghcr.io/$IMAGE_NAME:$IMAGE_TAG
docker push ghcr.io/$IMAGE_NAME:latest
# push to HuggingFace Spaces when branch name is main
- name: Push to HF Space
if: startsWith(github.ref, 'refs/heads/main')
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git remote add hf "https://api:$HF_TOKEN@huggingface.co/spaces/$HF_ORGANIZATION/$HF_SPACE"
git fetch hf
git push hf main --force