diff --git a/.github/workflows/CreateReleaseFromChangeLog.yml b/.github/workflows/CreateReleaseFromChangeLog.yml new file mode 100644 index 0000000..3bc3069 --- /dev/null +++ b/.github/workflows/CreateReleaseFromChangeLog.yml @@ -0,0 +1,93 @@ +name: Create Release from Changelog + +on: + workflow_dispatch: + inputs: + dry_run: + description: 'Dry run (do not create tag/release)' + required: false + type: boolean + default: false + +jobs: + create-release-from-changelog: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract version and changelog + id: extract + run: | + # Extract the latest version from CHANGELOG.md + VERSION=$(grep -m 1 -E "^## [0-9]+\.[0-9]+\.[0-9]+" CHANGELOG.md | sed -E 's/^## ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=v$VERSION" >> $GITHUB_OUTPUT + + # Extract changelog content for the latest version + CHANGELOG_CONTENT=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/{if(++count==1){flag=1;next}else{flag=0}}flag' CHANGELOG.md) + + # Save changelog to a temporary file + echo "$CHANGELOG_CONTENT" > /tmp/release_notes.md + + echo "Extracted version: $VERSION" + echo "Release notes:" + cat /tmp/release_notes.md + + - name: Check if tag exists + id: check_tag + run: | + TAG="${{ steps.extract.outputs.tag }}" + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag $TAG already exists" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Tag $TAG does not exist" + fi + + - name: Create and push tag + if: steps.check_tag.outputs.exists == 'false' && inputs.dry_run == false + run: | + TAG="${{ steps.extract.outputs.tag }}" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "$TAG" -m "Release $TAG" + git push origin "$TAG" + echo "Created and pushed tag: $TAG" + + - name: Create GitHub Release + if: steps.check_tag.outputs.exists == 'false' && inputs.dry_run == false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG="${{ steps.extract.outputs.tag }}" + VERSION="${{ steps.extract.outputs.version }}" + + gh release create "$TAG" \ + --title "Release $VERSION" \ + --notes-file /tmp/release_notes.md + + echo "Created GitHub release: $TAG" + + - name: Dry run summary + if: inputs.dry_run == true + run: | + echo "=== DRY RUN MODE ===" + echo "Version: ${{ steps.extract.outputs.version }}" + echo "Tag: ${{ steps.extract.outputs.tag }}" + echo "Tag exists: ${{ steps.check_tag.outputs.exists }}" + echo "" + echo "Release notes:" + cat /tmp/release_notes.md + + - name: Skip (tag already exists) + if: steps.check_tag.outputs.exists == 'true' + run: | + echo "Tag ${{ steps.extract.outputs.tag }} already exists. Skipping release creation." + echo "If you want to recreate the release, please delete the existing tag first."