From 0241b75f8a167bba8927fbedd5dcbae48368f5d7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 30 Jan 2024 18:31:50 +0300 Subject: [PATCH 1/5] ci: automate version bumps in module README.md files closes #138 --- .github/workflows/update-readme.yaml | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/update-readme.yaml diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml new file mode 100644 index 00000000..995c0214 --- /dev/null +++ b/.github/workflows/update-readme.yaml @@ -0,0 +1,38 @@ +name: Update README on Tag + +on: + push: + tags: + - 'v*' + +jobs: + update-readme: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get the latest tag + id: get-latest-tag + run: echo "TAG=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT + + - name: Run update script + run: ./update-readme.sh + + - name: Create Pull Request + id: create-pr + uses: peter-evans/create-pull-request@v5 + with: + commit-message: 'chore: bump version to ${{ steps.get-latest-tag.outputs.TAG }} in README.md files' + title: 'chore: bump version to ${{ steps.get-latest-tag.outputs.TAG }} in README.md files' + body: 'This is an auto-generated PR to update README.md files of all modules with the new tag ${{ steps.get-latest-tag.outputs.TAG }}' + branch: 'update-readme-branch' + + - name: Auto-approve + uses: hmarr/auto-approve-action@v4 + if: github.ref == 'refs/heads/update-readme-branch' From a2066238e60925a93afae4a91683d9ad3f7ed0dd Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 30 Jan 2024 18:32:49 +0300 Subject: [PATCH 2/5] run manually --- .github/workflows/update-readme.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 995c0214..8cd7885e 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -1,10 +1,11 @@ name: Update README on Tag on: + workflow_dispatch: push: tags: - 'v*' - + jobs: update-readme: permissions: From 51d217cc00f8f99c1bbe5ae154907b0403461cd7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 30 Jan 2024 18:33:51 +0300 Subject: [PATCH 3/5] simplify --- .github/workflows/update-readme.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 8cd7885e..4cae4aa1 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -29,10 +29,12 @@ jobs: id: create-pr uses: peter-evans/create-pull-request@v5 with: - commit-message: 'chore: bump version to ${{ steps.get-latest-tag.outputs.TAG }} in README.md files' - title: 'chore: bump version to ${{ steps.get-latest-tag.outputs.TAG }} in README.md files' - body: 'This is an auto-generated PR to update README.md files of all modules with the new tag ${{ steps.get-latest-tag.outputs.TAG }}' + commit-message: 'chore: bump version to ${{ env.TAG }} in README.md files' + title: 'chore: bump version to ${{ env.TAG }} in README.md files' + body: 'This is an auto-generated PR to update README.md files of all modules with the new tag ${{ env.TAG }}' branch: 'update-readme-branch' + env: + TAG: ${{ steps.get-latest-tag.outputs.TAG }} - name: Auto-approve uses: hmarr/auto-approve-action@v4 From 9d798b5ba8a0b4c30efd10fe26bfa5cf49bd9308 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 12 Feb 2024 17:44:32 +0300 Subject: [PATCH 4/5] only bump version for changed modules. --- .github/workflows/update-readme.yaml | 2 +- update-version.sh | 37 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 4cae4aa1..ffda6955 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -23,7 +23,7 @@ jobs: run: echo "TAG=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT - name: Run update script - run: ./update-readme.sh + run: ./update-version.sh - name: Create Pull Request id: create-pr diff --git a/update-version.sh b/update-version.sh index 2fadb577..093069b0 100755 --- a/update-version.sh +++ b/update-version.sh @@ -6,16 +6,31 @@ set -euo pipefail -LATEST_TAG=$(git describe --abbrev=0 --tags | sed 's/^v//') || exit $? +current_tag=$(git describe --tags --abbrev=0) +previous_tag=$(git describe --tags --abbrev=0 $current_tag^) +changed_files=$(git diff --name-only "$previous_tag" "$current_tag") -find . -name README.md | while read -r file; do - tmpfile=$(mktemp /tmp/tempfile.XXXXXX) - awk -v tag="$LATEST_TAG" '{ - if ($1 == "version" && $2 == "=") { - sub(/"[^"]*"/, "\"" tag "\"") - print - } else { - print - } - }' "$file" > "$tmpfile" && mv "$tmpfile" "$file" +changed_dirs=() +for file in $changed_files; do + dir=$(dirname "$file") + changed_dirs+=("$dir") done +changed_dirs=($(printf "%s\n" "${changed_dirs[@]}" | sort -u)) + +LATEST_TAG=$(git describe --abbrev=0 --tags | sed 's/^v//') || exit $? + +for dir in "${changed_dirs[@]}"; do + if [[ -f "$dir/README.md" ]]; then + echo "Bumping version in $dir/README.md" + file="$dir/README.md" + tmpfile=$(mktemp /tmp/tempfile.XXXXXX) + awk -v tag="$LATEST_TAG" '{ + if ($1 == "version" && $2 == "=") { + sub(/"[^"]*"/, "\"" tag "\"") + print + } else { + print + } + }' "$file" > "$tmpfile" && mv "$tmpfile" "$file" + fi +done \ No newline at end of file From bf298551b1e599f61999e70bb9d5d6c607be35e1 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:11:45 +0300 Subject: [PATCH 5/5] Update update-version.sh Co-authored-by: Mathias Fredriksson --- update-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-version.sh b/update-version.sh index 093069b0..433f614a 100755 --- a/update-version.sh +++ b/update-version.sh @@ -8,7 +8,7 @@ set -euo pipefail current_tag=$(git describe --tags --abbrev=0) previous_tag=$(git describe --tags --abbrev=0 $current_tag^) -changed_files=$(git diff --name-only "$previous_tag" "$current_tag") +mapfile -t changed_files < <(git diff --name-only "$previous_tag" "$current_tag" | xargs dirname | sort -u | grep -v '^\.') changed_dirs=() for file in $changed_files; do