diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f880d8c..14d592e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,4 +44,63 @@ jobs: - name: Publish to hex.pm env: HEX_API_KEY: ${{ secrets.HEX_API_KEY }} - run: mix hex.publish --yes \ No newline at end of file + run: mix hex.publish --yes + create-release: + name: Create GitHub Release + runs-on: ubuntu-latest + needs: publish + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate changelog + env: + REF_NAME: ${{ github.ref_name }} + run: | + # Get the previous tag + PREV_TAG=$(git describe --abbrev=0 --tags "$(git rev-list --tags --skip=1 --max-count=1)" 2>/dev/null || echo "") + + if [ -z "$PREV_TAG" ]; then + RANGE="$REF_NAME" + else + RANGE="$PREV_TAG..$REF_NAME" + fi + + # Extract the CHANGELOG.md section for this version (Keep-a-Changelog), + # falling back to commit subjects if the section is missing. + VERSION="${REF_NAME#v}" + if awk -v v="## [$VERSION]" 'found && /^## \[/ {exit} $0 == v {found=1; next} found' CHANGELOG.md > changelog-section.md && [ -s changelog-section.md ]; then + cp changelog-section.md release-notes.md + else + git log --pretty=format:"- %s (%h)" "$RANGE" > release-notes.md + fi + + { + echo "## Changes" + echo + git log --pretty=format:"- %s (%h)" "$RANGE" + echo + echo + echo "## Installation" + echo + echo '```elixir' + echo "{:ueberauth_authify, \"~> ${VERSION}\"}" + echo '```' + } >> release-notes.md + + echo "----- release-notes.md -----" + cat release-notes.md + + - name: Create Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REF_NAME: ${{ github.ref_name }} + run: | + gh release create "$REF_NAME" \ + --title "Release $REF_NAME" \ + --notes-file release-notes.md