Jacob Molnia commited on
Commit
8d3475a
1 Parent(s): f883fe6

Add files via upload

Browse files
.github/workflows/sync-to-hf.yaml ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face Hub
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ env:
9
+ HF_USERNAME: jake-molnia
10
+ HF_SPACE_NAME: test_space
11
+
12
+ jobs:
13
+ sync-to-hub:
14
+ runs-on: ubuntu-latest
15
+ environment: deployment_to_huggingface
16
+
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v3
20
+ with:
21
+ fetch-depth: 0
22
+ lfs: true
23
+
24
+ - name: Setup Git configuration
25
+ run: |
26
+ git config --global user.name "GitHub Action"
27
+ git config --global user.email "action@github.com"
28
+
29
+ - name: Verify Git status
30
+ run: |
31
+ git status
32
+ git log -n 1
33
+
34
+ - name: Setup Hugging Face CLI
35
+ run: pip install huggingface_hub
36
+
37
+ - name: Login to Hugging Face
38
+ env:
39
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
40
+ run: huggingface-cli login --token $HF_TOKEN
41
+
42
+ - name: Sync to Hugging Face Hub
43
+ env:
44
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
45
+ run: |
46
+ echo "Syncing to Hugging Face Space: ${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }}"
47
+ if ! git push https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main --force; then
48
+ echo "Push failed. Attempting to resolve conflicts..."
49
+ git config --global pull.rebase false
50
+ git pull https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main --allow-unrelated-histories
51
+ git push https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main
52
+ fi
53
+
54
+ - name: Verify sync
55
+ run: |
56
+ echo "Verifying sync..."
57
+ git ls-remote --exit-code https://${{ env.HF_USERNAME }}:$HF_TOKEN@huggingface.co/spaces/${{ env.HF_USERNAME }}/${{ env.HF_SPACE_NAME }} main
58
+
59
+ - name: Cleanup
60
+ if: always()
61
+ run: |
62
+ echo "Cleaning up..."
63
+ huggingface-cli logout
64
+ git config --global --unset user.name
65
+ git config --global --unset user.email
66
+
67
+ - name: Notify Discord
68
+ if: always()
69
+ env:
70
+ DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
71
+ run: |
72
+ if [ "${{ job.status }}" == "success" ]; then
73
+ COLOR="3066993"
74
+ TITLE="🚀 Sync Successful!"
75
+ DESCRIPTION="The sync to Hugging Face Hub completed successfully."
76
+ EMOJI="✅"
77
+ else
78
+ COLOR="15158332"
79
+ TITLE="💥 Sync Failed"
80
+ DESCRIPTION="The sync to Hugging Face Hub encountered an error."
81
+ EMOJI="❌"
82
+ fi
83
+
84
+ # Prepare the JSON payload
85
+ PAYLOAD=$(cat <<EOF
86
+ {
87
+ "embeds": [{
88
+ "title": "$TITLE",
89
+ "description": "$DESCRIPTION",
90
+ "color": $COLOR,
91
+ "fields": [
92
+ {
93
+ "name": "Repository",
94
+ "value": "${{ github.repository }}",
95
+ "inline": true
96
+ },
97
+ {
98
+ "name": "Branch",
99
+ "value": "${{ github.ref_name }}",
100
+ "inline": true
101
+ },
102
+ {
103
+ "name": "Triggered by",
104
+ "value": "${{ github.event_name }}",
105
+ "inline": true
106
+ }
107
+ ],
108
+ "footer": {
109
+ "text": "$EMOJI Workflow run completed at $(date -u "+%Y-%m-%d %H:%M:%S UTC")"
110
+ }
111
+ }],
112
+ "username": "GitHub Actions",
113
+ "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
114
+ }
115
+ EOF
116
+ )
117
+
118
+ # Send the payload and capture the response
119
+ RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Content-Type: application/json" -d "$PAYLOAD" $DISCORD_WEBHOOK)
120
+
121
+ # Check if the request was successful
122
+ if [ $RESPONSE -ne 204 ]; then
123
+ echo "Failed to send Discord notification. HTTP response code: $RESPONSE"
124
+ echo "Payload:"
125
+ echo "$PAYLOAD"
126
+ exit 1
127
+ else
128
+ echo "Discord notification sent successfully!"
129
+ fi
.github/workflows/unit-test.yaml ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run Unit Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ run-tests:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: Checkout repository
16
+ uses: actions/checkout@v3
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v4
20
+ with:
21
+ python-version: '3.9'
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install -r requirements.txt
27
+
28
+ - name: Run tests
29
+ run: pytest tests/
30
+
31
+ - name: Notify Discord
32
+ if: always()
33
+ env:
34
+ DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
35
+ run: |
36
+ if [ "${{ job.status }}" == "success" ]; then
37
+ COLOR="3066993"
38
+ TITLE="✅ Unit Tests Passed"
39
+ DESCRIPTION="All unit tests have passed successfully."
40
+ EMOJI="🎉"
41
+ else
42
+ COLOR="15158332"
43
+ TITLE="❌ Unit Tests Failed"
44
+ DESCRIPTION="Some unit tests have failed. Please check the logs for more details."
45
+ EMOJI="🚨"
46
+ fi
47
+
48
+ PAYLOAD=$(cat <<EOF
49
+ {
50
+ "embeds": [{
51
+ "title": "$TITLE",
52
+ "description": "$DESCRIPTION",
53
+ "color": $COLOR,
54
+ "fields": [
55
+ {
56
+ "name": "Repository",
57
+ "value": "${{ github.repository }}",
58
+ "inline": true
59
+ },
60
+ {
61
+ "name": "Branch",
62
+ "value": "${{ github.ref_name }}",
63
+ "inline": true
64
+ },
65
+ {
66
+ "name": "Triggered by",
67
+ "value": "${{ github.event_name }}",
68
+ "inline": true
69
+ },
70
+ {
71
+ "name": "Run by",
72
+ "value": "${{ github.actor }}",
73
+ "inline": true
74
+ }
75
+ ],
76
+ "footer": {
77
+ "text": "$EMOJI Test run completed at $(date -u "+%Y-%m-%d %H:%M:%S UTC")"
78
+ }
79
+ }],
80
+ "username": "GitHub Actions",
81
+ "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
82
+ }
83
+ EOF
84
+ )
85
+
86
+ RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Content-Type: application/json" -d "$PAYLOAD" $DISCORD_WEBHOOK)
87
+
88
+ if [ $RESPONSE -ne 204 ]; then
89
+ echo "Failed to send Discord notification. HTTP response code: $RESPONSE"
90
+ exit 1
91
+ else
92
+ echo "Discord notification sent successfully!"
93
+ fi