SurfSense/.github/workflows/release-obsidian-plugin.yml

117 lines
4.1 KiB
YAML

name: Release Obsidian Plugin
# Tag format: `obsidian-v<version>` and `<version>` must match `surfsense_obsidian/manifest.json` exactly.
on:
push:
tags:
- "obsidian-v*"
workflow_dispatch:
inputs:
publish:
description: "Publish to GitHub Releases"
required: true
type: choice
options:
- never
- always
default: "never"
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
defaults:
run:
working-directory: surfsense_obsidian
steps:
- uses: actions/checkout@v6
with:
# Need write access for the manifest/versions.json mirror commit
# back to main further down.
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v6
with:
node-version: 22.x
cache: npm
cache-dependency-path: surfsense_obsidian/package-lock.json
- name: Resolve plugin version
id: version
run: |
manifest_version=$(node -p "require('./manifest.json').version")
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual runs derive the release version from manifest.json.
version="$manifest_version"
tag="obsidian-v$version"
else
tag="${GITHUB_REF_NAME}"
if [ -z "$tag" ] || [[ "$tag" != obsidian-v* ]]; then
echo "::error::Invalid tag '$tag'. Expected format: obsidian-v<version>"
exit 1
fi
version="${tag#obsidian-v}"
if [ "$version" != "$manifest_version" ]; then
echo "::error::Tag version '$version' does not match manifest version '$manifest_version'"
exit 1
fi
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Resolve publish mode
id: release_mode
run: |
if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.publish }}" = "always" ]; then
echo "should_publish=true" >> "$GITHUB_OUTPUT"
else
echo "should_publish=false" >> "$GITHUB_OUTPUT"
fi
- run: npm ci
- run: npm run lint
- run: npm run build
- name: Verify build artifacts
run: |
for f in main.js manifest.json styles.css; do
test -f "$f" || (echo "::error::Missing release artifact: $f" && exit 1)
done
- name: Mirror manifest.json + versions.json to repo root
if: steps.release_mode.outputs.should_publish == 'true'
working-directory: ${{ github.workspace }}
run: |
cp surfsense_obsidian/manifest.json manifest.json
cp surfsense_obsidian/versions.json versions.json
if git diff --quiet manifest.json versions.json; then
echo "Root manifest/versions already up to date."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add manifest.json versions.json
git commit -m "chore(obsidian-plugin): mirror manifest+versions for ${{ steps.version.outputs.tag }}"
# Push to the default branch so Obsidian can fetch raw files from HEAD.
if ! git push origin HEAD:${{ github.event.repository.default_branch }}; then
echo "::warning::Failed to push mirrored manifest/versions to default branch (likely branch protection). Continuing release."
fi
# Publish release under bare `manifest.json` version (no `obsidian-v` prefix) for BRAT/store compatibility.
- name: Create GitHub release
if: steps.release_mode.outputs.should_publish == 'true'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
name: SurfSense Obsidian Plugin ${{ steps.version.outputs.version }}
generate_release_notes: true
files: |
surfsense_obsidian/main.js
surfsense_obsidian/manifest.json
surfsense_obsidian/styles.css