|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Extract version from tag |
| 22 | + id: version |
| 23 | + run: | |
| 24 | + TAG=${GITHUB_REF#refs/tags/} |
| 25 | + # Remove 'v' prefix if present |
| 26 | + VERSION=${TAG#v} |
| 27 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 28 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 29 | +
|
| 30 | + - name: Extract changelog for version |
| 31 | + id: changelog |
| 32 | + run: | |
| 33 | + VERSION="${{ steps.version.outputs.version }}" |
| 34 | +
|
| 35 | + # Extract changelog section for this version |
| 36 | + CHANGELOG=$(awk -v version="$VERSION" ' |
| 37 | + BEGIN { found=0; capture=0; content="" } |
| 38 | + /^### \[/ { |
| 39 | + if (capture) { exit } |
| 40 | + if ($0 ~ "\\[" version "\\]") { |
| 41 | + found=1 |
| 42 | + capture=1 |
| 43 | + next |
| 44 | + } |
| 45 | + } |
| 46 | + capture && /^### \[/ { exit } |
| 47 | + capture { |
| 48 | + if (content != "") content = content "\n" |
| 49 | + content = content $0 |
| 50 | + } |
| 51 | + END { |
| 52 | + if (found) print content |
| 53 | + else print "Release " version |
| 54 | + } |
| 55 | + ' CHANGELOG.md) |
| 56 | +
|
| 57 | + # Save to file for multiline output |
| 58 | + echo "$CHANGELOG" > /tmp/changelog.txt |
| 59 | +
|
| 60 | + # Set output using file |
| 61 | + { |
| 62 | + echo "content<<EOF" |
| 63 | + cat /tmp/changelog.txt |
| 64 | + echo "EOF" |
| 65 | + } >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Create GitHub Release |
| 68 | + uses: softprops/action-gh-release@v1 |
| 69 | + with: |
| 70 | + name: Release ${{ steps.version.outputs.version }} |
| 71 | + body: ${{ steps.changelog.outputs.content }} |
| 72 | + draft: false |
| 73 | + prerelease: ${{ contains(steps.version.outputs.version, 'alpha') || contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'rc') }} |
| 74 | + generate_release_notes: false |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments