-
Notifications
You must be signed in to change notification settings - Fork 9
40 lines (33 loc) · 1.47 KB
/
update-release-version-in-readme.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: "Update Latest Release Version in README"
on:
release:
types: [published]
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure full history is available for pushing
- name: Switch to the main branch
run: |
git fetch origin main # Fetch latest main branch
git checkout main # Explicitly switch to main branch
git reset --hard origin/main # Reset to match remote state
- name: Get latest release version
run: echo "LATEST_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
- name: Update version in README
run: |
sed -i "s#\(\[latest release\](https://github.com/Kinds-of-Intelligence-CFI/animal-ai/releases/tag/v\)[0-9.]*#\1${LATEST_VERSION}#g" README.md
- name: Commit and push changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add README.md
git commit -m "Update latest release version to $LATEST_VERSION"
git push origin main # Push changes to main branch
- name: Handle detached HEAD (if still in detached state)
if: failure() # Only run this if the previous push fails due to detached HEAD
run: |
git push origin HEAD:main # Push from detached HEAD to main branch