This repository was archived by the owner on May 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +67
-11
lines changed Expand file tree Collapse file tree 2 files changed +67
-11
lines changed Original file line number Diff line number Diff line change 1+ name : Update README on Tag
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ tags :
7+ - ' v*'
8+
9+ jobs :
10+ update-readme :
11+ permissions :
12+ contents : read
13+ pull-requests : write
14+ runs-on : ubuntu-latest
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
20+
21+ - name : Get the latest tag
22+ id : get-latest-tag
23+ run : echo "TAG=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT
24+
25+ - name : Run update script
26+ run : ./update-version.sh
27+
28+ - name : Create Pull Request
29+ id : create-pr
30+ uses : peter-evans/create-pull-request@v5
31+ with :
32+ commit-message : ' chore: bump version to ${{ env.TAG }} in README.md files'
33+ title : ' chore: bump version to ${{ env.TAG }} in README.md files'
34+ body : ' This is an auto-generated PR to update README.md files of all modules with the new tag ${{ env.TAG }}'
35+ branch : ' update-readme-branch'
36+ env :
37+ TAG : ${{ steps.get-latest-tag.outputs.TAG }}
38+
39+ - name : Auto-approve
40+ uses : hmarr/auto-approve-action@v4
41+ if : github.ref == 'refs/heads/update-readme-branch'
Original file line number Diff line number Diff line change 66
77set -euo pipefail
88
9- LATEST_TAG=$( git describe --abbrev=0 --tags | sed ' s/^v//' ) || exit $?
9+ current_tag=$( git describe --tags --abbrev=0)
10+ previous_tag=$( git describe --tags --abbrev=0 $current_tag ^)
11+ mapfile -t changed_files < <( git diff --name-only " $previous_tag " " $current_tag " | xargs dirname | sort -u | grep -v ' ^\.' )
1012
11- find . -name README.md | while read -r file; do
12- tmpfile=$( mktemp /tmp/tempfile.XXXXXX)
13- awk -v tag=" $LATEST_TAG " ' {
14- if ($1 == "version" && $2 == "=") {
15- sub(/"[^"]*"/, "\"" tag "\"")
16- print
17- } else {
18- print
19- }
20- }' " $file " > " $tmpfile " && mv " $tmpfile " " $file "
13+ changed_dirs=()
14+ for file in $changed_files ; do
15+ dir=$( dirname " $file " )
16+ changed_dirs+=(" $dir " )
2117done
18+ changed_dirs=($( printf " %s\n" " ${changed_dirs[@]} " | sort -u) )
19+
20+ LATEST_TAG=$( git describe --abbrev=0 --tags | sed ' s/^v//' ) || exit $?
21+
22+ for dir in " ${changed_dirs[@]} " ; do
23+ if [[ -f " $dir /README.md" ]]; then
24+ echo " Bumping version in $dir /README.md"
25+ file=" $dir /README.md"
26+ tmpfile=$( mktemp /tmp/tempfile.XXXXXX)
27+ awk -v tag=" $LATEST_TAG " ' {
28+ if ($1 == "version" && $2 == "=") {
29+ sub(/"[^"]*"/, "\"" tag "\"")
30+ print
31+ } else {
32+ print
33+ }
34+ }' " $file " > " $tmpfile " && mv " $tmpfile " " $file "
35+ fi
36+ done
You can’t perform that action at this time.
0 commit comments