Files
obsidian-jekyll-publish/.gitea/workflows/release.yml
2026-06-19 02:22:57 +00:00

109 lines
3.8 KiB
YAML

name: Release
# Manually-dispatched release: build the plugin, tag it, and publish an
# installable Gitea Release with the files Obsidian needs.
on:
workflow_dispatch:
inputs:
tag:
description: "Version to release (e.g. 0.1.0 — no leading v)"
required: true
default: "0.1.0"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Unit tests
run: npm test
- name: Build
run: npm run build
- name: Sync version to tag
env:
TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
VERSION="${TAG#v}"
echo "Releasing version $VERSION (tag $TAG)"
tmp=$(mktemp)
jq --arg v "$VERSION" '.version = $v' manifest.json > "$tmp" && mv "$tmp" manifest.json
tmp=$(mktemp)
jq --arg v "$VERSION" '.version = $v' package.json > "$tmp" && mv "$tmp" package.json
# keep the built folder in sync with the bumped manifest
cp manifest.json dist/manifest.json
if ! git diff --quiet -- manifest.json package.json; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.gitea"
git add manifest.json package.json
git commit -m "chore: release $VERSION"
git push origin "HEAD:${{ github.ref_name }}"
else
echo "Version already $VERSION — no commit needed"
fi
- name: Create and push tag
env:
TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.gitea"
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists on origin"
exit 1
fi
git tag -a "$TAG" -m "Release $TAG"
git push origin "refs/tags/$TAG"
- name: Package artifacts
env:
TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
( cd dist && zip -j "../jekyll-publish-$TAG.zip" main.js manifest.json styles.css )
ls -la dist jekyll-publish-*.zip
- name: Publish Gitea release
env:
TAG: ${{ inputs.tag }}
TOKEN: ${{ github.token }}
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
run: |
set -euo pipefail
body=$(printf 'Install: download main.js, manifest.json and styles.css into `<vault>/.obsidian/plugins/jekyll-publish/`, then enable **Jekyll Publish** under Settings → Community plugins.')
payload=$(jq -n --arg tag "$TAG" --arg name "$TAG" --arg body "$body" \
'{tag_name:$tag, name:$name, body:$body, draft:false, prerelease:false}')
release=$(curl -sf -X POST "$API/releases" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d "$payload")
id=$(echo "$release" | jq -r '.id')
echo "Created release id=$id"
for f in dist/main.js dist/manifest.json dist/styles.css "jekyll-publish-$TAG.zip"; do
name=$(basename "$f")
echo "Uploading $name"
curl -sf -X POST "$API/releases/$id/assets?name=$name" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$f" >/dev/null
done
echo "Release $TAG published with assets"