Skip to content

Instantly share code, notes, and snippets.

@conor-f
Created January 1, 2024 15:00
Show Gist options
  • Save conor-f/c3fe3880fecaab7d29eb72b8456c5798 to your computer and use it in GitHub Desktop.
Save conor-f/c3fe3880fecaab7d29eb72b8456c5798 to your computer and use it in GitHub Desktop.
Automatically runs Black code formatter on specified repos. Easily changed to any other tool/process.
#!/bin/bash
declare -a repo_names=("repo" "names" "here")
for r in ${repo_names[@]}; do
echo "-----------------------"
echo "$r:"
if [ ! -s $r ]
then
git clone https://github.com/org-name-here/$r
fi
cd $r
echo "Checking out default branch..."
git checkout $(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
echo "Pulling default branch.."
git pull
echo "Checking out new branch..."
git checkout -b automated-black-integration
if [ ! -s .github/workflows/ ]
then
echo "$r doesn't have any github actions! Be careful!"
mkdir -p .github/workflows/
fi
if [ -s .github/workflows/black.yml ]
then
echo "Not adding to $r as it already has black.yml"
else
echo "Adding black.yml..."
echo """name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
src: "./src"""" > .github/workflows/black.yml
echo "git adding black.yml..."
git add .github/workflows/black.yml
echo "git committing black.yml..."
git commit .github/workflows/black.yml -m "Adds GH Actions black.yml."
fi
echo "linting src..."
black src/
echo "committing changes..."
git commit -am "Runs initial Black formatting."
echo "pushing changes..."
git push
echo "creating pr..."
gh pr create -B $(git remote show origin | sed -n '/HEAD branch/s/.*: //p') -r conor-f --title "Adds GH Actions for Black." --body "Automated Commits."
echo "cd back to code root..."
cd ../
echo "Completed $r!"
echo "-----------------------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment