74 lines
2.4 KiB
YAML
74 lines
2.4 KiB
YAML
name: Auto Versioning and Release
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
version:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Generate semantic version (fallback script)
|
|
id: semver
|
|
run: |
|
|
# Ensure git tags are fetched
|
|
git fetch --tags --quiet || true
|
|
# Get latest tag or default to v0.0.0
|
|
TAG=$(git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0")
|
|
echo "Detected latest tag: $TAG"
|
|
# Set outputs for downstream steps
|
|
echo "version=$TAG" >> $GITHUB_OUTPUT
|
|
echo "release_notes=Fallback: using latest tag only" >> $GITHUB_OUTPUT
|
|
echo "changed=false" >> $GITHUB_OUTPUT
|
|
|
|
- name: Show version
|
|
run: |
|
|
echo "Next version: ${{ steps.semver.outputs.version }}"
|
|
|
|
- id: create_tag
|
|
name: Create annotated tag and push
|
|
if: ${{ steps.semver.outputs.changed }}
|
|
run: |
|
|
# Ensure a committer identity is configured in the runner so git tag works
|
|
git config --global user.email "actions@github.com"
|
|
git config --global user.name "GitHub Actions"
|
|
|
|
# Normalize the version: remove any leading 'v' so we don't end up with 'vvX.Y.Z'
|
|
RAW="${{ steps.semver.outputs.version }}"
|
|
VERSION_NO_V="${RAW#v}"
|
|
|
|
TAG="v${VERSION_NO_V}"
|
|
echo "TAG=${TAG}"
|
|
|
|
# If tag already exists, skip creation to avoid failure
|
|
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
|
|
echo "Tag ${TAG} already exists; skipping tag creation"
|
|
else
|
|
git tag -a "${TAG}" -m "Release ${TAG}"
|
|
git push origin "${TAG}"
|
|
fi
|
|
|
|
# Export the tag for downstream steps
|
|
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Create GitHub Release (tag-only, no workspace changes)
|
|
if: ${{ steps.semver.outputs.changed }}
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
tag_name: ${{ steps.create_tag.outputs.tag }}
|
|
name: Release ${{ steps.create_tag.outputs.tag }}
|
|
body: ${{ steps.semver.outputs.release_notes }}
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|