Skip to content

Commit

Permalink
Merge pull request #49 from edwardtfn/new-versioning-03
Browse files Browse the repository at this point in the history
Fix verison validation
  • Loading branch information
edwardtfn authored Dec 21, 2024
2 parents 46c04eb + 360ae31 commit cf3018c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ jobs:
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Create Temporary Branch
run: |
TEMP_BRANCH="temp/version-bump-$(uuidgen)"
echo "TEMP_BRANCH=${TEMP_BRANCH}" >> "${GITHUB_ENV}"
git checkout -b "${TEMP_BRANCH}"
- name: Bump Version
run: |
chmod +x "./versioning/bump_version.sh"
"./versioning/bump_version.sh"
- name: Push Changes to Temporary Branch
- name: Push Changes and Tags
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
Expand Down
2 changes: 1 addition & 1 deletion versioning/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.12.1
2024.12.2
21 changes: 9 additions & 12 deletions versioning/bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,28 @@ else
CURRENT_VERSION="0.0.0" # Default if file doesn't exist
fi

# Extract components
CURRENT_YEAR=$(date +%Y)
CURRENT_MONTH=$(date +%m)
if ! [[ "$CURRENT_VERSION" =~ ^[0-9]{4}\.[0-9]{2}\.[0-9]{2}$ ]]; then
# Validate the current version format
if ! [[ "$CURRENT_VERSION" =~ ^[0-9]{4}\.[0-9]{1,2}\.[0-9]+$ ]]; then
echo "Error: Invalid version format in $VERSION_FILE"
exit 1
fi

# Extract components
CURRENT_YEAR=$(date +%Y)
CURRENT_MONTH=$(date +%-m) # Avoid leading zero for the month
CURRENT_SEQ=$(echo "$CURRENT_VERSION" | awk -F. '{print $3}')

VERSION_YEAR=$(echo "$CURRENT_VERSION" | awk -F. '{print $1}')
VERSION_MONTH=$(echo "$CURRENT_VERSION" | awk -F. '{print $2}')

# Determine new version
if [[ "$CURRENT_YEAR" == "$VERSION_YEAR" && "$CURRENT_MONTH" == "$VERSION_MONTH" ]]; then
NEXT_SEQ=$((10#$CURRENT_SEQ + 1))
if [ $NEXT_SEQ -gt 99 ]; then
echo "Error: Sequence number would exceed 99"
exit 1
fi
NEW_SEQ=$(printf "%02d" $NEXT_SEQ)
NEXT_SEQ=$((CURRENT_SEQ + 1))
else
NEW_SEQ="01" # Reset sequence for a new month
NEXT_SEQ=1 # Reset sequence for a new month
fi

NEW_VERSION="${CURRENT_YEAR}.${CURRENT_MONTH}.${NEW_SEQ}"
NEW_VERSION="${CURRENT_YEAR}.${CURRENT_MONTH}.${NEXT_SEQ}"

# Update the plain text VERSION file
echo "$NEW_VERSION" > "$VERSION_FILE"
Expand Down

0 comments on commit cf3018c

Please sign in to comment.