Skip to content

Commit 3c9d870

Browse files
authored
xuy-UID2-5055-release-operator-from-releas-branch (#167)
* xuy-UID2-5055-release-operator-from-releas-branch
1 parent 1114cab commit 3c9d870

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

actions/check_branch_and_release_type/action.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
FORCE_RELEASE=${{ inputs.force_release == 'yes' }}
2626
FORCE_NOT_RELEASE=${{ inputs.force_release == 'no' }}
2727
CHECK_BRANCH_FOR_RELEASE=${{ inputs.force_release == 'branch' }}
28-
BRANCH_ALLOWS_RELEASE=${{ (inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name) }}
28+
BRANCH_ALLOWS_RELEASE=${{ (inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name || startsWith(github.ref_name, 'release')) }}
2929
if $FORCE_RELEASE; then
3030
ISRELEASE=true
3131
elif $FORCE_NOT_RELEASE; then
@@ -46,9 +46,9 @@ runs:
4646
script: |
4747
core.setFailed('Snapshot packages can not be created on the default branch. Release Type: ${{ inputs.release_type }}, Branch: ${{ github.ref_name }}')
4848
49-
- name: Fail if Release and not on Default branch
50-
if: ${{ inputs.release_type != 'Snapshot' && github.event.repository.default_branch != github.ref_name }}
49+
- name: Fail if Release and not on Default branch or release-yyyy-q branch
50+
if: ${{ inputs.release_type != 'Snapshot' && github.event.repository.default_branch != github.ref_name && !startsWith(github.ref_name, 'release')}}
5151
uses: actions/github-script@v7
5252
with:
5353
script: |
54-
core.setFailed('Releases can not be created on a feature branch. Release Type: ${{ inputs.release_type }}, Branch: ${{ github.ref_name }}')
54+
core.setFailed('Releases can only be created on a Default or release-yyyy-q branch. Release Type: ${{ inputs.release_type }}, Branch: ${{ github.ref_name }}')

actions/version_number/action.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ runs:
7979
else
8080
echo "new_version=$NBGV_SimpleVersion-SNAPSHOT" >> $GITHUB_OUTPUT
8181
fi
82+
elif [[ "$BRANCH_NAME" =~ ^release.* ]]; then
83+
git fetch --tags --all
84+
# Find the base tag that the branch derived from
85+
BASE_TAG=$(git describe --tags --abbrev=0 $(git merge-base HEAD origin/main))
86+
BASE_TAG_CLEAN=$(echo "$BASE_TAG" | sed -E 's/-r[0-9]+$//')
87+
# Count number of commits since the clean tag
88+
REV_COUNT=$(git rev-list --count ${BASE_TAG_CLEAN}..HEAD)
89+
VERSION="$(echo "$BASE_TAG_CLEAN" | sed -E 's/^v//')-r${REV_COUNT}"
90+
echo "new_version=$VERSION" >> $GITHUB_OUTPUT
8291
elif [[ "$BRANCH_NAME_TRUNC" != "" && "$BRANCH_NAME_TRUNC" != "master" && "$BRANCH_NAME_TRUNC" != "main" ]]; then
8392
echo "new_version=$NBGV_SimpleVersion-$BRANCH_NAME_TRUNC" >> $GITHUB_OUTPUT
8493
else

0 commit comments

Comments
 (0)