From 3686ead800f5e2c9b529a88c7aa7dd0ea8e8a2a3 Mon Sep 17 00:00:00 2001 From: weaigc <879821485@qq.com> Date: Fri, 8 Sep 2023 20:45:02 +0800 Subject: [PATCH] build: sync env --- .github/workflows/sync.yml | 10 +++------- sync/.gitignore | 1 - sync/sync.py | 15 ++++++++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 5c03db36..b8169d9a 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -15,9 +15,7 @@ jobs: with: path: | sync/endpoint.txt - key: endpoint-${{ github.run_id }} - restore-keys: | - endpoint- + key: endpoint-${{ hashFiles('sync/endpoint.txt') }} - uses: actions/setup-python@v4 with: python-version: '3.10' @@ -26,13 +24,11 @@ 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: Save cache id: file-save uses: actions/cache/save@v3 with: path: | sync/endpoint.txt - key: endpoint-${{ github.run_id }} - restore-keys: | - endpoint- + key: endpoint-${{ hashFiles('sync/endpoint.txt') }} diff --git a/sync/.gitignore b/sync/.gitignore index 406bab72..f10862a6 100644 --- a/sync/.gitignore +++ b/sync/.gitignore @@ -1,2 +1 @@ -/endpoint.txt /.env diff --git a/sync/sync.py b/sync/sync.py index c11ad81b..88a712d6 100644 --- a/sync/sync.py +++ b/sync/sync.py @@ -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())