|
| 1 | +name: Create Release from Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Extract version from tag |
| 20 | + id: version |
| 21 | + run: | |
| 22 | + # Remove 'v' prefix from tag to get version number |
| 23 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 24 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 25 | + echo "Releasing version: $VERSION" |
| 26 | + |
| 27 | + - name: Extract changelog for this version |
| 28 | + id: changelog |
| 29 | + run: | |
| 30 | + VERSION="${{ steps.version.outputs.VERSION }}" |
| 31 | + echo "Extracting changelog for version: $VERSION" |
| 32 | + |
| 33 | + # Extract the section between this version header and the next version header |
| 34 | + # The pattern matches ## [VERSION] and extracts everything until the next ## [ |
| 35 | + awk -v ver="$VERSION" ' |
| 36 | + BEGIN { found=0; printing=0 } |
| 37 | + /^## \[/ { |
| 38 | + if (printing) { exit } |
| 39 | + if (index($0, "[" ver "]") > 0) { found=1; printing=1; next } |
| 40 | + } |
| 41 | + printing { print } |
| 42 | + ' CHANGELOG.md > release_notes.md |
| 43 | + |
| 44 | + # Check if we found content |
| 45 | + if [ ! -s release_notes.md ]; then |
| 46 | + echo "No changelog entry found for version $VERSION" |
| 47 | + echo "Using default release notes." |
| 48 | + echo "Release $VERSION" > release_notes.md |
| 49 | + else |
| 50 | + echo "Changelog extracted successfully:" |
| 51 | + cat release_notes.md |
| 52 | + fi |
| 53 | + |
| 54 | + - name: Create GitHub Release |
| 55 | + uses: softprops/action-gh-release@v2 |
| 56 | + with: |
| 57 | + name: "v${{ steps.version.outputs.VERSION }}" |
| 58 | + body_path: release_notes.md |
| 59 | + draft: false |
| 60 | + prerelease: ${{ contains(steps.version.outputs.VERSION, '-') }} |
| 61 | + generate_release_notes: false |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments