Release Obsidian Plugin #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Obsidian Plugin | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number to release (leave blank to auto-detect from manifest.json)' | |
| required: false | |
| default: '' | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.FINE_GRAINED_TOKEN }} | |
| fetch-depth: 0 # Fetch all history for generating changelog | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18.x" | |
| - name: Install dependencies and build | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Determine release version | |
| id: version | |
| run: | | |
| if [ -n "${{ github.event.inputs.version }}" ]; then | |
| version="${{ github.event.inputs.version }}" | |
| else | |
| version=$(jq -r '.version' manifest.json) | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "Releasing version: $version" | |
| - name: Get previous tag | |
| id: prev_tag | |
| run: | | |
| prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| echo "prev_tag=$prev_tag" >> "$GITHUB_OUTPUT" | |
| echo "Previous tag: $prev_tag" | |
| - name: Generate changelog | |
| id: changelog | |
| env: | |
| GH_TOKEN: ${{ secrets.FINE_GRAINED_TOKEN }} | |
| run: | | |
| version="${{ steps.version.outputs.version }}" | |
| prev_tag="${{ steps.prev_tag.outputs.prev_tag }}" | |
| # Start building the changelog | |
| changelog="## What's Changed\n\n" | |
| # Get commit SHAs since last tag | |
| if [ -n "$prev_tag" ]; then | |
| commit_shas=$(git log $prev_tag..HEAD --pretty=format:"%H" --no-merges) | |
| comparison="$prev_tag...v$version" | |
| else | |
| commit_shas=$(git log --pretty=format:"%H" --no-merges -20) | |
| comparison="v$version" | |
| fi | |
| if [ -z "$commit_shas" ]; then | |
| changelog="${changelog}No changes detected.\n" | |
| else | |
| # Process each commit to get GitHub username | |
| while IFS= read -r sha; do | |
| # Get commit message | |
| message=$(git log --format=%s -n 1 $sha) | |
| # Get GitHub username via API | |
| author=$(gh api repos/${{ github.repository }}/commits/$sha --jq '.author.login // .commit.author.name') | |
| changelog="${changelog}* ${message} by @${author}\n" | |
| done <<< "$commit_shas" | |
| fi | |
| # Add Full Changelog link | |
| changelog="${changelog}\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/$comparison" | |
| # Save to output | |
| echo "changelog<<EOF" >> "$GITHUB_OUTPUT" | |
| echo -e "$changelog" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.FINE_GRAINED_TOKEN }} | |
| run: | | |
| version="${{ steps.version.outputs.version }}" | |
| notes="${{ steps.changelog.outputs.changelog }}" | |
| echo "Creating release for $version" | |
| gh release create "v$version" \ | |
| --repo "${{ github.repository }}" \ | |
| --title "$version" \ | |
| --notes "$notes" \ | |
| main.js manifest.json style.css |