Skip to content

Merge pull request #140 from mission-minded-llc/develop #28

Merge pull request #140 from mission-minded-llc/develop

Merge pull request #140 from mission-minded-llc/develop #28

Workflow file for this run

name: Tag Version
on:
pull_request:
types: [closed]
push:
branches:
- main
workflow_dispatch:
inputs:
manual_version:
description: "Manual version number (e.g., 1.2.3) - leave empty for auto-increment"
required: false
type: string
pattern: '^[0-9]+\.[0-9]+\.[0-9]+$'
jobs:
tag-version:
runs-on: ubuntu-latest
# Only run on push if it's not from a merged PR (to avoid duplicate runs)
if:
github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'Merge pull
request')
permissions:
contents: write # This allows pushing tags and commits
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch all history and tags
fetch-depth: 0
persist-credentials: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest version from tags
id: current-version
run: |
# Get the latest version tag, defaulting to 0.0.0 if no tags exist
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$LATEST_TAG" ]; then
CURRENT_VERSION="0.0.0"
echo "No version tags found, starting with 0.0.0"
else
# Remove the 'v' prefix to get just the version number
CURRENT_VERSION="${LATEST_TAG#v}"
echo "Latest version tag: $LATEST_TAG"
fi
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new-version
run: |
# Check if manual version was provided via workflow_dispatch
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.manual_version }}" ]; then
echo "Using manual version: ${{ github.event.inputs.manual_version }}"
NEW_VERSION="${{ github.event.inputs.manual_version }}"
else
CURRENT_VERSION="${{ steps.current-version.outputs.current_version }}"
# Split version into parts
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
# Check recent commits for version bump indicators
if git log --oneline -10 | grep -q "\[major\]"; then
echo "Major version bump detected"
NEW_MAJOR=$((MAJOR + 1))
NEW_VERSION="$NEW_MAJOR.0.0"
elif git log --oneline -10 | grep -q "\[minor\]"; then
echo "Minor version bump detected"
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
else
echo "Patch version bump (default)"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
fi
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update package.json version
run: |
NEW_VERSION="${{ steps.new-version.outputs.new_version }}"
npm version $NEW_VERSION --no-git-tag-version
echo "Updated package.json to version $NEW_VERSION"
- name: Version bump and push tag
run: |
# Configure git user
git config --global user.name "GitHub Actions Bot"
git config --global user.email "[email protected]"
# Commit version changes
git add package.json package-lock.json
git commit -m "Bump version to ${{ steps.new-version.outputs.new_version }} [skip ci]" || echo "No changes to commit"
# Create and push tag
git tag -a "v${{ steps.new-version.outputs.new_version }}" -m "Release version ${{ steps.new-version.outputs.new_version }}"
# Push changes and tag back to the repository
git push --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.new-version.outputs.new_version }}
name: Release v${{ steps.new-version.outputs.new_version }}
body: |
## What's Changed
Version ${{ steps.new-version.outputs.new_version }} includes the following changes:
${{ github.event_name == 'pull_request' && format('This release includes changes from merged pull request #{0}.
### Changes
{1}
{2}', github.event.pull_request.number, github.event.pull_request.title, github.event.pull_request.body) || '' }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge main back to develop
run: |
# Check if develop branch exists
if git ls-remote --heads origin develop | grep -q develop; then
echo "Develop branch exists, merging main into develop..."
git fetch origin
git checkout develop
git merge origin/main --no-edit
git push origin develop
echo "Successfully merged main into develop"
else
echo "Develop branch does not exist, skipping merge"
fi