22 workflow_dispatch :
33 inputs :
44 version :
5- description : " "
6- type : string
5+ description : " Version type to release (major, minor, patch)"
6+ type : choice
7+ options :
8+ - ' patch'
9+ - ' minor'
10+ - ' major'
711 required : true
812
913name : Create Workflow-Hub GitHub release
10- run-name : " Workflow-Hub GitHub release v ${{ inputs.version }}"
14+ run-name : " Workflow-Hub GitHub release type ${{ inputs.version }}"
1115permissions :
1216 contents : read
1317
@@ -16,24 +20,76 @@ jobs:
1620 permissions :
1721 contents : read
1822 runs-on : ubuntu-latest
23+ outputs :
24+ version : ${{ steps.generate_version.outputs.version }}
1925 steps :
20- - name : Input parameters
21- env :
22- VERSION : ${{ inputs.version }}
23- run : |
24- echo "Version: $VERSION" >> $GITHUB_STEP_SUMMARY
25-
2626 - name : Checkout code
2727 uses : actions/checkout@v6
2828 with :
2929 persist-credentials : false
3030 fetch-depth : 0
3131
32+ - name : Get latest release via GitHub API
33+ id : generate_version
34+ env :
35+ VERSION_TYPE : ${{ inputs.version }}
36+ run : |
37+ set -euo pipefail
38+
39+ RESPONSE=$(curl -s \
40+ -H "Accept: application/vnd.github.v3+json" \
41+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
42+ https://api.github.com/repos/${{ github.repository }}/releases/latest)
43+
44+ LATEST_TAG=$(echo "$RESPONSE" | jq -r '.tag_name')
45+ echo "LATEST_TAG → $LATEST_TAG"
46+
47+ LATEST_VERSION="${LATEST_TAG#v}"
48+ echo "Clean version string → '$LATEST_VERSION'"
49+ IFS='.' read -r raw_major raw_minor raw_patch _ <<< "${LATEST_VERSION}"
50+
51+ MAJOR=${raw_major}
52+ MINOR=${raw_minor}
53+ PATCH=${raw_patch}
54+
55+ [[ ! $MAJOR =~ ^[0-9]+$ ]] && { echo "Error: MAJOR not a number: '$MAJOR'"; exit 2; }
56+ [[ ! $MINOR =~ ^[0-9]+$ ]] && { echo "Error: MINOR not a number: '$MINOR'"; exit 2; }
57+ [[ ! $PATCH =~ ^[0-9]+$ ]] && { echo "Error: PATCH not a number: '$PATCH'"; exit 2; }
58+
59+ echo "Parsed → MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
60+
61+ echo "Increment type → '$VERSION_TYPE'"
62+
63+ case "$VERSION_TYPE" in
64+ patch)
65+ ((PATCH += 1))
66+ ;;
67+ minor)
68+ ((MINOR += 1))
69+ PATCH=0
70+ ;;
71+ major)
72+ ((MAJOR += 1))
73+ MINOR=0
74+ PATCH=0
75+ ;;
76+ *)
77+ echo "Unknown type: '$VERSION_TYPE'"
78+ exit 1
79+ ;;
80+ esac
81+
82+ NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
83+ echo "→ New version: $NEW_VERSION"
84+
85+ echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
86+ echo "**New version**: $NEW_VERSION" >> "$GITHUB_STEP_SUMMARY"
87+
3288 - name : Check if tag exists
3389 id : check_tag
34- uses : netcracker/qubership-workflow-hub/actions/tag-action@b575bad3a0959c4e883bc34f9d055ff07fde2dbd # v2.0.1
90+ uses : netcracker/qubership-workflow-hub/actions/tag-action@v2.1.2
3591 with :
36- tag-name : " v${{ github.event.inputs .version }}"
92+ tag-name : " v${{ steps.generate_version.outputs .version }}"
3793 ref : ${{ github.ref }}
3894 create-tag : false
3995 check-tag : true
@@ -45,11 +101,13 @@ jobs:
45101 permissions :
46102 contents : write
47103 runs-on : ubuntu-latest
104+ env :
105+ VERSION : ${{ needs.check-tag.outputs.version }}
48106 steps :
49107 - name : Checkout code
50108 uses : actions/checkout@v6
51109 with :
52- persist-credentials : false
110+ persist-credentials : true
53111 token : ${{ secrets.GH_ACCESS_TOKEN }}
54112
55113 - name : Set up authentication
@@ -63,15 +121,11 @@ jobs:
63121 git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$REPOSITORY
64122
65123 - name : Create Release Branch
66- env :
67- VERSION : ${{ inputs.version }}
68124 run : |
69125 git checkout -b "release/v$VERSION"
70126 git push origin "release/v$VERSION"
71127
72128 - name : Update references
73- env :
74- VERSION : ${{ inputs.version }}
75129 run : |
76130 # shellcheck disable=2038
77131 find . -type f \( -name '*.yaml' -o -name '*.yml' -o -name '*.md' \) ! -name 'github-release.yml' \
80134 - name : Commit and push changes
81135 env :
82136 ACTOR : ${{ github.actor }}
83- VERSION : ${{ inputs.version }}
84137 run : |
85138 git config --global user.name "$ACTOR"
86139 git config --global user.email "$ACTOR@users.noreply.github.com"
@@ -91,11 +144,11 @@ jobs:
91144 git push origin "v$VERSION"
92145
93146 create-github-release :
94- needs : [release-preparation]
147+ needs : [check-tag, release-preparation]
95148 permissions :
96149 contents : write
97150 uses : netcracker/qubership-workflow-hub/.github/workflows/release-drafter.yml@main
98151 with :
99- version : ${{ inputs .version }}
152+ version : ${{ needs.check-tag.outputs .version }}
100153 publish : false
101- config-name : release-drafter-config .yml
154+ config-name : release-drafter.yml
0 commit comments