name: Feature Branch CI on: push: branches-ignore: - main - staging pull_request: branches: - staging permissions: contents: write pull-requests: read jobs: test-and-merge: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 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 env: GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} run: pytest -v - name: Merge to staging and push to HF test space if: success() && github.event_name == 'push' env: HF_TOKEN: ${{ secrets.HF_TOKEN }} HF_USERNAME: neurostack-in SPACE_NAME: talk2map-test GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" # Fetch all branches and tags git fetch origin # Check if staging branch exists remotely if git show-ref --verify --quiet refs/remotes/origin/staging; then echo "Staging branch exists, checking out and merging" git checkout staging # Try to merge with strategy to resolve conflicts automatically if git merge ${{ github.ref_name }} --allow-unrelated-histories --no-ff -X theirs -m "Auto-merge ${{ github.ref_name }} to staging"; then echo "Merge successful" else echo "Merge conflicts detected, using feature branch version" # Reset to feature branch state and create merge commit git reset --hard ${{ github.sha }} git commit --allow-empty -m "Auto-merge ${{ github.ref_name }} to staging (using feature branch version)" fi else echo "Staging branch doesn't exist, creating from current branch" git checkout -b staging fi # Push to staging using authenticated remote git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git echo "Pushing to staging branch..." git push origin staging echo "Successfully pushed to staging. This should trigger the promote workflow." # Wait a moment for the push to be processed sleep 5 # Push to Hugging Face test space echo "Pushing to Hugging Face test space..." git push --force \ https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME \ staging:main echo "Successfully pushed to Hugging Face test space."