3232 runs-on : ubuntu-latest
3333 outputs :
3434 semantic-release-version : ${{ steps.set_semantic_version.outputs.semantic-release-version }}
35+ semantic-version-change-required : ${{ steps.set_semantic_version.outputs.semantic-version-change-required }}
3536 steps :
3637 - name : checkout repository
3738 uses : actions/checkout@v4
@@ -51,37 +52,75 @@ jobs:
5152 echo "Semantic Release packages installed."
5253 npm ls --depth=0 # Debug: List installed packages
5354
54-
55-
5655 # configured with .releaseserc
57- - name : Run semantic release
56+ - name : run semantic release
5857 id : set_semantic_version
5958 run : |
60- set +e
61- RELEASE_OUTPUT=$(npx semantic-release 2>&1)
62- echo "$RELEASE_OUTPUT"
63-
64- # Try to extract the version from the full output
65- SEMVER_VERSION=$(echo "$RELEASE_OUTPUT" | grep -oP 'Published release \K[\d.]+')
66-
67- # Output it clearly for debugging
68- echo "Parsed semantic-release version: $SEMVER_VERSION"
69-
70- # Set GitHub Action output
71- echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT
72-
73- # Check if SEMVER_VERSION is empty and echo the message if so
74- if [ -z "$SEMVER_VERSION" ]; then
75- echo "Changes do not warrant a version change. gh_pages and packages won't be updated."
59+ # Set pipefail so we can check if pipefail is semantic-release classifying no version bump required as an error
60+ set -o pipefail
61+ OUTPUT=$(npx semantic-release 2>&1) || STATUS=$?
62+ echo "$OUTPUT"
63+
64+ # 0 not exclusively due to no version bump so check output
65+ if [ "${STATUS:-0}" -ne 0 ]; then
66+ if echo "$OUTPUT" | grep -q "No release published"; then
67+ # No new version, but we can find the current version
68+ echo "No new version required getting current version from git tags"
69+ SEMVER_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-placeholder") # last git tag
70+ echo "semantic-release-version=$SEMVER_VERSION"
71+ SEMVER_CHANGED=false
72+ echo "Changes do not warrant a version change. gh_pages and packages won't be updated."
73+ echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT
74+ echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT
75+ exit 0 # treat as success code didnt fail there just was no version increment required
76+ else
77+ exit $STATUS # real error → fail pipeline
78+ fi
79+ else
80+ SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[\d.]+')
81+ echo "semantic-release-version=$SEMVER_VERSION"
82+ # VERSION=$(echo "$OUTPUT" | grep "Published release" | awk '{print $NF}') - AI suggestion try if issues
83+ # awk is a text-processing tool that splits each line into fields using whitespace by default.
84+ # $NF is a special variable in awk that means “the last field” of the current line.
85+ # print $NF prints just that last field.
86+ SEMVER_CHANGED=true
87+ echo "semantic-version-change-required=$SEMVER_CHANGED""
88+ echo "version change required true"
89+ echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT
90+ echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT
91+ # Just because weve been handling errors
92+ exit 0
7693 fi
77- set -e
94+
95+ # configured with .releaseserc
96+ # - name: Run semantic release
97+ # id: set_semantic_version
98+ # run: |
99+ # set +e
100+ # RELEASE_OUTPUT=$(npx semantic-release 2>&1)
101+ # echo "$RELEASE_OUTPUT"
102+
103+ # # Try to extract the version from the full output
104+ # SEMVER_VERSION=$(echo "$RELEASE_OUTPUT" | grep -oP 'Published release \K[\d.]+')
105+
106+ # # Output it clearly for debugging
107+ # echo "Parsed semantic-release version: $SEMVER_VERSION"
108+
109+ # # Set GitHub Action output
110+ # echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT
111+
112+ # # Check if SEMVER_VERSION is empty and echo the message if so
113+ # if [ -z "$SEMVER_VERSION" ]; then
114+ # echo "Changes do not warrant a version change. gh_pages and packages won't be updated."
115+ # fi
116+ # set -e
78117
79118
80119
81120 build-telblazor-package-and-publish :
82121 needs : [generate-semantic-version]
83122 runs-on : ubuntu-latest
84- if : ${{ needs.generate-semantic-version.outputs.semantic-release- version != ' ' }} # Only run if there's a version
123+ if : ${{ needs.generate-semantic-version.outputs.semantic-version-change-required == 'true ' }} # Only run if there's a version
85124 env :
86125 TELBLAZOR_PACKAGE_VERSION : ${{ needs.generate-semantic-version.outputs.semantic-release-version }}
87126 steps :
0 commit comments