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
70 changes: 70 additions & 0 deletions .github/workflows/auto-bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Auto-bump Version on Merge

# This triggers ONLY when code is pushed directly to master
# (which includes when a Pull Request is merged into it).
on:
push:
branches:
- master # If your default branch is 'main', change this to 'main'

jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write # Required so the bot can push the new commit to your repo
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Calculate and Update Version
run: |
# 1. Extract current version from the DESCRIPTION file
CURRENT_VERSION=$(grep -i "^Version:" DESCRIPTION | awk '{print $2}')

# SECURITY CHECK: Ensure it strictly matches a version number format (e.g., 0.17.0 or 0.17.0.9000)
if [[ ! "$CURRENT_VERSION" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
echo "❌ Error: Invalid version format in DESCRIPTION: '$CURRENT_VERSION'"
exit 1
fi

# 2. Split the version string by periods into an array
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"

# 3. Increment the very last number by 1
LAST_INDEX=$((${#VERSION_PARTS[@]} - 1))
VERSION_PARTS[$LAST_INDEX]=$((VERSION_PARTS[$LAST_INDEX] + 1))

# 4. Stitch the version string back together
NEW_VERSION=$(IFS='.'; echo "${VERSION_PARTS[*]}")

echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"

# 5. Safely replace the old version with the new version in the file
sed -i "s/^Version: [0-9.]\+/Version: $NEW_VERSION/i" DESCRIPTION

# 6. Securely pass the new version to the next step for the commit message
cat <<EOF >> "$GITHUB_ENV"
NEW_VERSION=$NEW_VERSION
EOF

- name: Commit and Push
run: |
# Configure Git to act as the official GitHub Actions bot
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

# Stage the changed file
git add DESCRIPTION

# Check if there are actually changes to commit (prevents errors if version didn't change)
if ! git diff-index --quiet HEAD; then
# The [skip ci] flag is CRITICAL. It tells GitHub NOT to trigger
# another workflow run from this automated commit, preventing infinite loops.
git commit -m "chore: auto-bump version to ${{ env.NEW_VERSION }} [skip ci]"
git push
echo "✅ Successfully bumped version and pushed to master."
else
echo "No changes needed."
fi
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: jaspModuleTemplate
Type: Package
Type: Package
Title: A module for JASP
Version: 0.1.0
Date: 2020-10-15
Expand Down