Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 33 additions & 43 deletions .github/actions/version-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ runs:

# Determine color and status based on version
if [[ $VERSION == *"-dev"* ]]; then
COLOR="blue"
STATUS="Development"
COLOR="red"
STATUS="Unstable Development"
elif [[ $VERSION == *"-alpha"* ]]; then
COLOR="orange"
STATUS="Alpha"
elif [[ $VERSION == *"-beta"* ]]; then
COLOR="yellow"
STATUS="Beta"
elif [[ $VERSION == *"-rc"* ]]; then
COLOR="yellowgreen"
COLOR="blue"
STATUS="Release Candidate"
else
COLOR="brightgreen"
Expand All @@ -135,52 +135,42 @@ runs:
if [[ -f "README.md" ]]; then
BADGES_CHANGED=false

# Extract current version from README badge
if grep -q "\[\!\[Version\]\]" README.md; then
# Extract the current version from the badge URL
CURRENT_VERSION_BADGE=$(grep "\[\!\[Version\]\]" README.md)
echo "Current version badge in README: $CURRENT_VERSION_BADGE"

# Extract just the version number from the current badge
CURRENT_VERSION_IN_BADGE=$(echo "$CURRENT_VERSION_BADGE" | grep -oP 'version-\K[^-]*(?=-|-)' | sed 's/%2E/./g' | sed 's/--/-/g')
echo "Extracted version from README badge: $CURRENT_VERSION_IN_BADGE"
# Get the current version from Solution.props
echo "Current version from Solution.props: $VERSION"

# Create new badge URLs
VERSION_BADGE_URL="https://img.shields.io/badge/version-$ENCODED_VERSION-$COLOR"
STATUS_BADGE_URL="https://img.shields.io/badge/status-$STATUS-$COLOR"

# Create badge markdown
VERSION_BADGE="[![Version]($VERSION_BADGE_URL)](https://github.com/architects-toolkit/SmartHopper/releases)"
STATUS_BADGE="[![Status]($STATUS_BADGE_URL)](https://github.com/architects-toolkit/SmartHopper/releases)"

echo "New version badge: $VERSION_BADGE"
echo "New status badge: $STATUS_BADGE"

# Check if README contains version badge
if grep -q "\[\!\[Version\]" README.md; then
echo "Found version badge in README"

# Compare actual versions, not just badge strings
if [[ "$CURRENT_VERSION_IN_BADGE" != "$VERSION" ]]; then
echo "Version mismatch: README has '$CURRENT_VERSION_IN_BADGE', Solution.props has '$VERSION'"
# Use sed to replace the version badge
sed -i "s|\[\!\[Version\]\](https://img\.shields\.io/badge/version[^)]*)|[![Version]($VERSION_BADGE_URL)|g" README.md
echo "Updated version badge"
BADGES_CHANGED=true
else
echo "Version badge already up to date (both have version $VERSION)"
fi
# Always update the badges with the current version from Solution.props
sed -i "s|\[\!\[Version\](https://img\.shields\.io/badge/version[^)]*)|[![Version]($VERSION_BADGE_URL)|g" README.md
echo "Updated version badge"
BADGES_CHANGED=true
else
echo "No version badge found in README"
echo "No version badge found in README to replace"
fi

# Check if status badge exists and update it
if grep -q "\[\!\[Status\]\]" README.md; then
# Get current status badge
CURRENT_STATUS_BADGE=$(grep "\[\!\[Status\]\]" README.md)
echo "Current status badge in README: $CURRENT_STATUS_BADGE"

# Extract the current status from the badge URL
CURRENT_STATUS_IN_BADGE=$(echo "$CURRENT_STATUS_BADGE" | grep -oP 'status-\K[^-]*(?=-)')
echo "Extracted status from README badge: $CURRENT_STATUS_IN_BADGE"
# Check if README contains status badge
if grep -q "\[\!\[Status\]" README.md; then
echo "Found status badge in README"

# Compare status values
if [[ "$CURRENT_STATUS_IN_BADGE" != "$STATUS" ]]; then
echo "Status mismatch: README has '$CURRENT_STATUS_IN_BADGE', should be '$STATUS'"
# Use sed to replace the status badge
sed -i "s|\[\!\[Status\]\](https://img\.shields\.io/badge/status[^)]*)|[![Status]($STATUS_BADGE_URL)|g" README.md
echo "Updated status badge"
BADGES_CHANGED=true
else
echo "Status badge already up to date (both have status $STATUS)"
fi
# Always update the status badge
sed -i "s|\[\!\[Status\](https://img\.shields\.io/badge/status[^)]*)|[![Status]($STATUS_BADGE_URL)|g" README.md
echo "Updated status badge"
BADGES_CHANGED=true
else
echo "No status badge found in README"
echo "No status badge found in README to replace"
fi

# Check if badges were changed
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/chore-version-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,25 @@ jobs:
run: |
echo "Creating new branch: ${{ env.BADGE_BRANCH }}"
git checkout -b ${{ env.BADGE_BRANCH }}
git add README.md
git commit -m "docs: update version badge for ${{ env.TARGET_BRANCH }}"
git push origin ${{ env.BADGE_BRANCH }}

# Check if there are actual changes to commit
if [[ -n "$(git status --porcelain README.md)" ]]; then
echo "Changes detected in README.md, committing and pushing"
git add README.md
git commit -m "docs: update version badge for ${{ env.TARGET_BRANCH }}"
git push origin ${{ env.BADGE_BRANCH }}
echo "CHANGES_PUSHED=true" >> $GITHUB_ENV
else
echo "No actual changes detected in README.md despite badges-changed=true"
echo "This might indicate a parsing issue in the version-tools action"
echo "::warning::No changes to commit for README.md despite badges-changed=true"
echo "CHANGES_PUSHED=false" >> $GITHUB_ENV
fi

- name: Create PR
if: steps.update-badge.outputs.badges-changed == 'true'
if: steps.update-badge.outputs.badges-changed == 'true' && env.CHANGES_PUSHED == 'true'
run: |
PR_TITLE="docs: update version badge for ${{ env.TARGET_BRANCH }} to ${{ steps.version-check.outputs.version }}"
PR_TITLE="docs: update version badge for ${{ env.TARGET_BRANCH }} to ${{ steps.update-badge.outputs.version }}"
PR_BODY="This PR updates the version badge in the README.md to match the current version in Solution.props.

This is an automated PR created by the Update Version Badge workflow."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SmartHopper - AI-Powered Grasshopper3D Plugin

[![Version](https://img.shields.io/badge/version-0%2E1%2E3--dev%2E250319-yellow)](https://github.com/architects-toolkit/SmartHopper/releases)
[![Status](https://img.shields.io/badge/status-Unstable%20development-yellow)](https://github.com/architects-toolkit/SmartHopper/releases)
[![Version](https://img.shields.io/badge/version-0%2E1%2E3--dev%2E250330-red)](https://github.com/architects-toolkit/SmartHopper/releases)
[![Status](https://img.shields.io/badge/status-Development-red)](https://github.com/architects-toolkit/SmartHopper/releases)
[![Grasshopper](https://img.shields.io/badge/plugin_for-Grasshopper3D-darkgreen?logo=rhinoceros)](https://www.rhino3d.com/)
[![MistralAI](https://img.shields.io/badge/AI--powered-MistralAI-orange)](https://mistral.ai/)
[![OpenAI](https://img.shields.io/badge/AI--powered-OpenAI-blue?logo=openai)](https://openai.com/)
Expand Down
Loading