Spaces:
Sleeping
Sleeping
Commit ·
3b1479b
1
Parent(s): 08c1844
simplify CI/CD pipeline
Browse files3 unmodified lines4567891044 unmodified lines5556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581593 unmodified linespush:branches:- masterworkflow_dispatch: {}jobs:test:44 unmodified linesrun: python -m pytest --disable-warnings -vdeploy:# Only run deploy for pushes or manual dispatches in the main repositoryif: github.repository == 'abdullah090809/Job_Tracker' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')runs-on: ubuntu-latestneeds: testenv:SECRET_KEY: ${{ secrets.SECRET_KEY }} # if needed for scriptsHF_TOKEN: ${{ secrets.HF_TOKEN }}steps:- name: Checkout codeuses: actions/checkout@v3with:fetch-depth: 0lfs: true- name: Debug run context & check HF_TOKENenv:HF_TOKEN: ${{ secrets.HF_TOKEN }}run: |echo "Run info:"echo " event: $GITHUB_EVENT_NAME"echo " repo: $GITHUB_REPOSITORY"echo " ref: $GITHUB_REF"echo " actor: $GITHUB_ACTOR"echo " head_ref: $GITHUB_HEAD_REF" # non-empty for PRs from forks# Safe check for secret presence (DO NOT print the secret)if [ -z "$HF_TOKEN" ]; thenecho "ERROR: HF_TOKEN is not available in this run (empty)."echo " -> If this was a PR from a fork, GitHub will not expose secrets to that run."exit 1elseecho "HF_TOKEN is present."fi- name: Install huggingface_hubrun: pip install huggingface_hub- name: Push to Hugging Face via huggingface_hubenv:HF_TOKEN: ${{ secrets.HF_TOKEN }}run: |python - <<'PY'import os, sys, shutilfrom huggingface_hub import Repositorytoken = os.getenv("HF_TOKEN")if not token:sys.exit("HF_TOKEN not set")repo_url = "https://huggingface.co/spaces/abdullah090809/Job_Tracker_API"local_dir = "hf_space_tmp"# Clean up previous clone if presentif os.path.exists(local_dir):shutil.rmtree(local_dir)# Clone the Space repositoryrepo = Repository(local_dir=local_dir, clone_from=repo_url, use_auth_token=token)# Copy workspace files into the cloned space (skip .git)def copy_dir(src, dst):for item in os.listdir(src):if item == ".git" or item == local_dir:continues = os.path.join(src, item)d = os.path.join(dst, item)if os.path.isdir(s):if os.path.exists(d):shutil.rmtree(d)shutil.copytree(s, d)else:# ensure destination dir existsos.makedirs(os.path.dirname(d), exist_ok=True)shutil.copy2(s, d)copy_dir(".", local_dir)# Add, commit and push changesrepo.git_add(pattern=".")try:repo.git_commit("CI: update Space")except Exception:# If commit fails because nothing to commit, skipprint("No changes to commit or commit failed.")repo.git_push(force=True)PY# Optional fallback (token-in-URL). Keep commented unless you explicitly want it.# - name: Push to Hugging Face (fallback git token-in-URL)# env:# HF_TOKEN: ${{ secrets.HF_TOKEN }}# run: |# if [ -z "$HF_TOKEN" ]; then# echo "HF_TOKEN not set; aborting push."# exit 1# fi# git config --global user.email "ci@github.com"# git config --global user.name "GitHub Actions"# git remote add space "https://abdullah090809:${HF_TOKEN}@huggingface.co/spaces/abdullah090809/Job_Tracker_API.git" || \# git remote set-url space "https://abdullah090809:${HF_TOKEN}@huggingface.co/spaces/abdullah090809/Job_Tracker_API.git"# git push space master:main --force3 unmodified lines45678944 unmodified lines54555657585960616263646566676869703 unmodified linespush:branches:- masterjobs:test:44 unmodified linesrun: python -m pytest --disable-warnings -vdeploy:runs-on: ubuntu-latestneeds: teststeps:- name: Checkout codeuses: actions/checkout@v3with:fetch-depth: 0- name: Push to Hugging Facerun: |git config --global user.email "ci@github.com"git config --global user.name "GitHub Actions"git push https://abdullah090809:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/abdullah090809/Job_Tracker_API HEAD:main --force
.github/workflows/ci-cd.yml+4-93