talk2map-test / .github /workflows /sync-to-hf.yml
Noel-Teens's picture
testing new workflow
bfa95ad
Raw History Blame Contribute Delete
6.62 kB
name: Deploy to Production
on:
workflow_run:
workflows: ["Manual Staging to Main Promotion"]
types:
- completed
branches:
- main
push:
branches:
- main
permissions:
contents: read
issues: write
jobs:
deploy-to-production:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' }}
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
lfs: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run final tests on main
id: test-main
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: |
echo "Running final tests on main branch before production deployment..."
pytest -v
echo "βœ… Main branch tests passed!"
- name: Configure git user
if: steps.test-main.outcome == 'success'
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Deploy to Hugging Face Production Space
if: steps.test-main.outcome == 'success'
id: deploy-hf
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: neurostack-in
SPACE_NAME: talk2map-prod
run: |
echo "πŸš€ Deploying main branch to Hugging Face production space..."
git push --force \
https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME \
HEAD:main
echo "βœ… Successfully deployed to production!"
echo "🌐 Production URL: https://neurostack-in-talk2map-prod.hf.space"
- name: Create deployment success notification
if: steps.test-main.outcome == 'success' && steps.deploy-hf.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const title = `πŸš€ Production Deployment Successful`;
const body = `## Production Deployment Complete
**Branch:** \`main\`
**Commit:** ${context.sha}
**Deployed to:** HuggingFace Production Space
### Status:
- βœ… Final tests passed on main branch
- βœ… Successfully deployed to production
- 🌐 **Live URL:** https://neurostack-in-talk2map-prod.hf.space
### Deployment Details:
- **Environment:** Production
- **Platform:** HuggingFace Spaces
- **Space Name:** neurostack-in/talk2map-prod
- **Deployment Time:** ${new Date().toISOString()}
### Next Steps:
The production API is now live. You can:
1. Test the production endpoints
2. Monitor for any issues
3. Run API tests against production if needed
API testing can be triggered manually using the [API Testing workflow](${context.payload.repository.html_url}/actions/workflows/api-testing.yml).`;
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['deployment-success', 'production']
});
- name: Create test failure alert
if: steps.test-main.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const title = `❌ Production Deployment Blocked - Tests Failed`;
const body = `## Main Branch Tests Failed
**Branch:** \`main\`
**Commit:** ${context.sha}
**Workflow:** ${context.workflow}
**Run ID:** ${context.runId}
### Issue:
Tests failed on the main branch, blocking production deployment.
### Action Required:
1. Review the [failed workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
2. Fix the failing tests
3. Use a hotfix branch or roll back the problematic changes
### Emergency Options:
- **Hotfix:** Create a hotfix branch, fix the issue, and merge to main
- **Rollback:** Revert the problematic commit and redeploy
- **Manual Deploy:** Use manual deployment after fixing issues locally
**⚠️ Production deployment is currently blocked!**`;
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['test-failure', 'deployment-blocked', 'production', 'urgent']
});
- name: Create deployment failure alert
if: steps.test-main.outcome == 'success' && steps.deploy-hf.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const title = `❌ Production Deployment Failed`;
const body = `## HuggingFace Deployment Failed
**Branch:** \`main\`
**Commit:** ${context.sha}
**Workflow:** ${context.workflow}
**Run ID:** ${context.runId}
### Issue:
Tests passed but deployment to HuggingFace production space failed.
### Possible Causes:
- HuggingFace API token issues
- Network connectivity problems
- HuggingFace service issues
- Space configuration problems
### Action Required:
1. Check [workflow logs](${context.payload.repository.html_url}/actions/runs/${context.runId})
2. Verify HF_TOKEN secret is valid
3. Check HuggingFace space status
4. Retry deployment manually if needed
**⚠️ Production deployment failed - manual intervention required!**`;
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['deployment-failure', 'production', 'urgent']
});