Sync Hugging Face App #174
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Hugging Face App | |
on: | |
schedule: | |
- cron: '0 4 * * *' # 04:00 UTC | |
workflow_dispatch: | |
jobs: | |
sync-hf: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
env: | |
HF_USERNAME: 'DmitryRyumin' | |
HF_REPO: 'NewEraAI-Papers' | |
LOCAL_DIR: 'NewEraAI-Papers' | |
HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN }} | |
JSON_DATA_PATH_2023: 'json_data/2023/CVPR' | |
JSON_DATA_PATH_2024: 'json_data/2024/CVPR' | |
UPDATE_REPO_SH: 'update_repo.sh' | |
COMPARE_FILES_SH: 'compare_files.sh' | |
EMAIL: '[email protected]' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
continue-on-error: true # Continue with the workflow even if the checkout fails | |
with: | |
ref: ${{ github.event.before || 'main' }} | |
- name: Install Git LFS | |
run: | | |
if ! command -v git-lfs &> /dev/null; then | |
echo "Git LFS is not installed. Installing ..." | |
sudo apt-get install git-lfs | |
fi | |
git lfs install | |
- name: Install colordiff | |
run: | | |
if ! command -v colordiff &> /dev/null; then | |
echo "colordiff is not installed. Installing ..." | |
sudo apt-get install colordiff | |
fi | |
- name: Set REMOTE_URL | |
run: | | |
echo "REMOTE_URL=https://${{ env.HF_USERNAME }}:${{ env.HF_TOKEN }}@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_REPO }}" >> $GITHUB_ENV | |
- name: Clone Hugging Face Repository | |
run: | | |
GIT_LFS_SKIP_SMUDGE=1 git clone --quiet --branch=main --single-branch --depth=1 "$REMOTE_URL" "${{ env.LOCAL_DIR }}" | |
continue-on-error: true | |
- name: Create directories if they do not exist | |
run: | | |
mkdir -p "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2023 }}" | |
mkdir -p "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2024 }}" | |
- name: Display cloned directory contents for 2023 | |
run: | | |
ls -al "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2023 }}" | |
- name: Display cloned directory contents for 2024 | |
run: | | |
ls -al "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2024 }}" | |
- name: Make scripts executable | |
run: | | |
chmod +x ${{ github.workspace }}/scripts/${{ env.UPDATE_REPO_SH }} | |
chmod +x ${{ github.workspace }}/scripts/${{ env.COMPARE_FILES_SH }} | |
- name: Define scripts | |
run: | | |
echo 'source ${{ github.workspace }}/scripts/${{ env.UPDATE_REPO_SH }}' > ${{ env.UPDATE_REPO_SH }} | |
echo 'source ${{ github.workspace }}/scripts/${{ env.COMPARE_FILES_SH }}' > ${{ env.COMPARE_FILES_SH }} | |
chmod +x ${{ github.workspace }}/${{ env.UPDATE_REPO_SH }} | |
chmod +x ${{ github.workspace }}/${{ env.COMPARE_FILES_SH }} | |
- name: Compare and update files for 2023 | |
run: bash ${{ env.COMPARE_FILES_SH }} "${{ github.workspace }}/json_data/2023" "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2023 }}" | |
- name: Compare and update files for 2024 | |
run: bash ${{ env.COMPARE_FILES_SH }} "${{ github.workspace }}/json_data/2024" "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2024 }}" | |
- name: Update repository and commit for 2023 | |
run: bash ${{ env.UPDATE_REPO_SH }} "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2023 }}" "${{ env.EMAIL }}" "${{ env.HF_USERNAME }}" "${{ env.JSON_DATA_PATH_2023 }}" "${{ env.HF_USERNAME }}" "${{ env.HF_TOKEN }}" "${{ env.HF_REPO }}" | |
- name: Update repository and commit for 2024 | |
run: bash ${{ env.UPDATE_REPO_SH }} "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH_2024 }}" "${{ env.EMAIL }}" "${{ env.HF_USERNAME }}" "${{ env.JSON_DATA_PATH_2024 }}" "${{ env.HF_USERNAME }}" "${{ env.HF_TOKEN }}" "${{ env.HF_REPO }}" | |
finalize: | |
runs-on: ubuntu-latest | |
needs: sync-hf | |
steps: | |
- name: Output completion time | |
run: echo "Workflow completed at [$(date '+%Y-%m-%d %H:%M:%S')]" | |
- name: Set output status | |
run: | | |
if [ ${{ needs.sync-hf.result }} == 'success' ]; then | |
echo "status=success" >> $GITHUB_ENV | |
else | |
echo "status=failure" >> $GITHUB_ENV | |
fi |