name: Create Release on: push: branches: [main] paths: [CHANGELOG.md] workflow_dispatch: jobs: release: runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 0 - name: Determine version id: version run: | # Extract latest version from CHANGELOG.md VERSION=$(grep -m1 '^## \[' CHANGELOG.md | sed 's/^## \[\(.*\)\].*/\1/') if [ -z "$VERSION" ]; then echo "No version found in CHANGELOG.md" exit 0 fi # Check if tag already exists if git rev-parse "v${VERSION}" >/dev/null 2>&1; then echo "Tag v${VERSION} already exists, skipping" echo "skip=true" >> "$GITHUB_OUTPUT" exit 0 fi echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT" echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - name: Create tag if needed if: steps.version.outputs.skip != 'true' && steps.version.outputs.tag != '' run: | TAG="${{ steps.version.outputs.tag }}" if ! git rev-parse "$TAG" >/dev/null 2>&1; then git tag "$TAG" git push origin "$TAG" fi - name: Extract changelog if: steps.version.outputs.skip != 'true' && steps.version.outputs.version != '' run: | VERSION="${{ steps.version.outputs.version }}" NOTES=$(sed -n "/^## \[${VERSION}\]/,/^## \[/p" CHANGELOG.md | head -n -1) if [ -z "$NOTES" ]; then NOTES="Release v${VERSION}" fi echo "$NOTES" > /tmp/release-notes.md - name: Create GitHub release if: steps.version.outputs.skip != 'true' && steps.version.outputs.version != '' env: GH_TOKEN: ${{ github.token }} run: | TAG="${{ steps.version.outputs.tag }}" gh release create "$TAG" \ --title "$TAG" \ --notes-file /tmp/release-notes.md