Spaces:
Sleeping
Sleeping
Download .github/workflows/promote.yml from neurostack-in/talk2map-test: direct link, hf CLI and curl.
- Browser
- Download file 8.53 kB
-
https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/.github/workflows/promote.yml
- Command line
-
hf download hf://spaces/neurostack-in/talk2map-test/.github/workflows/promote.yml
-
curl -L -o promote.yml https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/.github/workflows/promote.yml
8.53 kB
| name: Manual Staging to Main Promotion | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: 'Reason for promotion to main' | |
| required: false | |
| default: 'Manual promotion triggered' | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| test-staging-and-promote: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout staging | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: staging | |
| fetch-depth: 0 | |
| lfs: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - 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 tests on staging | |
| id: test-staging | |
| env: | |
| GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} | |
| run: | | |
| echo "Manual promotion reason: ${{ github.event.inputs.reason }}" | |
| echo "Starting manual promotion from staging to main..." | |
| echo "Running tests on staging branch before promotion..." | |
| pytest -v | |
| echo "β Staging tests passed!" | |
| - name: Check for merge conflicts with main | |
| id: conflict-check | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "Checking for potential merge conflicts with main..." | |
| git fetch origin main:main 2>/dev/null || { | |
| echo "main_exists=false" >> $GITHUB_OUTPUT | |
| echo "β οΈ Main branch doesn't exist yet. Will create it from staging." | |
| exit 0 | |
| } | |
| echo "main_exists=true" >> $GITHUB_OUTPUT | |
| # Try a test merge to check for conflicts | |
| git checkout main | |
| git checkout staging | |
| if git merge-tree $(git merge-base main staging) main staging | grep -q "<<<<<<< "; then | |
| echo "has_conflicts=true" >> $GITHUB_OUTPUT | |
| echo "β Merge conflicts detected with main branch!" | |
| # Get conflict details | |
| conflict_files=$(git merge-tree $(git merge-base main staging) main staging | grep "<<<<<<< " -A 10 -B 2 || echo "Unable to determine conflict details") | |
| echo "conflict_details<<EOF" >> $GITHUB_OUTPUT | |
| echo "$conflict_files" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_conflicts=false" >> $GITHUB_OUTPUT | |
| echo "β No merge conflicts detected with main!" | |
| fi | |
| - name: Create conflict alert issue | |
| if: steps.conflict-check.outputs.has_conflicts == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = `π¨ Staging to Main Merge Conflict Alert`; | |
| const body = `## Merge Conflict Detected During Promotion | |
| **Source Branch:** \`staging\` | |
| **Target Branch:** \`main\` | |
| **Commit:** ${context.sha} | |
| ### Conflict Details: | |
| \`\`\` | |
| ${{ steps.conflict-check.outputs.conflict_details }} | |
| \`\`\` | |
| ### Action Required: | |
| The staging branch cannot be automatically promoted to main due to merge conflicts. | |
| **Options:** | |
| 1. **Manual Resolution:** Use the [Manual Promotion workflow](${context.payload.repository.html_url}/actions/workflows/manual-promote.yml) after resolving conflicts | |
| 2. **Fix Conflicts:** Manually resolve conflicts in a feature branch and re-merge to staging | |
| ### Manual Resolution Commands: | |
| \`\`\`bash | |
| git checkout main | |
| git pull origin main | |
| git merge staging | |
| # Resolve conflicts manually | |
| git add . | |
| git commit -m "Resolve staging to main merge conflicts" | |
| git push origin main | |
| \`\`\` | |
| This issue will be closed when the promotion is successful.`; | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['merge-conflict', 'promotion-blocked', 'urgent'] | |
| }); | |
| - name: Create test failure alert | |
| if: steps.test-staging.outcome == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = `β Staging Tests Failed - Promotion Blocked`; | |
| const body = `## Staging Branch Tests Failed | |
| **Branch:** \`staging\` | |
| **Commit:** ${context.sha} | |
| **Workflow:** ${context.workflow} | |
| **Run ID:** ${context.runId} | |
| ### Issue: | |
| Tests failed on the staging branch, blocking automatic promotion to main. | |
| ### Action Required: | |
| 1. Review the [failed workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId}) | |
| 2. Fix the failing tests in a feature branch | |
| 3. Merge the fix to staging to retry promotion | |
| ### Test Command: | |
| \`\`\`bash | |
| pytest -v | |
| \`\`\` | |
| This issue will be closed when tests pass and promotion succeeds.`; | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['test-failure', 'promotion-blocked', 'urgent'] | |
| }); | |
| - name: Clean workspace | |
| if: steps.test-staging.outcome == 'success' && steps.conflict-check.outputs.has_conflicts == 'false' | |
| run: | | |
| git reset --hard | |
| git clean -fdx | |
| - name: Promote staging to main | |
| if: steps.test-staging.outcome == 'success' && steps.conflict-check.outputs.has_conflicts == 'false' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "β Tests passed and no conflicts detected. Proceeding with promotion to main..." | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| git fetch origin | |
| git reset --hard | |
| git clean -fdx | |
| # Handle main branch creation or checkout | |
| if [ "${{ steps.conflict-check.outputs.main_exists }}" = "true" ]; then | |
| echo "Checking out existing main branch" | |
| git checkout main | |
| git merge staging --no-ff -m "Auto-promote staging to main" | |
| else | |
| echo "Creating main branch from staging" | |
| git checkout -b main | |
| fi | |
| # Push to main | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | |
| echo "Pushing to main branch..." | |
| git push origin main | |
| echo "β Successfully promoted staging to main!" | |
| echo "π This will trigger deployment to production..." | |
| - name: Create success notification | |
| if: steps.test-staging.outcome == 'success' && steps.conflict-check.outputs.has_conflicts == 'false' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = `β Staging Successfully Promoted to Main`; | |
| const body = `## Promotion Successful | |
| **Source Branch:** \`staging\` | |
| **Target Branch:** \`main\` | |
| **Commit:** ${context.sha} | |
| ### Status: | |
| - β Tests passed on staging | |
| - β No merge conflicts detected | |
| - β Successfully merged to main | |
| - π Production deployment triggered | |
| ### Next Steps: | |
| The [Deploy to Production workflow](${context.payload.repository.html_url}/actions) will now run to deploy the main branch to HuggingFace production space. | |
| **Production URL:** https://neurostack-in-talk2map-prod.hf.space`; | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['promotion-success', 'deployment'] | |
| }); | |