start new version. inc versionNr #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow automates the process of creating GitHub Releases when a new version | |
# is detected in the `mod.json` file. It ensures that a release is created only if | |
# the version number in `mod.json` has been incremented, and it generates release notes | |
# based on the commits since the last release. | |
name: Create GitHub Release | |
# This workflow is triggered on pushes to the specified branches (e.g., master or main) | |
# AND when the `mod.json` file is modified. Both conditions must be met for the workflow | |
# to run. | |
on: | |
push: | |
paths: | |
- 'mod.json' | |
branches: | |
- master # Or main, depending on your branch name | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Important to fetch all tags | |
- name: Get Version from mod.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r .version mod.json) | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
- name: Calculate Release Version and Tag | |
id: calculate_release_version | |
run: | | |
VERSION="${{ steps.get_version.outputs.VERSION }}" | |
# Extract the parts of the version number | |
MAJOR=$(echo "$VERSION" | cut -d'.' -f1) | |
MINOR=$(echo "$VERSION" | cut -d'.' -f2) | |
PATCH=$(echo "$VERSION" | cut -d'.' -f3) | |
# Calculate the RELEASE version (one less than current version in mod.json) | |
if [[ "$PATCH" -gt 0 ]]; then | |
RELEASE_VERSION="$MAJOR.$MINOR.$((PATCH - 1))" | |
elif [[ "$MINOR" -gt 0 ]]; then | |
RELEASE_VERSION="$MAJOR.$((MINOR - 1)).99" # Assuming 99 is the last patch version | |
elif [[ "$MAJOR" -gt 0 ]]; then | |
RELEASE_VERSION="$((MAJOR - 1)).99.99" # Assuming 99 is the last minor version | |
else | |
RELEASE_VERSION="0.0.0" # Or whatever makes sense for your project | |
fi | |
RELEASE_TAG="v$RELEASE_VERSION" | |
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT | |
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
- name: Check if Tag Exists | |
id: check_tag_exists | |
run: | | |
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}" | |
git fetch --tags | |
if git rev-parse --verify "refs/tags/$RELEASE_TAG" >/dev/null 2>&1; then | |
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT | |
echo "Tag $RELEASE_TAG already exists. Skipping release creation." | |
else | |
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT | |
echo "Tag $RELEASE_TAG does not exist. Proceeding with release creation." | |
fi | |
- name: Generate Release Notes | |
id: generate_release_notes | |
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false' | |
run: | | |
VERSION="${{ steps.get_version.outputs.VERSION }}" | |
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}" | |
# Using git log to get commits since the calculated tag | |
RELEASE_NOTES=$(git log --pretty=format:"- %s" $(git describe --abbrev=0 --tags || echo HEAD) ..HEAD) | |
RELEASE_NOTES="https://autocivp.netlify.app/download/latest.zip \n${RELEASE_NOTES}" | |
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT | |
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create Release | |
uses: actions/create-release@v1 | |
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.calculate_release_version.outputs.RELEASE_TAG }} | |
release_name: Release ${{ steps.calculate_release_version.outputs.RELEASE_TAG }} | |
body: ${{ steps.generate_release_notes.outputs.RELEASE_NOTES }} | |
draft: false | |
prerelease: false | |
- name: Create Tag (if it doesn't exist) | |
if: steps.check_tag_exists.outputs.TAG_EXISTS == 'false' | |
run: | | |
VERSION="${{ steps.get_version.outputs.VERSION }}" | |
RELEASE_TAG="${{ steps.calculate_release_version.outputs.RELEASE_TAG }}" | |
git tag $RELEASE_TAG | |
git push origin $RELEASE_TAG | |
echo "Created tag $RELEASE_TAG" | |