From 9a63ba89298af3a9653524a8758776e8698d4013 Mon Sep 17 00:00:00 2001 From: Phil-NHS Date: Tue, 19 Aug 2025 12:57:44 +0100 Subject: [PATCH] chore(release-cicd): improve error handling and version reporting Error handling previously hid the true underlying errors. This was because when no version increment occurrs the library considers it an error. Issue: ensure errors surface properly and no version bump required is non breaking. --- .github/workflows/release.yml | 81 ++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31f24a9..94b3783 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,7 @@ jobs: runs-on: ubuntu-latest outputs: semantic-release-version: ${{ steps.set_semantic_version.outputs.semantic-release-version }} + semantic-version-change-required: ${{ steps.set_semantic_version.outputs.semantic-version-change-required }} steps: - name: checkout repository uses: actions/checkout@v4 @@ -51,37 +52,75 @@ jobs: echo "Semantic Release packages installed." npm ls --depth=0 # Debug: List installed packages - - #configured with .releaseserc - - name: Run semantic release + - name: run semantic release id: set_semantic_version run: | - set +e - RELEASE_OUTPUT=$(npx semantic-release 2>&1) - echo "$RELEASE_OUTPUT" - - # Try to extract the version from the full output - SEMVER_VERSION=$(echo "$RELEASE_OUTPUT" | grep -oP 'Published release \K[\d.]+') - - # Output it clearly for debugging - echo "Parsed semantic-release version: $SEMVER_VERSION" - - # Set GitHub Action output - echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT - - # Check if SEMVER_VERSION is empty and echo the message if so - if [ -z "$SEMVER_VERSION" ]; then - echo "Changes do not warrant a version change. gh_pages and packages won't be updated." + # Set pipefail so we can check if pipefail is semantic-release classifying no version bump required as an error + set -o pipefail + OUTPUT=$(npx semantic-release 2>&1) || STATUS=$? + echo "$OUTPUT" + + # 0 not exclusively due to no version bump so check output + if [ "${STATUS:-0}" -ne 0 ]; then + if echo "$OUTPUT" | grep -q "No release published"; then + # No new version, but we can find the current version + echo "No new version required getting current version from git tags" + SEMVER_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-placeholder") # last git tag + echo "semantic-release-version=$SEMVER_VERSION" + SEMVER_CHANGED=false + echo "Changes do not warrant a version change. gh_pages and packages won't be updated." + echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT + echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT + exit 0 # treat as success code didnt fail there just was no version increment required + else + exit $STATUS # real error → fail pipeline + fi + else + SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[\d.]+') + echo "semantic-release-version=$SEMVER_VERSION" + # VERSION=$(echo "$OUTPUT" | grep "Published release" | awk '{print $NF}') - AI suggestion try if issues + # awk is a text-processing tool that splits each line into fields using whitespace by default. + # $NF is a special variable in awk that means “the last field” of the current line. + # print $NF prints just that last field. + SEMVER_CHANGED=true + echo "semantic-version-change-required=$SEMVER_CHANGED"" + echo "version change required true" + echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT + echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT + # Just because weve been handling errors + exit 0 fi - set -e + + #configured with .releaseserc + # - name: Run semantic release + # id: set_semantic_version + # run: | + # set +e + # RELEASE_OUTPUT=$(npx semantic-release 2>&1) + # echo "$RELEASE_OUTPUT" + + # # Try to extract the version from the full output + # SEMVER_VERSION=$(echo "$RELEASE_OUTPUT" | grep -oP 'Published release \K[\d.]+') + + # # Output it clearly for debugging + # echo "Parsed semantic-release version: $SEMVER_VERSION" + + # # Set GitHub Action output + # echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT + + # # Check if SEMVER_VERSION is empty and echo the message if so + # if [ -z "$SEMVER_VERSION" ]; then + # echo "Changes do not warrant a version change. gh_pages and packages won't be updated." + # fi + # set -e build-telblazor-package-and-publish: needs: [generate-semantic-version] runs-on: ubuntu-latest - if: ${{ needs.generate-semantic-version.outputs.semantic-release-version != '' }} # Only run if there's a version + if: ${{ needs.generate-semantic-version.outputs.semantic-version-change-required == 'true' }} # Only run if there's a version env: TELBLAZOR_PACKAGE_VERSION: ${{ needs.generate-semantic-version.outputs.semantic-release-version }} steps: