Skip to content

Commit

Permalink
build: sync env
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 8, 2023
1 parent 2da30dd commit a472081
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ on:
push:
branches:
- sync
schedule:
- cron: '0 16 * * *'

jobs:
sync-to-hub:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -15,9 +18,7 @@ jobs:
with:
path: |
sync/endpoint.txt
key: endpoint-${{ github.run_id }}
restore-keys: |
endpoint-
key: endpoint
- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand All @@ -26,13 +27,22 @@ jobs:
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
ENDPOINTS: ${{ vars.ENDPOINTS }}
run: cd sync && cat endpoint.txt && pip install huggingface_hub && python sync.py && cat endpoint.txt
run: cd sync && pip install huggingface_hub && python sync.py && cat endpoint.txt
- name: Delete cache
run: |
gh extension install actions/gh-actions-cache
set +e
echo "Deleting cache..."
gh actions-cache delete endpoint -R ${{ github.repository }} --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save cache
if: always()
id: file-save
uses: actions/cache/save@v3
with:
path: |
sync/endpoint.txt
key: endpoint-${{ github.run_id }}
restore-keys: |
endpoint-
key: endpoint

1 change: 0 additions & 1 deletion sync/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/endpoint.txt
/.env
15 changes: 8 additions & 7 deletions sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
ENDPOINTS = os.environ.get('ENDPOINTS')
file = 'endpoint.txt'
endpoints = ENDPOINTS.split('\n')
endpoint = endpoints[0].strip()
endpointIndex = '0'
try:
with open(file,"r") as f:
content=f.read().strip()
endpoint = endpoints[1] if content == endpoints[0] else endpoints[0]
print('content:', content)
endpointIndex = '1' if content == '0' else '0'
f.close()
except IOError:
print("File not accessible")
with open(file, "w") as wf:
wf.write(endpoint)
wf.close()

print('new endpoint', endpoint)
hf_api.add_space_secret('hf4all/bingo2', 'ENDPOINT', endpoint.strip())
with open(file, "w") as wf:
wf.write(endpointIndex)
wf.close()

print('new endpoint', endpoints[int(endpointIndex)])
hf_api.add_space_secret('hf4all/bingo2', 'ENDPOINT', endpoints[int(endpointIndex)].strip())

0 comments on commit a472081

Please sign in to comment.