Skip to content

feat: set up complete Python testing infrastructure #3

feat: set up complete Python testing infrastructure

feat: set up complete Python testing infrastructure #3

Workflow file for this run

name: Hugging Face Deployment
env:
HF_AT: ${{ secrets.HF_AT }}
HF_USER_ID: ${{ secrets.HF_USER_ID }}
GDRIVE_CREDENTIAL: ${{ secrets.GDRIVE_CREDENTIAL }}
on:
pull_request:
types: [opened]
issue_comment:
types: [created]
jobs:
hf-deploy:
runs-on: ubuntu-latest
steps:
- uses: octokit/[email protected]
name: GitHub API Request
id: request
with:
route: ${{ github.event.issue.pull_request.url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR informations
id: pr_data
run: |
echo "::set-output name=number::${{ fromJson(steps.request.outputs.data).number }}"
echo "::set-output name=branch::${{ fromJson(steps.request.outputs.data).head.ref }}"
echo "::set-output name=repo_name::${{ github.event.repository.name }}"
echo "::set-output name=repo_owner::${{ github.event.repository.owner.login }}"
echo "::set-output name=comment_owner::${{ github.event.sender.login }}"
echo "::set-output name=comment::${{ github.event.comment.body }}"
- name: Extract comment
if: ${{ steps.pr_data.outputs.repo_owner == steps.pr_data.outputs.comment_owner }}
run: |
echo "Eligible!!"
- uses: khan/[email protected]
name: Listen to comment on PR (training)
id: check
if: ${{ steps.pr_data.outputs.repo_owner == steps.pr_data.outputs.comment_owner }}
with:
trigger: '#deploy-hf'
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- uses: actions/checkout@v3
name: Clone branch of PR
if: steps.check.outputs.triggered == 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ steps.pr_data.outputs.branch }}
- name: Install Python packages
if: steps.check.outputs.triggered == 'true'
run: |
pip install -r requirements.txt
- name: Get Current Version of Model
if: steps.check.outputs.triggered == 'true'
run: |
mkdir .dvc/tmp
echo '${{ env.GDRIVE_CREDENTIAL }}' > .dvc/tmp/gdrive-user-credentials.json
dvc pull outputs/model.tar.gz
- name: Create or get HF's model repo
id: hf_model
if: steps.check.outputs.triggered == 'true'
run: |
python clouds/huggingface.py \
repo create \
"${{ env.HF_AT }}" "${{ env.HF_USER_ID }}" "${{ steps.pr_data.outputs.repo_name }}" --repo-type "model" \
> outputs.json
echo "::set-output name=result::$(cat outputs.json)"
- name: Upload model to HF's model repo
id: hf_model_upload
run: |
python clouds/huggingface.py \
repo upload \
"${{ env.HF_AT }}" "${{ fromJSON(steps.hf_model.outputs.result).repo_id }}" \
> outputs.json
echo "::set-output name=result::$(cat outputs.json)"
- name: Create or get HF's space repo
id: hf_space
run: |
python clouds/huggingface.py \
repo create \
"${{ env.HF_AT }}" "${{ env.HF_USER_ID }}" "${{ steps.pr_data.outputs.repo_name }}" --repo-type "space" \
> outputs.json
echo "::set-output name=result::$(cat outputs.json)"
- name: Upload app to HF's space repo
run: |
export MODEL_REPO_ID="${{ fromJSON(steps.hf_model.outputs.result).repo_id }}"
envsubst '$MODEL_REPO_ID' < hf-space/app_template.py > hf-space/app.py
rm "hf-space/app_template.py"
python clouds/huggingface.py \
repo upload \
"${{ env.HF_AT }}" "${{ fromJSON(steps.hf_space.outputs.result).repo_id }}" --repo-type "space" \
> outputs.json
cat outputs.json