Skip to content

Instantly share code, notes, and snippets.

@tatiana
Created January 9, 2025 11:11
Show Gist options
  • Save tatiana/21f10255e79541ccdbe770edd30cf794 to your computer and use it in GitHub Desktop.
Save tatiana/21f10255e79541ccdbe770edd30cf794 to your computer and use it in GitHub Desktop.
Script to automate adding a Dependabot configuration file to multiple GitHub repositories
#!/usr/bin/env bash
# Script to automate adding a Dependabot configuration file to multiple GitHub repositories
# User must have previously installed the GitHub CLI and authenticated using `gh auth login`
REPOSITORIES=(
"astronomer/airflow-dag-versioning-private" # archived
"astronomer/airflow-private"
"astronomer/apache-airflow-providers-transfers" # archived
"astronomer/astro-provider-anyscale"
"astronomer/astro-provider-databricks" # archived
"astronomer/astro-provider-venv"
"astronomer/astro-provider-ray"
"astronomer/airflow-provider-weaviate"
"astronomer/astro-sdk"
# "astronomer/astronomer-cosmos"
"astronomer/creutil"
"astronomer/custom-package-demo"
"astronomer/local-dag-run"
"astronomer/o11y"
# "astronomer/terraform-provider-astro"
)
# Dependabot configuration content
DEPENDABOT_CONFIG="version: 2
updates:
- package-ecosystem: "github-actions"
directory: \"/\"
schedule:
interval: \"daily\""
# Branch name for the changes
BRANCH_NAME="add-dependabot-config"
# Loop through each repository
for REPO in "${REPOSITORIES[@]}"; do
echo "Checking repository: $REPO"
# Check if the repository is archived
IS_ARCHIVED=$(gh repo view "$REPO" --json isArchived -q .isArchived)
if [ "$IS_ARCHIVED" == "true" ]; then
echo "Skipping archived repository: $REPO"
continue
fi
echo "Processing repository: $REPO"
# Clone the repository
git clone "https://github.com/$REPO.git"
REPO_NAME=$(basename "$REPO")
cd "$REPO_NAME" || exit 1
# Create and switch to a new branch
git checkout -b "$BRANCH_NAME"
# Create the .github directory and add the dependabot.yml file
mkdir -p .github
echo "$DEPENDABOT_CONFIG" > .github/dependabot.yml
# Add, commit, and push the changes
git add .github/dependabot.yml
git commit -m "Add Dependabot configuration"
git push -u origin "$BRANCH_NAME"
# Create a pull request using GitHub CLI
gh pr create --title "Add Dependabot configuration" --body "This PR adds a Dependabot configuration file to keep dependencies up to date." --base main
# Move back to the parent directory
cd ..
# Remove the cloned repository to save space
rm -rf "$REPO_NAME"
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment