Skip to content

Commit 1c69697

Browse files
committed
chore(error): grep error
1 parent 1e9e044 commit 1c69697

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

.github/workflows/dev.yml

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,42 +89,70 @@ jobs:
8989
# qqqq if we are not versioning the repo why arnt we dry running
9090
- name: Run dev semantic version (None Blocking)
9191
run: |
92-
# Set pipefail so we can check if pipefail is semantic-release classifying no version bump required as an error
93-
# qqqq set -o pipefail
94-
# qqqq now were dry running do we need to error handle?
95-
set +e
92+
93+
#set +e
9694
# Due to dry-run need to catch error differently : SEMVER_OUTPUT_RAW=$(npx semantic-release --dry-run 2>&1) || STATUS=$?
9795
echo "running semantic-release"
9896
SEMVER_OUTPUT_RAW=$(npx semantic-release --dry-run 2>&1)
9997
STATUS=$?
10098
echo "status = $STATUS"
99+
#set -e
100+
echo "$SEMVER_OUTPUT_RAW"
101+
102+
# Get fallback version
103+
FALLBACK_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-not-found")
104+
echo "FALLBACK_VERSION=$FALLBACK_VERSION"
105+
106+
set +e
107+
# Check what's in the output
108+
GREP_NO_CHANGES=$(echo "$SEMVER_OUTPUT_RAW" | grep -q 'There are no relevant changes' && echo "true" || echo "false")
109+
GREP_WOULD_PUBLISH=$(echo "$SEMVER_OUTPUT_RAW" | grep -q 'Dry run: would publish version' && echo "true" || echo "false")
110+
echo "GREP_NO_CHANGES=$GREP_NO_CHANGES"
111+
echo "GREP_WOULD_PUBLISH=$GREP_WOULD_PUBLISH"
101112
set -e
102-
echo "$SEMVER_OUTPUT_RAW"
103-
104-
# 0 not exclusively due to no version bump so check output
105-
if [ "${STATUS:-0}" -ne 0 ]; then
106-
echo "in if status 0"
107-
if echo "$SEMVER_OUTPUT_RAW" | grep -q "There are no relevant changes"; then
108-
echo "in if no release published"
109-
# No new version, but we can find the current version
110-
echo "No new version required getting current version from git tags"
111-
DEV_SEMVER_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-not-found") # last git tag so if multiple bumps in other branches making package version there will be some discrepancy but the purpose is distinguishing them for dev purposes.
112-
echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
113-
exit 0 # treat as success code didnt fail there just was no version increment required
114-
else
115-
echo "in else no release published"
116-
exit $STATUS # real error → fail pipeline
117-
fi
118-
else
119-
# Get version include prerelease tag
120-
# Dry run returns different text DEV_SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[^\s]+')
121-
echo "in else so status was zero for error"
122-
DEV_SEMVER_VERSION=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Dry run: would publish version \K[^\s]+')
123-
echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
113+
114+
# Check for no changes and set DEV_SEMVER_VERSION accordingly
115+
if echo "$SEMVER_OUTPUT_RAW" | grep -q 'There are no relevant changes'; then
116+
DEV_SEMVER_VERSION="$FALLBACK_VERSION"
117+
echo "No relevant changes found - DEV_SEMVER_VERSION=$DEV_SEMVER_VERSION"
118+
elif echo "$SEMVER_OUTPUT_RAW" | grep -q 'Dry run: would publish version'; then
119+
# Extract the actual version
120+
DEV_SEMVER_VERSION=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Dry run: would publish version \K[^\s]+' || echo "extract-failed")
121+
echo "Version change detected - DEV_SEMVER_VERSION=$DEV_SEMVER_VERSION"
124122
echo "version change required true"
125-
# Just because weve been handling errors
126-
exit 0
123+
else
124+
echo "Neither 'no changes' nor 'would publish' found, using fallback"
125+
DEV_SEMVER_VERSION="$FALLBACK_VERSION"
126+
echo "DEV_SEMVER_VERSION=$DEV_SEMVER_VERSION"
127127
fi
128+
129+
exit 0
130+
131+
# 0 not exclusively due to no version bump so check output
132+
# dry release seems not to error 1 qqqq!
133+
# if [ "${STATUS:-0}" -ne 0 ]; then
134+
# echo "in if status 0"
135+
# if echo "$SEMVER_OUTPUT_RAW" | grep -q "There are no relevant changes"; then
136+
# echo "in if no release published"
137+
# # No new version, but we can find the current version
138+
# echo "No new version required getting current version from git tags"
139+
# DEV_SEMVER_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-not-found") # last git tag so if multiple bumps in other branches making package version there will be some discrepancy but the purpose is distinguishing them for dev purposes.
140+
# echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
141+
# exit 0 # treat as success code didnt fail there just was no version increment required
142+
# else
143+
# echo "in else no release published"
144+
# exit $STATUS # real error → fail pipeline
145+
# fi
146+
# else
147+
# # Get version include prerelease tag
148+
# # Dry run returns different text DEV_SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[^\s]+')
149+
# echo "in else so status was zero for error"
150+
# DEV_SEMVER_VERSION=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Dry run: would publish version \K[^\s]+')
151+
# echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
152+
# echo "version change required true"
153+
# # Just because weve been handling errors
154+
# exit 0
155+
# fi
128156

129157

130158
# qqqq - name: Run semantic version (None Blocking)

0 commit comments

Comments
 (0)