Closed arzola closed 8 months ago
Update:
Update:
Update:
#!/bin/bash
echo "First parameter: $1"
branch_starting=$1 branch_new=$2
branch_starting="dev" branch_new="chore/bot/update-autoupdate-workflow-to-main"
ORGANIZATION="pressbooks"
repos=("pressbooks-book")
for repo in "${repos[@]}" ; do
echo "Processing repository: $repo"
cd "$repo"
# git branch --list $branch
# if [ $? -eq 0 ]; then
# echo "Branch exists locally."
# break;
# fi
if git diff-index --quiet HEAD --; then
echo "No changes in the repository."
else
echo "There are uncommitted changes in the repository."
git stash;
# break;
fi
# reset starting branch
git fetch origin
git checkout $branch_starting
git pull
git reset --hard origin/$branch_starting
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" = $branch_starting ]; then
git checkout -b $branch_new
# Find and replace the target strings in all files within the repository
grep -rl 'pressbooks/composer-autoupdate-bedrock@v1' . | xargs sed -i '' 's|pressbooks/composer-autoupdate-bedrock@v1|pressbooks/composer-autoupdate-bedrock@main|g'
grep -rl 'pressbooks/composer-autoupdate-bedrock@v2' . | xargs sed -i '' 's|pressbooks/composer-autoupdate-bedrock@v2|pressbooks/composer-autoupdate-bedrock@main|g'
# Check for any changes in the repository and list them
echo "Listing modified, added, or deleted files:"
git status --porcelain | while read -r status file; do
echo "${status} ${file}"
git diff;
done
# Check if there are any changes to commit
if [ -n "$(git status --porcelain)" ]; then
echo 'diff found'
echo 'About to start creating branch, commit and push PR'
read -p "Do you want to proceed? (y/n) " answer
# Normalize the answer to lowercase
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
# Check the user's answer
if [ "$answer" != "y" ] && [ "$answer" != "yes" ]; then
echo "Aborting."
skip;
fi
echo "Proceeding..."
# git config user.email "you@example.com"
# git config user.name "Your Name"
#Commit the changes
git add .
git commit -m 'chore: update workflows that uses versioned pressbooks/composer-autoupdate-bedrock to use main branch to simplify releases.'
# Push the branch to the remote
git push origin $branch_new
# Create a pull request using the GitHub CLI targeting the dev branch
gh pr create --title "chore: update workflow to use main branch for composer-autoupdate-bedrock" \
--body "Resolves: pressbooks/composer-autoupdate-bedrock/issues/73" \
--base "$branch_starting" \
--head "$branch_new"
else
echo "No changes found in $repo."
fi
fi
#clean up
git checkout $branch_starting
git branch -D $branch_new
# Go back to the parent directory
cd ..
done
Our current plugins and themes have a GitHub action step setup after running tests and all the build process that looks like the following:
Our current implementation has a couple of things that should be improved.
The following list of bedrocks is hardcoded in the composer-autoupdate-action repo
See #72 for a related issue.
There are different ways to solve that for example