https://github.com/carry0987/version-extractor
A GitHub Action to extract and parse semantic versions from tags, refs, or manual input.
https://github.com/carry0987/version-extractor
actions semver tsdown typescript
Last synced: 6 days ago
JSON representation
A GitHub Action to extract and parse semantic versions from tags, refs, or manual input.
- Host: GitHub
- URL: https://github.com/carry0987/version-extractor
- Owner: carry0987
- License: mit
- Created: 2026-03-13T12:21:51.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-03-20T14:31:47.000Z (3 months ago)
- Last Synced: 2026-03-21T06:41:11.206Z (3 months ago)
- Topics: actions, semver, tsdown, typescript
- Language: TypeScript
- Homepage:
- Size: 274 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Version Extractor
A GitHub Action that extracts and parses semantic versions from tags, refs, or manual input. Provides the full version string and individual semver components as action outputs.
## Usage
```yaml
- uses: carry0987/version-extractor@v1
id: version
with:
tag: ${{ github.event.release.tag_name }}
- run: echo "Deploying version ${{ steps.version.outputs.version }}"
# outputs.version → v1.3.0
# outputs.version-number → 1.3.0
```
## Inputs
| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `tag` | No | `''` | Tag to extract version from (e.g. `v1.3.0`). Takes priority over `fallback-ref`. |
| `fallback-ref` | No | `${{ github.ref_name }}` | Fallback ref name when `tag` is empty |
| `prefix` | No | `v` | Version prefix to strip |
| `strict` | No | `true` | Whether to strictly validate semver format |
| `extract-pattern` | No | `''` | Regex to extract version from raw input (first capture group is used if present) |
| `fail-on-error` | No | `true` | Whether to fail the action when version extraction fails |
## Outputs
| Output | Description | Example |
|--------|-------------|---------|
| `found` | Whether a valid version was found | `true` / `false` |
| `source` | The raw input string before any processing | `v1.3.0` |
| `version` | Full version string with prefix | `v1.3.0` |
| `version-number` | Version string without prefix | `1.3.0` |
| `major` | Major version number | `1` |
| `minor` | Minor version number | `3` |
| `patch` | Patch version number | `0` |
| `prerelease` | Prerelease identifier (if any) | `beta.1` |
| `is-prerelease` | Whether the version is a prerelease | `true` / `false` |
## Examples
### Extract version from a release tag
```yaml
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: carry0987/version-extractor@v1
id: version
with:
tag: ${{ github.event.release.tag_name }}
- run: |
echo "Version: ${{ steps.version.outputs.version }}"
echo "Version Number: ${{ steps.version.outputs.version-number }}"
echo "Major: ${{ steps.version.outputs.major }}"
```
### Extract version from a pushed tag
```yaml
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: carry0987/version-extractor@v1
id: version
- run: echo "Building ${{ steps.version.outputs.version }}"
```
### Custom prefix
```yaml
- uses: carry0987/version-extractor@v1
id: version
with:
tag: 'release-2.5.1'
prefix: 'release-'
# outputs.version → release-2.5.1
# outputs.version-number → 2.5.1
```
### Prerelease detection
```yaml
- uses: carry0987/version-extractor@v1
id: version
with:
tag: 'v3.0.0-beta.1'
- if: steps.version.outputs.is-prerelease == 'true'
run: echo "This is a prerelease!"
```
### Extract version from text with regex
Use `extract-pattern` to pull a version out of arbitrary text (e.g. commit messages):
```yaml
- uses: carry0987/version-extractor@v1
id: version
with:
tag: 'chore: release v1.2.0'
extract-pattern: 'v?(\d+\.\d+\.\d+)'
# outputs.version → v1.2.0
# outputs.version-number → 1.2.0
```
### Soft failure mode
Set `fail-on-error` to `false` to emit a warning instead of failing the action when no version is found:
```yaml
- uses: carry0987/version-extractor@v1
id: version
with:
tag: 'not-a-version'
fail-on-error: false
- if: steps.version.outputs.found == 'true'
run: echo "Version ${{ steps.version.outputs.version }}"
```
### Strict mode (default)
Strict mode only accepts valid semver strings:
```yaml
- uses: carry0987/version-extractor@v1
with:
tag: '1.3'
# ❌ Fails — "1.3" is not valid semver
```
### Non-strict mode
Non-strict mode uses `semver.coerce` as a fallback, accepting partial versions:
```yaml
- uses: carry0987/version-extractor@v1
with:
tag: '1.3'
strict: false
# outputs.version → 1.3.0
```
## License
[MIT](LICENSE)