Skip to content

Commit

Permalink
Create createRelease.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenBL authored Dec 9, 2024
1 parent 19191bc commit ecbcc02
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/createRelease.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Create Release

on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., v1.0.0). Leave blank to use the latest version from CHANGELOG.md.'
required: false
pull_request:
types:
- closed

permissions:
contents: write

jobs:
create-release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Determine Version
id: determine_version
run: |
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
echo "Using provided version: $VERSION"
else
if [ -f CHANGELOG.md ]; then
# Extract the latest version heading from CHANGELOG.md
VERSION=$(grep -oP '^## \[\K[^]]+' CHANGELOG.md | head -n 1)
if [ -z "$VERSION" ]; then
echo "No versions found in CHANGELOG.md."
exit 1
fi
echo "Using latest version from CHANGELOG.md: $VERSION"
else
echo "CHANGELOG.md not found. Cannot determine version."
exit 1
fi
fi
# Prepend 'v' if not already present
if [[ "$VERSION" != v* ]]; then
VERSION="v$VERSION"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION_NO_V=${VERSION#v}" >> $GITHUB_ENV
- name: Extract Release Notes from CHANGELOG.md
id: extract_notes
if: ${{ github.event.inputs.version == '' }} # Skip if a version is provided as input
run: |
if [ -f CHANGELOG.md ]; then
NOTES=$(awk '/## \['"${{ env.VERSION_NO_V }}"'\]/{flag=1; next} /## \[/{flag=0} flag' CHANGELOG.md)
if [ -z "$NOTES" ]; then
echo "No release notes found for version ${{ env.VERSION_NO_V }} in CHANGELOG.md."
exit 1
fi
echo "NOTES<<EOF" >> $GITHUB_ENV
echo "$NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "CHANGELOG.md not found in the repository."
exit 1
fi
- name: Default Release Notes
id: default_notes
if: ${{ github.event.inputs.version != '' }} # Use default notes if a version is provided as input
run: |
echo "NOTES<<EOF" >> $GITHUB_ENV
echo "Release notes not provided for version ${{ env.VERSION }}." >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Debug Release Notes
run: |
echo "Extracted Release Notes:"
echo "${{ env.NOTES }}"
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
body: ${{ env.NOTES }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit ecbcc02

Please sign in to comment.