Skip to content

Commit a8d5eb2

Browse files
chore: bump action version in example to tag instead of SHA (#16)
* fix: vv issue in tag creation * chore: only run after tag publishing * chore: bump action version in example to tag instead of SHA
1 parent 3f799fd commit a8d5eb2

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: Bump Action version
22

33
on:
4-
push:
4+
workflow_run:
5+
workflows: ["Publish Release Tag"]
6+
types:
7+
- completed
58
branches:
69
- main
710
workflow_dispatch:
@@ -16,22 +19,24 @@ jobs:
1619
with:
1720
fetch-depth: 0
1821

19-
- name: Update dirty-waters-action version
22+
- name: Get latest tag from this repository
23+
id: get-latest-tag
2024
run: |
21-
COMMIT_SHA=$(git rev-parse HEAD)
25+
LATEST_TAG=$(git describe --tags --abbrev=0)
26+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
2227
23-
# Use sed to update occurrences of the version in the workflow file
24-
sed -i "s/chains-project\/dirty-waters-action@v[0-9.]\+/chains-project\/dirty-waters-action@${COMMIT_SHA}/g" ./example_workflow.yml
25-
26-
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_ENV
28+
- name: Update dirty-waters-action version to latest tag
29+
run: |
30+
# Use sed to update occurrences of the version in the workflow file with latest tag
31+
sed -i "s/chains-project\/dirty-waters-action@[a-z0-9]\+/chains-project\/dirty-waters-action@${{ env.LATEST_TAG }}/g" ./example_workflow.yml
2732
2833
- name: Update dirty_waters_version in the action to the repo's latest tag
2934
run: |
30-
LATEST_TAG=$(git ls-remote --tags https://github.com/chains-project/dirty-waters.git | awk -F/ '{print $3}' | sort -V | tail -n1)
31-
sed -i "s/DIRTY_WATERS_VERSION=\".*\"/DIRTY_WATERS_VERSION=\"$LATEST_TAG\"/" action.yml
35+
LATEST_DIRTY_WATERS_TAG=$(git ls-remote --tags https://github.com/chains-project/dirty-waters.git | awk -F/ '{print $3}' | sort -V | tail -n1)
36+
sed -i "s/DIRTY_WATERS_VERSION=\".*\"/DIRTY_WATERS_VERSION=\"$LATEST_DIRTY_WATERS_TAG\"/" action.yml
3237
3338
- name: Commit changes
3439
uses: stefanzweifel/git-auto-commit-action@v5.1.0
3540
with:
36-
commit_message: "Bump dirty-waters-action version to ${{ env.commit_sha }}"
41+
commit_message: "Bump dirty-waters-action version to ${{ env.LATEST_TAG }}"
3742
branch: ${{ github.head_ref }}

.github/workflows/publish-release-tag.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,35 @@ jobs:
1818
- name: Get latest tag
1919
id: get-latest-tag
2020
run: |
21-
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0")
21+
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
2222
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV
2323
2424
- name: Generate new tag
2525
id: generate-new-tag
2626
run: |
2727
current_tag=${{ env.LATEST_TAG }}
28-
IFS='.' read -r -a tag_parts <<< "$current_tag"
28+
29+
# Fix double 'v' prefix if it exists (e.g., convert vv1.11.1 to v1.11.1)
30+
if [[ $current_tag == vv* ]]; then
31+
current_tag="v${current_tag#vv}"
32+
echo "Fixing double v prefix in tag: $current_tag"
33+
fi
34+
35+
# Remove the 'v' prefix for version parsing
36+
version=${current_tag#v}
37+
38+
IFS='.' read -r -a tag_parts <<< "$version"
2939
major=${tag_parts[0]}
3040
minor=${tag_parts[1]}
31-
if [ ${#tag_parts[@]} -eq 2 ]; then
41+
42+
# Handle patch version correctly
43+
if [ ${#tag_parts[@]} -lt 3 ]; then
3244
patch=0
3345
else
3446
patch=${tag_parts[2]}
3547
fi
48+
49+
# Create new tag with proper v prefix
3650
new_tag="v$major.$minor.$((patch + 1))"
3751
echo "NEW_TAG=$new_tag" >> $GITHUB_ENV
3852

0 commit comments

Comments
 (0)