Update README with Release Branches #100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update README with Release Branches | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "15 8 * * *" # Runs every day (UTC) | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Git | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
- name: Update README | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN_CPRIMA_FOR_RPAPUB }} | |
run: | | |
cd "${{ runner.temp }}" | |
repos=("rpapub/REFramework-VB-legacy" "rpapub/REFramework-CSharp-legacy" "rpapub/REFramework-VB-Windows" "rpapub/REFramework-CSharp-Windows") | |
PRE_COMMENT="<!-- START OF AUTO-GENERATED CONTENT -->" | |
POST_COMMENT="<!-- END OF AUTO-GENERATED CONTENT -->" | |
for repo in "${repos[@]}"; do | |
echo "Updating README for $repo" | |
git clone https://x-access-token:[email protected]/$repo "$(basename $repo)" | |
cd "$(basename $repo)" | |
git checkout readme || git checkout -b readme | |
branches=$(git branch -r | grep 'release/v') | |
echo $branches | |
new_content="" | |
for branch in $branches; do | |
branch_name="${branch#*/}" | |
new_content+="- [$branch_name](https://github.com/$repo/tree/$branch_name)\n" | |
done | |
echo $new_content | |
# Find the line numbers of the comment markers | |
start_line=$(grep -n "$PRE_COMMENT" README.md | cut -d: -f1) | |
end_line=$(grep -n "$POST_COMMENT" README.md | cut -d: -f1) | |
# Replace the content between the markers | |
if [ -n "$start_line" ] && [ -n "$end_line" ]; then | |
# Extract and store the content before and after the markers | |
head -n "$((start_line - 1))" README.md > README.tmp | |
tail -n "+$((end_line + 1))" README.md >> README.tmp | |
# Recreate README.md with the new content between the markers | |
mv README.tmp README.md | |
echo "$PRE_COMMENT" >> README.md | |
echo -e "$new_content" >> README.md | |
echo "$POST_COMMENT" >> README.md | |
else | |
echo -e "\n$PRE_COMMENT\n$new_content\n$POST_COMMENT" >> README.md | |
fi | |
git add README.md | |
if git diff --staged --quiet; then | |
echo "No changes to commit." | |
else | |
COMMIT_MSG="Update README with vendor UiPath's release branches - commit $(date +"%Y-%m-%d")" | |
git commit -m "$COMMIT_MSG" | |
git push -u origin readme | |
fi | |
cd .. | |
done |