Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
266b630
Test PR comment and summary features
TheKathan Feb 12, 2026
b738dfb
Simplify PR comment - remove unnecessary note
TheKathan Feb 12, 2026
4c27eea
Reuse PR comment and fix wording
TheKathan Feb 12, 2026
8cf2d48
Fix YAML syntax by using heredoc with placeholders
TheKathan Feb 12, 2026
cc0ffea
fix: simplify PR comment generation using direct variable expansion
TheKathan Feb 12, 2026
82de789
fix: simplify comment format to avoid YAML parsing issues
TheKathan Feb 12, 2026
682e3e1
fix: replace heredoc with printf to avoid YAML parsing
TheKathan Feb 12, 2026
1ca80bc
fix: correct GitHub Actions bot username
TheKathan Feb 12, 2026
654c117
Update PR comment to cleaner one-line format
TheKathan Feb 12, 2026
8caf61e
Move type to separate line in PR comment
TheKathan Feb 12, 2026
93b40a3
Add comprehensive info to PR comment
TheKathan Feb 12, 2026
e98817d
Format PR comment as table
TheKathan Feb 12, 2026
aa7a79a
Only show PR comment when pre-release is enabled
TheKathan Feb 12, 2026
443767b
Only show job summary when on main or pre-release enabled
TheKathan Feb 12, 2026
1b23dcb
Separate job summary into its own step
TheKathan Feb 12, 2026
89a3c31
Remove Previous field from PR comment and summary
TheKathan Feb 12, 2026
58ef509
Update README with PR comment and job summary documentation
TheKathan Feb 12, 2026
aa5b17f
Add check to skip if tag already exists
TheKathan Feb 12, 2026
1cf26e6
Remove redundant comments
TheKathan Feb 12, 2026
d9c9968
Remove testing note from README
TheKathan Feb 12, 2026
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
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -24,6 +25,16 @@ jobs:
fi
echo "Action file validated"

- name: Test PR Features
if: github.event_name == 'pull_request'
id: pr-version
uses: ./
with:
major-version: "1"
enable-prerelease: "true"
comment-on-pr: "true"
add-to-summary: "true"

- name: Create Release Version
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: version
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ When you merge to main, it drops the suffix and creates the final version.
| `enable-prerelease` | `false` | Enable pre-release tags on feature branches |
| `github-token` | `${{ github.token }}` | Token for API access |
| `branch-patterns` | `""` | Custom branch patterns (JSON format, optional) |
| `comment-on-pr` | `false` | Add version preview comment to PRs |
| `comment-on-pr` | `false` | Add version comment to PRs (requires `enable-prerelease: true`) |
| `add-to-summary` | `false` | Add version to GitHub Actions job summary |

## Outputs
Expand All @@ -104,6 +104,39 @@ When you merge to main, it drops the suffix and creates the final version.
|--------|-------------|
| `version` | The version tag that was created (e.g., `v1.2.3`) |
| `is-prerelease` | `true` if it's a pre-release, `false` otherwise |
| `branch` | Branch name used for versioning |
| `previous-version` | Previous version tag |
| `bump-type` | Type of version bump (Minor or Patch) |

## PR Comments & Job Summaries

Enable helpful version information directly in your pull requests and workflow summaries:

```yaml
- uses: TheKathan/semantic-versioning@v1
with:
major-version: "1"
enable-prerelease: "true"
comment-on-pr: "true" # Adds comment to PRs
add-to-summary: "true" # Adds to workflow summary
```

Both features display the same information in a clean table format:

```
## 📦 Version: v1.2.0-alpha.1

| Field | Value |
|-------|-------|
| Type | Pre-release |
| Branch | feature/new-feature |
| Bump | Minor |
```

**Notes:**
- PR comments only appear when `enable-prerelease` is `true` (versions are created on feature branches)
- Job summaries appear on main branch merges or when `enable-prerelease` is `true`
- PR comments are updated in place (no duplicate comments)

## Creating Releases

Expand Down
79 changes: 58 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ outputs:
is-prerelease:
description: "Whether this is a pre-release version"
value: ${{ steps.version.outputs.is_prerelease }}
branch:
description: "Branch name used for versioning"
value: ${{ steps.version.outputs.branch }}
previous-version:
description: "Previous version tag"
value: ${{ steps.version.outputs.previous_version }}
bump-type:
description: "Type of version bump (Minor or Patch)"
value: ${{ steps.version.outputs.bump_type }}

runs:
using: "composite"
Expand Down Expand Up @@ -66,6 +75,12 @@ runs:
IFS='.' read -r MAJ MIN PAT <<< "${LATEST#v}"
echo "Version base: $MAJ.$MIN.$PAT"

# Determine bump type based on branch
BUMP_TYPE="Patch"
case "$BRANCH" in
feature/*|feat/*) BUMP_TYPE="Minor" ;;
esac

if [[ "$BRANCH" == "main" ]]; then
echo "On main branch, checking PR source"
SOURCE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
Expand Down Expand Up @@ -131,46 +146,62 @@ runs:
fi

echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "previous_version=$LATEST" >> $GITHUB_OUTPUT
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT

# Add to job summary if enabled
if [[ "${{ inputs.add-to-summary }}" == "true" ]]; then
echo "## 📦 Version: \`$VERSION\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: \`$BRANCH\`" >> $GITHUB_STEP_SUMMARY
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "- **Type**: Pre-release" >> $GITHUB_STEP_SUMMARY
else
echo "- **Type**: Release" >> $GITHUB_STEP_SUMMARY
fi

- name: Add to Job Summary
if: inputs.add-to-summary == 'true' && (github.ref == 'refs/heads/main' || inputs.enable-prerelease == 'true')
shell: bash
run: |
VERSION="${{ steps.version.outputs.version }}"
IS_PRERELEASE="${{ steps.version.outputs.is_prerelease }}"
BRANCH="${{ steps.version.outputs.branch }}"
PREVIOUS="${{ steps.version.outputs.previous_version }}"
BUMP="${{ steps.version.outputs.bump_type }}"

if [[ "$IS_PRERELEASE" == "true" ]]; then
TYPE="Pre-release"
else
TYPE="Release"
fi

echo "## 📦 Version: **$VERSION**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Type | $TYPE |" >> $GITHUB_STEP_SUMMARY
echo "| Branch | $BRANCH |" >> $GITHUB_STEP_SUMMARY
echo "| Bump | $BUMP |" >> $GITHUB_STEP_SUMMARY

- name: Comment on PR
if: inputs.comment-on-pr == 'true' && github.event_name == 'pull_request'
if: inputs.comment-on-pr == 'true' && github.event_name == 'pull_request' && inputs.enable-prerelease == 'true'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
IS_PRERELEASE="${{ steps.version.outputs.is_prerelease }}"
BRANCH="${{ steps.version.outputs.branch }}"
PREVIOUS="${{ steps.version.outputs.previous_version }}"
BUMP="${{ steps.version.outputs.bump_type }}"

if [[ "$IS_PRERELEASE" == "true" ]]; then
TYPE="Pre-release"
NOTE="Will be published as pre-release tag"
else
TYPE="Release"
NOTE="Will be published when merged to main"
fi

cat > comment.md << EOF
## 📦 Version Preview
printf "## 📦 Version: **%s**\n\n| Field | Value |\n|-------|-------|\n| Type | %s |\n| Branch | %s |\n| Bump | %s |\n" "$VERSION" "$TYPE" "$BRANCH" "$BUMP" > comment-body.txt

This PR will create version: **$VERSION**
EXISTING_COMMENT=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]" and (.body | contains("📦 Version"))) | .id' | head -1)

- Type: **$TYPE**
- $NOTE
EOF

gh pr comment ${{ github.event.pull_request.number }} --body-file comment.md
if [[ -n "$EXISTING_COMMENT" ]]; then
gh api -X PATCH "/repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT" -F body=@comment-body.txt
else
gh pr comment ${{ github.event.pull_request.number }} --body-file comment-body.txt
fi

- name: Push Tag
if: steps.version.outputs.skip_tag != 'true'
Expand All @@ -179,6 +210,12 @@ runs:
VERSION="${{ steps.version.outputs.version }}"
IS_PRERELEASE="${{ steps.version.outputs.is_prerelease }}"

# Check if tag already exists
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION already exists, skipping"
exit 0
fi

git tag "$VERSION"
git push origin "$VERSION"

Expand Down