@@ -0,0 +1,75 @@
|
||||
name: Check and Add Version in Changelog
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
check-and-add-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Extract and Determine Version
|
||||
id: extract_version
|
||||
run: |
|
||||
# Fetch the latest tags from the remote
|
||||
git fetch --tags
|
||||
|
||||
# Get the latest tag, or initialize to v0.0.0 if no tags are found
|
||||
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "v0.0.0")
|
||||
|
||||
# Extract version from PR title or body
|
||||
pr_body="${{ github.event.pull_request.body }}"
|
||||
pr_title="${{ github.event.pull_request.title }}"
|
||||
version_regex="v([0-9]+)\.([0-9]+)\.([0-9]+)"
|
||||
|
||||
if [[ $pr_body =~ $version_regex ]]; then
|
||||
major=${BASH_REMATCH[1]}
|
||||
minor=${BASH_REMATCH[2]}
|
||||
patch=${BASH_REMATCH[3]}
|
||||
new_tag="v$major.$minor.$patch"
|
||||
elif [[ $pr_title =~ $version_regex ]]; then
|
||||
major=${BASH_REMATCH[1]}
|
||||
minor=${BASH_REMATCH[2]}
|
||||
patch=${BASH_REMATCH[3]}
|
||||
new_tag="v$major.$minor.$patch"
|
||||
else
|
||||
# Split the latest tag into parts
|
||||
IFS='.' read -r -a parts <<< "${latest_tag#v}"
|
||||
major=${parts[0]}
|
||||
minor=${parts[1]}
|
||||
patch=${parts[2]}
|
||||
patch=$((patch + 1))
|
||||
new_tag="v$major.$minor.$patch"
|
||||
fi
|
||||
|
||||
clean_version="${new_tag#v}"
|
||||
echo "version=$clean_version" >> $GITHUB_ENV
|
||||
echo "Version determined: $clean_version"
|
||||
|
||||
- name: Check if Version Already Exists in Tags
|
||||
run: |
|
||||
version="${{ env.version }}"
|
||||
if git tag --list | grep -q "^$version$"; then
|
||||
echo "Version $version already exists in tags."
|
||||
exit 1
|
||||
else
|
||||
echo "Version $version does not exist in tags."
|
||||
fi
|
||||
|
||||
- name: Check Version in CHANGELOG
|
||||
id: check_version
|
||||
run: |
|
||||
version="${{ env.version }}"
|
||||
if ! grep -q "^## \[$version\]" CHANGELOG.md; then
|
||||
echo "Version $version not found in CHANGELOG.md."
|
||||
exit 1
|
||||
else
|
||||
echo "Version $version found in CHANGELOG.md."
|
||||
fi
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
|
||||
jobs:
|
||||
bump-version:
|
||||
if: ${{ github.event.pull_request.merged == true $$ github.event.pull_request.base.ref == 'main' }}
|
||||
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
@@ -17,27 +17,46 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Bump Version and Tag
|
||||
id: bump_version
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
run: |
|
||||
# Fetch the latest tags from the remote
|
||||
git fetch --tags
|
||||
|
||||
# Get the latest tag
|
||||
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
|
||||
# Get the latest tag, or initialize to v0.0.0 if no tags are found
|
||||
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "v0.0.0")
|
||||
|
||||
# Split the latest tag into parts
|
||||
IFS='.' read -r -a parts <<< "${latest_tag#v}"
|
||||
# Extract version from PR title or body
|
||||
pr_body="${{ github.event.pull_request.body }}"
|
||||
pr_title="${{ github.event.pull_request.title }}"
|
||||
version_regex="v([0-9]+)\.([0-9]+)\.([0-9]+)"
|
||||
|
||||
# Increment the patch version
|
||||
major=${parts[0]}
|
||||
minor=${parts[1]}
|
||||
patch=${parts[2]}
|
||||
new_patch=$((patch + 1))
|
||||
|
||||
# Create a new tag
|
||||
new_tag="v$major.$minor.$new_patch"
|
||||
if [[ $pr_body =~ $version_regex ]]; then
|
||||
major=${BASH_REMATCH[1]}
|
||||
minor=${BASH_REMATCH[2]}
|
||||
patch=${BASH_REMATCH[3]}
|
||||
new_tag="v$major.$minor.$patch"
|
||||
elif [[ $pr_title =~ $version_regex ]]; then
|
||||
major=${BASH_REMATCH[1]}
|
||||
minor=${BASH_REMATCH[2]}
|
||||
patch=${BASH_REMATCH[3]}
|
||||
new_tag="v$major.$minor.$patch"
|
||||
else
|
||||
# Split the latest tag into parts
|
||||
IFS='.' read -r -a parts <<< "${latest_tag#v}"
|
||||
major=${parts[0]}
|
||||
minor=${parts[1]}
|
||||
patch=${parts[2]}
|
||||
patch=$((patch + 1))
|
||||
new_tag="v$major.$minor.$patch"
|
||||
fi
|
||||
|
||||
echo "Bumping version from $latest_tag to $new_tag"
|
||||
|
||||
# Set the new tag as an environment variable
|
||||
echo "new_tag=$new_tag" >> $GITHUB_ENV
|
||||
|
||||
# Tag the new version
|
||||
git tag $new_tag
|
||||
|
||||
@@ -46,3 +65,33 @@ jobs:
|
||||
|
||||
# Push the new tag to the remote repository
|
||||
git push origin $new_tag
|
||||
|
||||
- name: Extract Release Notes
|
||||
id: extract_notes
|
||||
run: |
|
||||
version="${{ env.new_tag }}"
|
||||
clean_version="${version#v}"
|
||||
release_notes=$(awk -v version="$clean_version" '
|
||||
BEGIN { flag=0 }
|
||||
# Start flagging when the version section is found
|
||||
/^## \[.*\]/ {
|
||||
if (flag) exit # Exit when the next section starts
|
||||
}
|
||||
/^## \['"$clean_version"'\]/ { flag=1; next } # Start printing after the header
|
||||
flag { print } # Print lines while flag is 1
|
||||
' CHANGELOG.md)
|
||||
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
|
||||
echo "$release_notes" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
|
||||
- name: Create Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ env.new_tag }}
|
||||
release_name: Release ${{ env.new_tag }}
|
||||
body: ${{ env.RELEASE_NOTES }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
Reference in New Issue
Block a user