release.yml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. name: Release
  2. on:
  3. push:
  4. branches: [main]
  5. paths: [VERSION]
  6. workflow_dispatch:
  7. permissions:
  8. contents: write
  9. jobs:
  10. release:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v4
  14. with:
  15. fetch-depth: 0
  16. - name: Read version
  17. id: version
  18. run: |
  19. version="$(tr -d '[:space:]' < VERSION)"
  20. if [ -z "$version" ]; then
  21. echo "VERSION file is empty" >&2
  22. exit 1
  23. fi
  24. echo "version=$version" >> "$GITHUB_OUTPUT"
  25. echo "tag=v$version" >> "$GITHUB_OUTPUT"
  26. - name: Skip if tag already exists
  27. id: check
  28. env:
  29. TAG: ${{ steps.version.outputs.tag }}
  30. run: |
  31. if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
  32. echo "Tag $TAG already exists; nothing to do."
  33. echo "exists=true" >> "$GITHUB_OUTPUT"
  34. else
  35. echo "exists=false" >> "$GITHUB_OUTPUT"
  36. fi
  37. - name: Extract changelog section
  38. if: steps.check.outputs.exists == 'false'
  39. env:
  40. VERSION: ${{ steps.version.outputs.version }}
  41. run: |
  42. awk -v ver="$VERSION" '
  43. $0 ~ "^## \\[" ver "\\]" { found=1; print; next }
  44. found && /^## \[/ { exit }
  45. found { print }
  46. ' CHANGELOG.md > .release-notes.md
  47. if [ ! -s .release-notes.md ]; then
  48. echo "No changelog entry found for $VERSION" >&2
  49. exit 1
  50. fi
  51. - name: Create tag and GitHub Release
  52. if: steps.check.outputs.exists == 'false'
  53. env:
  54. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  55. TAG: ${{ steps.version.outputs.tag }}
  56. run: |
  57. gh release create "$TAG" \
  58. --target "$GITHUB_SHA" \
  59. --title "$TAG" \
  60. --notes-file .release-notes.md