Skip to content

Commit c80bab9

Browse files
authored
Merge pull request #103 from TechnologyEnhancedLearning/refactor-logging
Refactor logging
2 parents 8a5f955 + 99d5432 commit c80bab9

File tree

2 files changed

+66
-29
lines changed

2 files changed

+66
-29
lines changed

.github/workflows/dev.yml

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,51 +85,87 @@ jobs:
8585
echo "Semantic Release packages installed."
8686
npm ls --depth=0 # Debug: List installed packages
8787
88-
- name: Run semantic version (None Blocking)
88+
#configured with .releaseserc
89+
# qqqq if we are not versioning the repo why arnt we dry running
90+
- name: Run dev semantic version (None Blocking)
8991
run: |
90-
# If no version is required we can get an error so here we handle it
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?
9195
set +e
96+
# Due to dry-run need to catch error differently : SEMVER_OUTPUT_RAW=$(npx semantic-release --dry-run 2>&1) || STATUS=$?
97+
SEMVER_OUTPUT_RAW=$(npx semantic-release --dry-run 2>&1)
98+
STATUS=$?
99+
set -e
100+
echo "$SEMVER_OUTPUT_RAW"
101+
102+
# 0 not exclusively due to no version bump so check output
103+
if [ "${STATUS:-0}" -ne 0 ]; then
104+
if echo "$SEMVER_OUTPUT_RAW" | grep -q "No release published"; then
105+
# No new version, but we can find the current version
106+
echo "No new version required getting current version from git tags"
107+
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.
108+
echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
109+
exit 0 # treat as success code didnt fail there just was no version increment required
110+
else
111+
exit $STATUS # real error → fail pipeline
112+
fi
113+
else
114+
# Get version include prerelease tag
115+
# Dry run returns different text DEV_SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[^\s]+')
116+
DEV_SEMVER_VERSION=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Dry run: would publish version \K[^\s]+')
117+
echo "DEV_SEMVER_VERSION = $DEV_SEMVER_VERSION"
118+
echo "version change required true"
119+
# Just because weve been handling errors
120+
exit 0
121+
fi
122+
123+
124+
# qqqq - name: Run semantic version (None Blocking)
125+
# run: |
126+
# # If no version is required we can get an error so here we handle it
127+
# set +e
92128

93-
SEMVER_OUTPUT_RAW=$(npx semantic-release)
94-
echo "Raw SEMVER_OUTPUT_RAW=$SEMVER_OUTPUT_RAW"
129+
# SEMVER_OUTPUT_RAW=$(npx semantic-release)
130+
# echo "Raw SEMVER_OUTPUT_RAW=$SEMVER_OUTPUT_RAW"
95131

96-
SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Published release \K[^\s]+')
132+
# SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Published release \K[^\s]+')
97133

98-
# In development, we always package and update the website—even if there’s no version change.
99-
# This ensures the CI process runs consistently and the latest code is deployed.
100-
# It's especially useful when squashing commits, as it guarantees the package is still rebuilt and published.
101-
echo "Packaging and updating the website in development, even without version changes, to ensure consistent CI behavior and updated packages after squashed commits."
134+
# # In development, we always package and update the website—even if there’s no version change.
135+
# # This ensures the CI process runs consistently and the latest code is deployed.
136+
# # It's especially useful when squashing commits, as it guarantees the package is still rebuilt and published.
137+
# echo "Packaging and updating the website in development, even without version changes, to ensure consistent CI behavior and updated packages after squashed commits."
102138

103-
STATUS=$?
104-
if [ -z "$SEMVER_OUTPUT" ]; then
105-
SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Found git tag v\K[^\s]+')
106-
# Note: If Semver falls back to using a Git tag, it will pick the most recent one.
107-
# This tag may not belong to the current branch, so the result isn't guaranteed to reflect the latest changes on this branch.
108-
echo "Semver fallback: using latest Git tag, which may not be from the current branch."
109-
fi
139+
# STATUS=$?
140+
# if [ -z "$SEMVER_OUTPUT" ]; then
141+
# SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Found git tag v\K[^\s]+')
142+
# # Note: If Semver falls back to using a Git tag, it will pick the most recent one.
143+
# # This tag may not belong to the current branch, so the result isn't guaranteed to reflect the latest changes on this branch.
144+
# echo "Semver fallback: using latest Git tag, which may not be from the current branch."
145+
# fi
110146

111-
if [ -z "$SEMVER_OUTPUT" ]; then
112-
SEMVER_OUTPUT="0.0.0"
113-
echo "No semantic version or tag, defaulting to 0.0.0 $SEMVER_OUTPUT"
114-
fi
147+
# if [ -z "$SEMVER_OUTPUT" ]; then
148+
# SEMVER_OUTPUT="0.0.0"
149+
# echo "No semantic version or tag, defaulting to 0.0.0 $SEMVER_OUTPUT"
150+
# fi
115151

116-
# Export the result to the environment
117-
echo "SEMVER_OUTPUT=$SEMVER_OUTPUT" >> $GITHUB_ENV
118-
set -e
152+
# # Export the result to the environment
153+
# echo "SEMVER_OUTPUT=$SEMVER_OUTPUT" >> $GITHUB_ENV
154+
# set -e
119155

120156

121157
- name: Rename Semver Version with branch date time dev
122158
id: set_dev_semantic_version
123159
run: |
124-
echo "Semantic Release Output $SEMVER_OUTPUT"
160+
echo "Dev Semantic Release Output $DEV_SEMVER_VERSION"
125161
126162
# In development, we always package and update the website—even if there’s no version change.
127163
# This ensures the CI process runs consistently and the latest code is deployed.
128164
# It's especially useful when squashing commits, as it guarantees the package is still rebuilt and published.
129165
timestamp=$(date +"%y%m%d-%H%M")
130166
echo "Timestamp $timestamp"
131167
132-
full_version="${SEMVER_OUTPUT}-${timestamp}"
168+
full_version="${DEV_SEMVER_VERSION}-${timestamp}"
133169
echo "extracted version $full_version"
134170
echo "dev-semantic-version=$full_version" >> $GITHUB_OUTPUT
135171

.github/workflows/release.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ jobs:
5656
- name: run semantic release
5757
id: set_semantic_version
5858
run: |
59-
# Set pipefail so we can check if pipefail is semantic-release classifying no version bump required as an error
60-
set -o pipefail
59+
# Set error to not instantly fail so we can check if error is semantic-release classifying no version bump required as an error
60+
set +e
6161
OUTPUT=$(npx semantic-release 2>&1) || STATUS=$?
62+
set -e
6263
echo "$OUTPUT"
6364
6465
# 0 not exclusively due to no version bump so check output
@@ -79,7 +80,7 @@ jobs:
7980
else
8081
SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[\d.]+')
8182
echo "semantic-release-version=$SEMVER_VERSION"
82-
# VERSION=$(echo "$OUTPUT" | grep "Published release" | awk '{print $NF}') - AI suggestion try if issues
83+
# qqqq VERSION=$(echo "$OUTPUT" | grep "Published release" | awk '{print $NF}') - AI suggestion try if issues
8384
# awk is a text-processing tool that splits each line into fields using whitespace by default.
8485
# $NF is a special variable in awk that means “the last field” of the current line.
8586
# print $NF prints just that last field.
@@ -93,7 +94,7 @@ jobs:
9394
fi
9495
9596
#configured with .releaseserc
96-
# - name: Run semantic release
97+
# qqqq- name: Run semantic release
9798
# id: set_semantic_version
9899
# run: |
99100
# set +e

0 commit comments

Comments
 (0)