Files
TSinjex/.github/workflows/CreateRelease.yml

118 lines
4.5 KiB
YAML

name: Create Release
on:
push:
branches:
- main
- 'dev/*'
paths:
- 'package.json'
workflow_dispatch: # Allows manual execution of the workflow.
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.8.0'
- name: Install dependencies, run tests and build
run: npm run prepare:deploy
- name: Get the version
id: get_version
run: |
VERSION=$(npm run version:show | tail -n 1)
echo "VERSION=v$VERSION" >> $GITHUB_ENV
shell: bash
- name: Get previous release tag
id: get_previous_release
run: |
echo "Fetching previous release tag..."
previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$previous_tag" ]; then
echo "No previous tag found, using initial commit."
previous_tag=$(git rev-list --max-parents=0 HEAD)
fi
echo "Previous tag: $previous_tag"
echo "PREVIOUS_TAG=$previous_tag" >> $GITHUB_ENV
shell: bash
- name: Check if version changed
id: check_version
run: |
# Check if the version already exists as a tag
if git rev-parse "refs/tags/${{ env.VERSION }}" >/dev/null 2>&1; then
echo "skip_release=true" >> $GITHUB_OUTPUT
echo "Version ${{ env.VERSION }} already exists as a tag. No release will be created."
exit 0
fi
# Compare current version with previous tag
if [ "${{ env.VERSION }}" == "${{ env.PREVIOUS_TAG }}" ]; then
echo "skip_release=true" >> $GITHUB_OUTPUT
echo "Version has not changed. No release will be created."
exit 0
fi
echo "skip_release=false" >> $GITHUB_OUTPUT
shell: bash
- name: Generate release notes
id: generate_notes
if: steps.check_version.outputs.skip_release == 'false'
run: |
echo "Generating release notes from ${{ env.PREVIOUS_TAG }} to HEAD..."
repo_url=$(git config --get remote.origin.url)
notes=$(git log ${{ env.PREVIOUS_TAG }}..HEAD --pretty=format:"- [\`%h\`]($repo_url/commit/%H): %s%n")
echo "See [CHANGELOG.md](./CHANGELOG.md) for more details."
echo "$notes"
echo ""
echo "### Changes in this release" > release_notes.md
echo "$notes" >> release_notes.md
shell: bash
- name: Set Git user
if: steps.check_version.outputs.skip_release == 'false'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
shell: bash
- name: Create and push tag
id: create_tag
if: steps.check_version.outputs.skip_release == 'false'
run: |
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
- name: Set Release Prerelease Flag
id: set_prerelease_flag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "PRE_RELEASE=false" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == refs/heads/dev/* ]]; then
echo "PRE_RELEASE=true" >> $GITHUB_ENV
fi
- name: Release
if: steps.check_version.outputs.skip_release == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }}
name: Release ${{ env.VERSION }}
body_path: release_notes.md
prerelease: ${{ env.PRE_RELEASE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}