abdullah090809 commited on
Commit
3b1479b
·
1 Parent(s): 08c1844

simplify CI/CD pipeline

Browse files
Files changed (1) hide show
  1. .github/workflows/ci-cd.yml +4 -93
.github/workflows/ci-cd.yml CHANGED
@@ -4,7 +4,6 @@ on:
4
  push:
5
  branches:
6
  - master
7
- workflow_dispatch: {}
8
 
9
  jobs:
10
  test:
@@ -55,105 +54,17 @@ jobs:
55
  run: python -m pytest --disable-warnings -v
56
 
57
  deploy:
58
- # Only run deploy for pushes or manual dispatches in the main repository
59
- if: github.repository == 'abdullah090809/Job_Tracker' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
60
  runs-on: ubuntu-latest
61
  needs: test
62
 
63
- env:
64
- SECRET_KEY: ${{ secrets.SECRET_KEY }} # if needed for scripts
65
- HF_TOKEN: ${{ secrets.HF_TOKEN }}
66
-
67
  steps:
68
  - name: Checkout code
69
  uses: actions/checkout@v3
70
  with:
71
  fetch-depth: 0
72
- lfs: true
73
-
74
- - name: Debug run context & check HF_TOKEN
75
- env:
76
- HF_TOKEN: ${{ secrets.HF_TOKEN }}
77
- run: |
78
- echo "Run info:"
79
- echo " event: $GITHUB_EVENT_NAME"
80
- echo " repo: $GITHUB_REPOSITORY"
81
- echo " ref: $GITHUB_REF"
82
- echo " actor: $GITHUB_ACTOR"
83
- echo " head_ref: $GITHUB_HEAD_REF" # non-empty for PRs from forks
84
- # Safe check for secret presence (DO NOT print the secret)
85
- if [ -z "$HF_TOKEN" ]; then
86
- echo "ERROR: HF_TOKEN is not available in this run (empty)."
87
- echo " -> If this was a PR from a fork, GitHub will not expose secrets to that run."
88
- exit 1
89
- else
90
- echo "HF_TOKEN is present."
91
- fi
92
-
93
- - name: Install huggingface_hub
94
- run: pip install huggingface_hub
95
 
96
- - name: Push to Hugging Face via huggingface_hub
97
- env:
98
- HF_TOKEN: ${{ secrets.HF_TOKEN }}
99
  run: |
100
- python - <<'PY'
101
- import os, sys, shutil
102
- from huggingface_hub import Repository
103
-
104
- token = os.getenv("HF_TOKEN")
105
- if not token:
106
- sys.exit("HF_TOKEN not set")
107
-
108
- repo_url = "https://huggingface.co/spaces/abdullah090809/Job_Tracker_API"
109
- local_dir = "hf_space_tmp"
110
-
111
- # Clean up previous clone if present
112
- if os.path.exists(local_dir):
113
- shutil.rmtree(local_dir)
114
-
115
- # Clone the Space repository
116
- repo = Repository(local_dir=local_dir, clone_from=repo_url, use_auth_token=token)
117
-
118
- # Copy workspace files into the cloned space (skip .git)
119
- def copy_dir(src, dst):
120
- for item in os.listdir(src):
121
- if item == ".git" or item == local_dir:
122
- continue
123
- s = os.path.join(src, item)
124
- d = os.path.join(dst, item)
125
- if os.path.isdir(s):
126
- if os.path.exists(d):
127
- shutil.rmtree(d)
128
- shutil.copytree(s, d)
129
- else:
130
- # ensure destination dir exists
131
- os.makedirs(os.path.dirname(d), exist_ok=True)
132
- shutil.copy2(s, d)
133
-
134
- copy_dir(".", local_dir)
135
-
136
- # Add, commit and push changes
137
- repo.git_add(pattern=".")
138
- try:
139
- repo.git_commit("CI: update Space")
140
- except Exception:
141
- # If commit fails because nothing to commit, skip
142
- print("No changes to commit or commit failed.")
143
- repo.git_push(force=True)
144
- PY
145
-
146
- # Optional fallback (token-in-URL). Keep commented unless you explicitly want it.
147
- # - name: Push to Hugging Face (fallback git token-in-URL)
148
- # env:
149
- # HF_TOKEN: ${{ secrets.HF_TOKEN }}
150
- # run: |
151
- # if [ -z "$HF_TOKEN" ]; then
152
- # echo "HF_TOKEN not set; aborting push."
153
- # exit 1
154
- # fi
155
- # git config --global user.email "ci@github.com"
156
- # git config --global user.name "GitHub Actions"
157
- # git remote add space "https://abdullah090809:${HF_TOKEN}@huggingface.co/spaces/abdullah090809/Job_Tracker_API.git" || \
158
- # git remote set-url space "https://abdullah090809:${HF_TOKEN}@huggingface.co/spaces/abdullah090809/Job_Tracker_API.git"
159
- # git push space master:main --force
 
4
  push:
5
  branches:
6
  - master
 
7
 
8
  jobs:
9
  test:
 
54
  run: python -m pytest --disable-warnings -v
55
 
56
  deploy:
 
 
57
  runs-on: ubuntu-latest
58
  needs: test
59
 
 
 
 
 
60
  steps:
61
  - name: Checkout code
62
  uses: actions/checkout@v3
63
  with:
64
  fetch-depth: 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ - name: Push to Hugging Face
 
 
67
  run: |
68
+ git config --global user.email "ci@github.com"
69
+ git config --global user.name "GitHub Actions"
70
+ git push https://abdullah090809:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/abdullah090809/Job_Tracker_API HEAD:main --force