Skip to content

List branches

List branches #8

Workflow file for this run

name: Update README.md on all branches
#Run this workflow every time a push event occurs on the main branch, because almost all commits on the main branch will update the README.md file.
on:
push:
branches:
- main
env:
FILES_TO_SYNC: "README.md"
MY_NAME: "Nikolas Garofil (Using GitHub Actions)"
MY_EMAIL: "[email protected]"
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Update README.md in all other branches
shell: bash
run: |
echo "We will sync the following files: \" $FILES_TO_SYNC \" from ${{ github.ref }} to all other branches being: $(git branch --format='%(refname)')"
echo "Setting up git"
git config --global user.email "$MY_EMAIL"
git config --global user.name "$MY_NAME"
for branch in $(git branch --format='%(refname)'); do
echo "Checking out $branch"
if [[ $branch == ${{ github.ref }} ]]; then
echo "Skipping $branch because the new version of README.md comes from this branch"
continue
else
git checkout $branch
for file in $FILES_TO_SYNC; do
echo "Syncing $file from ${{ github.ref }} to $branch"
git checkout ${{ github.ref }} -- $file
git add $file
done
echo "Committing changes"
git commit -m "Sync $FILES_TO_SYNC from ${{ github.ref }}"
echo "Pushing changes to $branch"
git push origin $branch
fi
done