From dcdaa6b666c0f1a51e0aa0a6132ca3f765a743d3 Mon Sep 17 00:00:00 2001 From: liuweiqing Date: Sat, 19 Oct 2024 11:43:36 +0800 Subject: [PATCH] ci: hg_space --- .github/workflows/deploy-to-hf-spaces.yml | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/deploy-to-hf-spaces.yml diff --git a/.github/workflows/deploy-to-hf-spaces.yml b/.github/workflows/deploy-to-hf-spaces.yml new file mode 100644 index 00000000..1ef16fc9 --- /dev/null +++ b/.github/workflows/deploy-to-hf-spaces.yml @@ -0,0 +1,59 @@ +name: Deploy to HuggingFace Spaces + +on: + push: + branches: + - dev + - main + workflow_dispatch: + +jobs: + check-secret: + runs-on: ubuntu-latest + outputs: + token-set: ${{ steps.check-key.outputs.defined }} + steps: + - id: check-key + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + if: "${{ env.HF_TOKEN != '' }}" + run: echo "defined=true" >> $GITHUB_OUTPUT + + deploy: + runs-on: ubuntu-latest + needs: [check-secret] + if: needs.check-secret.outputs.token-set == 'true' + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Remove git history + run: rm -rf .git + + - name: Prepend YAML front matter to README.md + run: | + echo "---" > temp_readme.md + echo "title: Auto Read" >> temp_readme.md + echo "emoji: 🐳" >> temp_readme.md + echo "colorFrom: purple" >> temp_readme.md + echo "colorTo: gray" >> temp_readme.md + echo "sdk: docker" >> temp_readme.md + echo "app_port: 7860" >> temp_readme.md + echo "---" >> temp_readme.md + cat README.md >> temp_readme.md + mv temp_readme.md README.md + + - name: Configure git + run: | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + - name: Set up Git and push to Space + run: | + git init --initial-branch=main + git lfs track "*.ttf" + rm demo.gif + git add . + git commit -m "GitHub deploy: ${{ github.sha }}" + git push --force https://auto:${HF_TOKEN}@huggingface.co/spaces/auto/auto main \ No newline at end of file