Skip to content
Latchkey

Sync Hugging Face App workflow (DmitryRyumin/ICCV-2023-25-Papers)

The Sync Hugging Face App workflow from DmitryRyumin/ICCV-2023-25-Papers, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: DmitryRyumin/ICCV-2023-25-Papers.github/workflows/sync_papers_with_hf.ymlLicense MITView source

What it does

This is the Sync Hugging Face App workflow from the DmitryRyumin/ICCV-2023-25-Papers repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
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: 'json_data/2023/ICCV'
      UPDATE_REPO_SH: 'update_repo.sh'
      COMPARE_FILES_SH: 'compare_files.sh'
      EMAIL: 'dl_03.03.1991@mail.ru'

    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: Display cloned directory contents
        run: |
          ls -al "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}"

      - 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
        run: bash ${{ env.COMPARE_FILES_SH }} "${{ github.workspace }}/json_data" "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}"

      - name: Update repository and commit
        run: bash ${{ env.UPDATE_REPO_SH }} "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}" "${{ env.EMAIL }}" "${{ env.HF_USERNAME }}" "${{ env.JSON_DATA_PATH }}" "${{ 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

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Sync Hugging Face App
 
on:
  schedule:
    - cron: '0 4 * * *' # 04:00 UTC
  workflow_dispatch:
 
jobs:
  sync-hf:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    permissions:
      contents: write
 
    env:
      HF_USERNAME: 'DmitryRyumin'
      HF_REPO: 'NewEraAI-Papers'
      LOCAL_DIR: 'NewEraAI-Papers'
      HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN }}
      JSON_DATA_PATH: 'json_data/2023/ICCV'
      UPDATE_REPO_SH: 'update_repo.sh'
      COMPARE_FILES_SH: 'compare_files.sh'
      EMAIL: 'dl_03.03.1991@mail.ru'
 
    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: Display cloned directory contents
        run: |
          ls -al "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}"
 
      - 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
        run: bash ${{ env.COMPARE_FILES_SH }} "${{ github.workspace }}/json_data" "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}"
 
      - name: Update repository and commit
        run: bash ${{ env.UPDATE_REPO_SH }} "${{ github.workspace }}/${{ env.LOCAL_DIR }}/${{ env.JSON_DATA_PATH }}" "${{ env.EMAIL }}" "${{ env.HF_USERNAME }}" "${{ env.JSON_DATA_PATH }}" "${{ env.HF_USERNAME }}" "${{ env.HF_TOKEN }}" "${{ env.HF_REPO }}"
 
  finalize:
    timeout-minutes: 30
    runs-on: latchkey-small
    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
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow