name: Auto Update from Upstream
on:
schedule:
# Run once a day at midnight UTC
- cron: '0 0 * * *'
# Allow manual triggering
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- name: Setup Git Identity
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Add Upstream Remote
run: |
git remote add upstream https://github.com/brightdata/brightdata-mcp.git
git remote -v
- name: Fetch Upstream Changes
run: |
git fetch upstream
- name: Check for Updates
id: check-updates
run: |
if git log HEAD..upstream/main --oneline | grep -q .; then
echo "updates_available=true" >> $GITHUB_OUTPUT
echo "Updates available from upstream repository."
else
# When manually triggered, proceed even if there are no updates
# This allows testing the workflow
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Manually triggered workflow - proceeding with update process for testing"
echo "updates_available=true" >> $GITHUB_OUTPUT
else
echo "updates_available=false" >> $GITHUB_OUTPUT
echo "No updates available from upstream repository."
fi
fi
- name: Apply Updates
if: steps.check-updates.outputs.updates_available == 'true'
run: |
# Create a temporary branch for updates
git checkout -b temp-update
# Merge upstream changes
git merge upstream/main -m "Auto-merge upstream changes"
# List of files we want to preserve (Heroku-specific files)
PRESERVED_FILES=("app.json" "Procfile" "verify_heroku_config.js" "update_from_upstream.sh" ".github/workflows/auto-update.yml" "README_HEROKU.md")
# Make sure our preserved files are not overwritten
for file in "${PRESERVED_FILES[@]}"; do
if [ -f "$file" ]; then
git checkout HEAD@{1} -- "$file"
git add "$file"
fi
done
# Check if README.md was modified upstream
if git diff --name-only HEAD@{1} HEAD | grep -q "README.md"; then
echo "README.md was modified upstream, preserving our Heroku button section"
# Fix README.md with Heroku button
# First, create a backup of current README
cp README.md README.md.bak
# Add Heroku button below title if not present
if ! grep -q "Deploy to Heroku" README.md; then
# Get the line number of the h3 tag
TITLE_LINE=$(grep -n "<h3 align=\"center\">Enhance your LLM and AI agents with real-time web access</h3>" README.md | cut -d: -f1)
if [ -n "$TITLE_LINE" ]; then
# Use awk to insert content after the h3 line
awk -v line="$TITLE_LINE" -v heroku_button='
<p align="center">
<a href="https://heroku.com/deploy?template=https://github.com/dsouza-anush/brightdata-mcp-heroku">
<img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy to Heroku">
</a>
</p>' '
NR == line {print; print heroku_button; next}
{print}
' README.md.bak > README.md
fi
fi
# Add to table of contents if not present
if ! grep -q "Deploy to Heroku" README.md; then
# Get the line of the table of contents
TOC_LINE=$(grep -n "## Table of Content" README.md | cut -d: -f1)
if [ -n "$TOC_LINE" ]; then
# Find the MCP Playgrounds line in TOC
PLAYGROUNDS_LINE=$(grep -n "- \\[🎮 Try Bright Data MCP Playgrounds\\]" README.md | cut -d: -f1)
if [ -n "$PLAYGROUNDS_LINE" ]; then
# Insert Deploy to Heroku entry before Playgrounds
sed -i "${PLAYGROUNDS_LINE}i- [☁️ Deploy to Heroku](#%EF%B8%8F-deploy-to-heroku)" README.md
fi
fi
fi
# Add Deploy to Heroku section if not present
if ! grep -q "^## ☁️ Deploy to Heroku" README.md; then
# Find Playgrounds heading
PLAYGROUNDS_HEADING=$(grep -n "## 🎮 Try Bright Data MCP Playgrounds" README.md | cut -d: -f1)
if [ -n "$PLAYGROUNDS_HEADING" ]; then
# Insert deploy section before playgrounds heading
HEROKU_SECTION="## ☁️ Deploy to Heroku\n\nYou can deploy this MCP server to Heroku with one click using the button below:\n\n[](https://heroku.com/deploy?template=https://github.com/dsouza-anush/brightdata-mcp-heroku)\n\nAfter deployment, make sure to set the required environment variables in your Heroku app settings.\n\nThis MCP server is compatible with Heroku Inference and can be registered with your AI models. For detailed instructions, see the [Heroku-specific documentation](README_HEROKU.md#using-with-heroku-inference).\n"
sed -i "${PLAYGROUNDS_HEADING}i${HEROKU_SECTION}\n" README.md
fi
fi
git add README.md
fi
# Commit the preserved changes
git commit -m "Preserve Heroku-specific changes" || echo "No changes needed"
# Checkout back to main branch
git checkout main
# Merge the temporary branch
git merge temp-update -m "Auto-update from upstream with preserved Heroku changes"
# Delete the temporary branch
git branch -D temp-update
- name: Push Changes
if: steps.check-updates.outputs.updates_available == 'true'
run: git push origin main