Skip to content

Commit 07ff016

Browse files
authored
Fix update-examples workflow (#489)
Address issue faced by tag sorting in #487, #487. Make it possible to specify both old and new version when running manually.
1 parent 4796efd commit 07ff016

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

.github/scripts/replace_string.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ def _badge_version(version: str) -> str:
5050
return version.replace('-', '--')
5151

5252

53-
def _should_replace_in(repo, file):
54-
return file.is_file() and not repo.ignored(file) and file.parts[0] != '.git'
53+
def _should_replace_in(repo, file: Path) -> bool:
54+
return file.is_file() \
55+
and not repo.ignored(file) \
56+
and file.parts[0] != '.git' \
57+
and file.name != 'test_replace_string.py'
5558

5659

5760
if __name__ == "__main__":

.github/workflows/update-examples.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ on:
55
tags: [ '*' ]
66
workflow_dispatch:
77
inputs:
8-
ref:
8+
old:
9+
description: 'Git ref of version to replace. Leave empty for auto-detect from git tags.'
10+
required: false
11+
new:
912
description: 'Branch or tag'
1013
required: true
1114

@@ -25,13 +28,14 @@ jobs:
2528
- run: pip install -r .github/scripts/requirements.txt
2629
- name: 'Get versions'
2730
run: |
28-
new="${{ inputs.ref || github.ref_name }}"
29-
echo "Deleting '$new' in case it's alpha to stable bump." \
30-
"Git v:refname doesn't handle Maven version qualifiers correctly."
31-
git tag -d "$new"
32-
old="$(git tag --sort=-v:refname | head -n 1)"
33-
echo "OLD_VERSION=$old" | tee -a $GITHUB_ENV
31+
new="${{ inputs.new || github.ref_name }}"
3432
echo "NEW_VERSION=$new" | tee -a $GITHUB_ENV
33+
if [[ "${{ inputs.old }}" == "" ]]; then
34+
echo "Auto-detecting old version from git tags"
35+
# Get previous version from descending tag list
36+
old="$(git tag --sort=-v:refname | grep -A1 "$new" | tail -1)"
37+
fi
38+
echo "OLD_VERSION=$old" | tee -a $GITHUB_ENV
3539
- name: 'Update version in all files'
3640
run: ./.github/scripts/replace_string.py ./ "$OLD_VERSION" "$NEW_VERSION"
3741
- name: 'Create PR'
@@ -42,4 +46,4 @@ jobs:
4246
title: "Bump examples and badges to ${{ env.NEW_VERSION }}"
4347
author: "github-actions <github-actions@github.com>"
4448
committer: "github-actions <github-actions@github.com>"
45-
body: "Bump the version in examples and badges from ${{ env.OLD_VERSION }} to ${{ env.NEW_VERSION }}."
49+
body: "Bump versions from ${{ env.OLD_VERSION }} to ${{ env.NEW_VERSION }}."

0 commit comments

Comments
 (0)