Spaces:
Runtime error
Runtime error
New: Add dev mode and related config/workflow
Browse filesFiles changed (5)
1 unmodified line2345567878910118 unmodified lines2021222324252627282930313233343536373839404142434445464748495051525354551 unmodified line
from model import Config
UserName = Literal["default"]ProductionSpace = Literal["production"]
PRODUCTION_SPACE_CONFIG: Dict[UserName, Config] = { "default": {PRODUCTION_SPACE_CONFIG: Dict[ProductionSpace, Config] = { "production": { "space_name": "example", "space_owner": "jy-raychen", "space_readme": {8 unmodified lines }, }}
UserName = Literal["default", "jhihruei"]
DEV_SPACE_CONFIG: Dict[UserName, Config] = { "default": { "space_name": "dev-space", "space_owner": "jy-raychen", "space_readme": { "title": "Hugging Face Developing", "emoji": "🏢", "color_from": "blue", "color_to": "indigo", "sdk": "gradio", "sdk_version": "4.36.0", "app_file": "app.py", "pinned": False, }, }, "jhihruei": { "space_name": "personal-dev", "space_owner": "jy-raychen", "space_readme": { "title": "Personal Developing", "emoji": "🏢", "color_from": "yellow", "color_to": "indigo", "sdk": "gradio", "sdk_version": "4.21.0", "app_file": "app.py", "pinned": False, }, },}1 unmodified line2345567823 unmodified lines32333435363738394041373842434445464748495051525354551 unmodified lineimport subprocessimport sys
from config import PRODUCTION_SPACE_CONFIGfrom config import DEV_SPACE_CONFIG, PRODUCTION_SPACE_CONFIGfrom model import Space
23 unmodified lines parser.add_argument("--branch_name", required=True) parser.add_argument("--username", required=True) parser.add_argument("--user_token", required=True) parser.add_argument("--mode", required=True, choices=["prod", "dev"]) parser.add_argument( "--deployer", help="The actor in Github Actions, it used to choose space config in dev mode.", ) args = parser.parse_args()
# TODO: Use different space config when deploy to dev environment. space = Space(PRODUCTION_SPACE_CONFIG["default"]) try: if args.mode == "prod": space = Space(PRODUCTION_SPACE_CONFIG["production"]) elif args.mode == "dev": space_config = DEV_SPACE_CONFIG.get( args.deployer, DEV_SPACE_CONFIG["default"] ) space = Space(space_config) except Exception: print("Error: The space is not set correctly!") sys.exit(1)
push_result = force_push_to_remote( space, args.username, args.user_token, args.branch_name1233456715 unmodified lines23242526272829303132333435363725383940414243444546474849import argparseimport sys
from config import PRODUCTION_SPACE_CONFIGfrom config import DEV_SPACE_CONFIG, PRODUCTION_SPACE_CONFIGfrom model import ReadMe, Space
DEFAULT_USER = "jy-raychen"15 unmodified lines
if __name__ == "__main__": parser = argparse.ArgumentParser( description="Generate Hugging Face space config file (i.e. README.md)." ) parser.add_argument("--mode", required=True, choices=["prod", "dev"]) parser.add_argument( "--deployer", help="The actor in Github Actions, it used to choose space config in dev mode.", ) args = parser.parse_args()
try: if args.mode == "prod": space = Space(PRODUCTION_SPACE_CONFIG["default"]) space = Space(PRODUCTION_SPACE_CONFIG["production"]) elif args.mode == "dev": space_config = DEV_SPACE_CONFIG.get( args.deployer, DEV_SPACE_CONFIG["default"] ) space = Space(space_config) except Exception: print("Error: The space is not set correctly!") sys.exit(1)
readme = readme_template(space.readme) print(readme)1234567891011121314151617181920212223242526272829303132333435363738394041name: Deploy Dev run-name: Deploy to dev space
on: push: branches: - '**' - '!main'
concurrency: # NOTE: The same actor will deploy to the same space, so we should cancel other earlier jobs. group: ${{ github.workflow }}-${{ github.actor }} cancel-in-progress: true
jobs: run_deploy_tool: runs-on: ubuntu-latest permissions: contents: read steps: - name: Check out repository code uses: actions/checkout@v4 with: fetch-depth: '0' - name: Update Repo README.md run: | python3 .github/tools/generate_readme.py --mode="dev" --deployer="${{ github.actor }}" > README.md git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions[bot]" git add ./README.md if [[ `git status --porcelain` ]]; then git commit -m "[skip ci] update README.md" fi - name: Run deploy tool run: | python3 .github/tools/deploy_to_space.py \ --mode="dev" \ --deployer="${{ github.actor }}" \ --branch_name="${{ github.ref_name }}" \ --username="${{ vars.HF_USERNAME }}" \ --user_token="${{ secrets.HF_TOKEN }}"21 unmodified lines22232425252627281 unmodified line3031323333343536373821 unmodified lines fetch-depth: '0' - name: Update Repo README.md run: | python3 .github/tools/generate_readme.py > README.md python3 .github/tools/generate_readme.py --mode="prod" > README.md git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions[bot]" git add ./README.md1 unmodified line git commit -m "[skip ci] update README.md" fi - name: Run deploy tool run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --username="${{ vars.HF_USERNAME }}" --user_token="${{ secrets.HF_TOKEN }}" run: | python3 .github/tools/deploy_to_space.py \ --mode="prod" \ --branch_name="${{ github.ref_name }}" \ --username="${{ vars.HF_USERNAME }}" \ --user_token="${{ secrets.HF_TOKEN }}".github/tools/config.py+36-3
.github/tools/deploy_to_space.py+17-3
.github/tools/generate_readme.py+23-2
.github/workflows/deploy-to-dev.yamlAdded+41
.github/workflows/deploy-to-production.yaml+7-2