| 1 | name: Release |
| 2 | on: |
| 3 | push: |
| 4 | tags: |
| 5 | - '*' |
| 6 | permissions: |
| 7 | contents: write |
| 8 | jobs: |
| 9 | release: |
| 10 | name: Release On Tag |
| 11 | if: startsWith(github.ref, 'refs/tags/') |
| 12 | runs-on: ubuntu-latest |
| 13 | steps: |
| 14 | - name: Checkout the repository |
| 15 | uses: actions/checkout@v4 |
| 16 | - name: Extract the changelog |
| 17 | id: changelog |
| 18 | run: | |
| 19 | TAG_NAME=${GITHUB_REF/refs\/tags\//} |
| 20 | READ_SECTION=false |
| 21 | CHANGELOG="" |
| 22 | while IFS= read -r line; do |
| 23 | if [[ "$line" =~ ^#+\ +(.*) ]]; then |
| 24 | if [[ "${BASH_REMATCH[1]}" == "$TAG_NAME" ]]; then |
| 25 | READ_SECTION=true |
| 26 | elif [[ "$READ_SECTION" == true ]]; then |
| 27 | break |
| 28 | fi |
| 29 | elif [[ "$READ_SECTION" == true ]]; then |
| 30 | CHANGELOG+="$line"$'\n' |
| 31 | fi |
| 32 | done < "CHANGELOG.md" |
| 33 | CHANGELOG=$(echo "$CHANGELOG" | awk '/./ {$1=$1;print}') |
| 34 | echo "changelog_content<<EOF" >> $GITHUB_OUTPUT |
| 35 | echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 36 | echo "EOF" >> $GITHUB_OUTPUT |
| 37 | - name: Create the release |
| 38 | if: steps.changelog.outputs.changelog_content != '' |
| 39 | uses: softprops/action-gh-release@v1 |
| 40 | with: |
| 41 | name: ${{ github.ref_name }} |
| 42 | body: '${{ steps.changelog.outputs.changelog_content }}' |
| 43 | draft: false |
| 44 | prerelease: false |