@@ -4,7 +4,7 @@ name: Tag from composer.json version
44on :
55 workflow_dispatch :
66 push :
7- branches : [ 3.x ]
7+ branches : [ " 3.x" ]
88 paths :
99 - composer.json
1010
@@ -16,70 +16,70 @@ jobs:
1616 runs-on : ubuntu-latest
1717
1818 steps :
19- - name : Checkout repository (with history & tags)
20- uses : actions/checkout@v4
21- with :
22- fetch-depth : 0
19+ - name : Checkout repository (with history & tags)
20+ uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 0
2323
24- - name : Install jq
25- run : sudo apt-get update && sudo apt-get install -y jq
24+ - name : Install jq
25+ run : sudo apt-get update && sudo apt-get install -y jq
2626
27- - name : Get current and previous version
28- id : versions
29- shell : bash
30- run : |
31- # extract current version from composer.json
32- CURR_VERSION=$(jq -r '.version // empty' composer.json)
33- if [ -z "$CURR_VERSION" ] || [ "$CURR_VERSION" = "null" ]; then
34- echo "composer.json has no .version field – aborting."
35- exit 1
36- fi
27+ - name : Get current and previous version
28+ id : versions
29+ shell : bash
30+ run : |
31+ # extract current version from composer.json
32+ CURR_VERSION=$(jq -r '.version // empty' composer.json)
33+ if [ -z "$CURR_VERSION" ] || [ "$CURR_VERSION" = "null" ]; then
34+ echo "composer.json has no .version field – aborting."
35+ exit 1
36+ fi
3737
38- # get previous version from previous commit if composer.json existed there
39- if git rev-parse HEAD~1 >/dev/null 2>&1; then
40- if git show HEAD~1:composer.json >/dev/null 2>&1; then
41- PREV_VERSION=$(git show HEAD~1:composer.json | jq -r '.version // empty')
42- else
43- PREV_VERSION=""
44- fi
38+ # get previous version from previous commit if composer.json existed there
39+ if git rev-parse HEAD~1 >/dev/null 2>&1; then
40+ if git show HEAD~1:composer.json >/dev/null 2>&1; then
41+ PREV_VERSION=$(git show HEAD~1:composer.json | jq -r '.version // empty')
4542 else
4643 PREV_VERSION=""
4744 fi
45+ else
46+ PREV_VERSION=""
47+ fi
4848
49- echo "curr=$CURR_VERSION" >> $GITHUB_OUTPUT
50- echo "prev=$PREV_VERSION" >> $GITHUB_OUTPUT
49+ echo "curr=$CURR_VERSION" >> " $GITHUB_OUTPUT"
50+ echo "prev=$PREV_VERSION" >> " $GITHUB_OUTPUT"
5151
52- - name : Continue only if version changed
53- if : steps.versions.outputs.curr != steps.versions.outputs.prev
54- run :
55- echo "Version changed : ${{ steps.versions.outputs.prev }} -> ${{ steps.versions.outputs.curr }}"
52+ - name : Continue only if version changed
53+ if : steps.versions.outputs.curr != steps.versions.outputs.prev
54+ run : |
55+ echo "Version changed: ${{ steps.versions.outputs.prev }} -> ${{ steps.versions.outputs.curr }}"
5656
57- - name : Stop if version is unchanged
58- if : steps.versions.outputs.curr == steps.versions.outputs.prev
59- run : |
60- echo "Version unchanged (${{ steps.versions.outputs.curr }}) – no tag needed."
61- exit 0
57+ - name : Stop if version is unchanged
58+ if : steps.versions.outputs.curr == steps.versions.outputs.prev
59+ run : |
60+ echo "Version unchanged (${{ steps.versions.outputs.curr }}) – no tag needed."
61+ exit 0
6262
63- - name : Check if tag already exists
64- id : check_tag
65- run : |
66- TAG="v${{ steps.versions.outputs.curr }}"
67- if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1 || \
68- git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
69- echo "exists=true" >> $GITHUB_OUTPUT
70- else
71- echo "exists=false" >> $GITHUB_OUTPUT
72- fi
63+ - name : Check if tag already exists
64+ id : check_tag
65+ run : |
66+ TAG="v${{ steps.versions.outputs.curr }}"
67+ if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1 || \
68+ git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
69+ echo "exists=true" >> " $GITHUB_OUTPUT"
70+ else
71+ echo "exists=false" >> " $GITHUB_OUTPUT"
72+ fi
7373
74- - name : Create and push tag (with v prefix)
75- if : steps.check_tag.outputs.exists == 'false'
76- run : |
77- TAG="v${{ steps.versions.outputs.curr }}"
78- git config user.name "github-actions[bot]"
79- git config user.email "github-actions[bot]@users.noreply.github.com"
80- git tag "$TAG"
81- git push origin "$TAG"
74+ - name : Create and push tag (with v prefix)
75+ if : steps.check_tag.outputs.exists == 'false'
76+ run : |
77+ TAG="v${{ steps.versions.outputs.curr }}"
78+ git config user.name "github-actions[bot]"
79+ git config user.email "github-actions[bot]@users.noreply.github.com"
80+ git tag "$TAG"
81+ git push origin "$TAG"
8282
83- - name : Info if tag already exists
84- if : steps.check_tag.outputs.exists == 'true'
85- run : echo "Tag v${{ steps.versions.outputs.curr }} already exists – nothing to do."
83+ - name : Info if tag already exists
84+ if : steps.check_tag.outputs.exists == 'true'
85+ run : echo "Tag v${{ steps.versions.outputs.curr }} already exists – nothing to do."
0 commit comments