Update sync-to-hf-space.yml
Browse files
.github/workflows/sync-to-hf-space.yml
CHANGED
|
@@ -18,7 +18,7 @@ jobs:
|
|
| 18 |
group: hf-space-sync-matrix-ai
|
| 19 |
cancel-in-progress: false
|
| 20 |
|
| 21 |
-
# Hard-wire your Space here
|
| 22 |
env:
|
| 23 |
HF_USERNAME: ruslanmv
|
| 24 |
SPACE_NAME: matrix-ai
|
|
@@ -40,24 +40,30 @@ jobs:
|
|
| 40 |
if: ${{ inputs.force != true }}
|
| 41 |
env:
|
| 42 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 43 |
-
HF_USERNAME: ${{ env.HF_USERNAME }}
|
| 44 |
-
SPACE_NAME: ${{ env.SPACE_NAME }}
|
| 45 |
run: |
|
|
|
|
| 46 |
if [ -z "$HF_TOKEN" ]; then
|
| 47 |
echo "β Missing HF_TOKEN secret. Add it under: Settings β Secrets and variables β Actions β New repository secret."
|
| 48 |
exit 1
|
| 49 |
fi
|
|
|
|
|
|
|
| 50 |
REMOTE_URL="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}"
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
- name: Push to Hugging Face Space (force)
|
| 55 |
if: ${{ inputs.force == true }}
|
| 56 |
env:
|
| 57 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 58 |
-
HF_USERNAME: ${{ env.HF_USERNAME }}
|
| 59 |
-
SPACE_NAME: ${{ env.SPACE_NAME }}
|
| 60 |
run: |
|
|
|
|
| 61 |
if [ -z "$HF_TOKEN" ]; then
|
| 62 |
echo "β Missing HF_TOKEN secret. Add it under: Settings β Secrets and variables β Actions β New repository secret."
|
| 63 |
exit 1
|
|
|
|
| 18 |
group: hf-space-sync-matrix-ai
|
| 19 |
cancel-in-progress: false
|
| 20 |
|
| 21 |
+
# Hard-wire your Space coordinates here
|
| 22 |
env:
|
| 23 |
HF_USERNAME: ruslanmv
|
| 24 |
SPACE_NAME: matrix-ai
|
|
|
|
| 40 |
if: ${{ inputs.force != true }}
|
| 41 |
env:
|
| 42 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
|
|
|
|
|
| 43 |
run: |
|
| 44 |
+
set -e
|
| 45 |
if [ -z "$HF_TOKEN" ]; then
|
| 46 |
echo "β Missing HF_TOKEN secret. Add it under: Settings β Secrets and variables β Actions β New repository secret."
|
| 47 |
exit 1
|
| 48 |
fi
|
| 49 |
+
|
| 50 |
+
# Build the authenticated remote URL *inside* the step so the secret expands.
|
| 51 |
REMOTE_URL="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}"
|
| 52 |
+
|
| 53 |
+
# Try a normal fast-forward push: HEAD -> main (creates main if missing).
|
| 54 |
+
if ! git push "$REMOTE_URL" HEAD:main; then
|
| 55 |
+
echo "::error::Non-fast-forward (remote has commits you don't)."
|
| 56 |
+
echo " If GitHub is the source of truth, rerun this workflow with 'force: true'."
|
| 57 |
+
echo " Or fetch Space changes locally, merge into your GitHub branch, then push again."
|
| 58 |
+
exit 1
|
| 59 |
+
fi
|
| 60 |
|
| 61 |
- name: Push to Hugging Face Space (force)
|
| 62 |
if: ${{ inputs.force == true }}
|
| 63 |
env:
|
| 64 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
|
|
|
|
|
| 65 |
run: |
|
| 66 |
+
set -e
|
| 67 |
if [ -z "$HF_TOKEN" ]; then
|
| 68 |
echo "β Missing HF_TOKEN secret. Add it under: Settings β Secrets and variables β Actions β New repository secret."
|
| 69 |
exit 1
|