-
Notifications
You must be signed in to change notification settings - Fork 2
114 lines (94 loc) · 3.92 KB
/
hf-deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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