Merge pull request #513 from manojmallick/develop #93
This file contains hidden or 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
| name: Draft Release Notes | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "package.json" | |
| - "CHANGELOG.md" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| draft-release: | |
| name: Draft release notes | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from package.json | |
| id: version | |
| run: | | |
| VERSION=$(grep -m 1 '"version"' package.json | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') | |
| if [ -z "$VERSION" ]; then | |
| echo "ERROR: Could not extract version from package.json" | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| - name: Validate version in CHANGELOG | |
| run: | | |
| CHANGELOG_VERSION=$(grep -m 1 '## \[[0-9]' CHANGELOG.md | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "") | |
| PACKAGE_VERSION="${{ steps.version.outputs.version }}" | |
| if [ -z "$CHANGELOG_VERSION" ]; then | |
| echo "ERROR: No release section found in CHANGELOG.md" | |
| exit 1 | |
| fi | |
| if [ "$CHANGELOG_VERSION" != "$PACKAGE_VERSION" ]; then | |
| echo "ERROR: Version mismatch!" | |
| echo " package.json: $PACKAGE_VERSION" | |
| echo " CHANGELOG.md: $CHANGELOG_VERSION" | |
| exit 1 | |
| fi | |
| echo "✅ Versions match: $PACKAGE_VERSION" | |
| - name: Check if release exists | |
| id: check-release | |
| run: | | |
| if gh release view ${{ steps.version.outputs.tag }} > /dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "⚠️ Release ${{ steps.version.outputs.tag }} already exists" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Extract changelog section | |
| if: steps.check-release.outputs.exists == 'false' | |
| id: changelog | |
| run: | | |
| # Extract from second ## [ (v6.10.1) to third ## [ (v6.10.0) or end of file | |
| awk 'BEGIN{count=0} /^## \[/{count++; if(count>2) exit; if(count==2) {flag=1; next}} flag' CHANGELOG.md > /tmp/changelog.txt | |
| if [ ! -s /tmp/changelog.txt ]; then | |
| echo "ERROR: Could not extract changelog" | |
| exit 1 | |
| fi | |
| echo "notes<<EOF" >> $GITHUB_OUTPUT | |
| cat /tmp/changelog.txt >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create draft release | |
| if: steps.check-release.outputs.exists == 'false' | |
| id: create | |
| run: | | |
| gh release create ${{ steps.version.outputs.tag }} \ | |
| --title "SigMap ${{ steps.version.outputs.version }}" \ | |
| --notes-file /tmp/changelog.txt \ | |
| --draft | |
| echo "✅ Draft release created: ${{ steps.version.outputs.tag }}" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| if: always() | |
| run: | | |
| if [ "${{ steps.check-release.outputs.exists }}" = "true" ]; then | |
| echo "⏭️ Release already exists, skipping creation" | |
| elif [ "${{ steps.create.outcome }}" = "success" ]; then | |
| echo "✅ Release created successfully" | |
| echo "→ https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.tag }}" | |
| else | |
| echo "❌ Failed to create release" | |
| exit 1 | |
| fi |