diff --git a/.github/workflows/auto-bump-version.yml b/.github/workflows/auto-bump-version.yml new file mode 100644 index 0000000..16c1277 --- /dev/null +++ b/.github/workflows/auto-bump-version.yml @@ -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 <> "$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 diff --git a/DESCRIPTION b/DESCRIPTION index 2f52392..e0f2c9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: jaspModuleTemplate -Type: Package +Type: Package Title: A module for JASP Version: 0.1.0 Date: 2020-10-15