h-sphere_sql-seal/.github/workflows/publish.yml
2025-01-30 10:36:15 +00:00

70 lines
No EOL
2.1 KiB
YAML

name: Release Obsidian plugin
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Install packages
run: npm install
- name: Build plugin
run: |
npm run build
- name: Extract release notes
id: release-notes
run: |
tag="${GITHUB_REF#refs/tags/}"
# Remove 'v' prefix if present for matching
version="${tag#v}"
awk -v version="$version" '
BEGIN { found=0; content="" }
/^# [0-9]+\.[0-9]+\.[0-9]+/ {
if (found) { exit }
if ($2 ~ "^"version"($| \\()") { found=1; next }
}
found { content = content $0 "\n" }
END { printf "%s", content }
' CHANGELOG.md > release_notes.txt
echo "NOTES<<EOF" >> $GITHUB_OUTPUT
cat release_notes.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release create "$tag" \
--title="$tag" \
--notes="${{ steps.release-notes.outputs.NOTES }}" \
main.js manifest.json styles.css
echo "RELEASE_URL=$(gh release view $tag --json url -q .url)" >> $GITHUB_OUTPUT
- name: Send Discord notification
if: success() && github.event_name != 'pull_request'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
tag="${GITHUB_REF#refs/tags/}"
MESSAGE="🎉 New release $tag is now available!\n\n"
MESSAGE+="📝 Changes:\n"
MESSAGE+="${{ steps.release-notes.outputs.NOTES }}\n"
MESSAGE+="\n🔗 Release: ${{ steps.create-release.outputs.RELEASE_URL }}"
curl -H "Content-Type: application/json" \
-d "{\"content\": \"$MESSAGE\"}" \
$DISCORD_WEBHOOK