|
| 1 | +name: Release Obsidian Plugin |
| 2 | + |
| 3 | +# Tag format: `obsidian-v<version>` and `<version>` must match `surfsense_obsidian/manifest.json` exactly. |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "obsidian-v*" |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + publish: |
| 11 | + description: "Publish to GitHub Releases" |
| 12 | + required: true |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - never |
| 16 | + - always |
| 17 | + default: "never" |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-and-release: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + defaults: |
| 26 | + run: |
| 27 | + working-directory: surfsense_obsidian |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v6 |
| 31 | + with: |
| 32 | + # Need write access for the manifest/versions.json mirror commit |
| 33 | + # back to main further down. |
| 34 | + fetch-depth: 0 |
| 35 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - uses: actions/setup-node@v6 |
| 38 | + with: |
| 39 | + node-version: 22.x |
| 40 | + cache: npm |
| 41 | + cache-dependency-path: surfsense_obsidian/package-lock.json |
| 42 | + |
| 43 | + - name: Resolve plugin version |
| 44 | + id: version |
| 45 | + run: | |
| 46 | + manifest_version=$(node -p "require('./manifest.json').version") |
| 47 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 48 | + # Manual runs derive the release version from manifest.json. |
| 49 | + version="$manifest_version" |
| 50 | + tag="obsidian-v$version" |
| 51 | + else |
| 52 | + tag="${GITHUB_REF_NAME}" |
| 53 | + if [ -z "$tag" ] || [[ "$tag" != obsidian-v* ]]; then |
| 54 | + echo "::error::Invalid tag '$tag'. Expected format: obsidian-v<version>" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + version="${tag#obsidian-v}" |
| 58 | + if [ "$version" != "$manifest_version" ]; then |
| 59 | + echo "::error::Tag version '$version' does not match manifest version '$manifest_version'" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + fi |
| 63 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 64 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Resolve publish mode |
| 67 | + id: release_mode |
| 68 | + run: | |
| 69 | + if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.publish }}" = "always" ]; then |
| 70 | + echo "should_publish=true" >> "$GITHUB_OUTPUT" |
| 71 | + else |
| 72 | + echo "should_publish=false" >> "$GITHUB_OUTPUT" |
| 73 | + fi |
| 74 | +
|
| 75 | + - run: npm ci |
| 76 | + |
| 77 | + - run: npm run lint |
| 78 | + |
| 79 | + - run: npm run build |
| 80 | + |
| 81 | + - name: Verify build artifacts |
| 82 | + run: | |
| 83 | + for f in main.js manifest.json styles.css; do |
| 84 | + test -f "$f" || (echo "::error::Missing release artifact: $f" && exit 1) |
| 85 | + done |
| 86 | +
|
| 87 | + - name: Mirror manifest.json + versions.json to repo root |
| 88 | + if: steps.release_mode.outputs.should_publish == 'true' |
| 89 | + working-directory: ${{ github.workspace }} |
| 90 | + run: | |
| 91 | + cp surfsense_obsidian/manifest.json manifest.json |
| 92 | + cp surfsense_obsidian/versions.json versions.json |
| 93 | + if git diff --quiet manifest.json versions.json; then |
| 94 | + echo "Root manifest/versions already up to date." |
| 95 | + exit 0 |
| 96 | + fi |
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | + git add manifest.json versions.json |
| 100 | + git commit -m "chore(obsidian-plugin): mirror manifest+versions for ${{ steps.version.outputs.tag }}" |
| 101 | + # Push to the default branch so Obsidian can fetch raw files from HEAD. |
| 102 | + if ! git push origin HEAD:${{ github.event.repository.default_branch }}; then |
| 103 | + echo "::warning::Failed to push mirrored manifest/versions to default branch (likely branch protection). Continuing release." |
| 104 | + fi |
| 105 | +
|
| 106 | + # Publish release under bare `manifest.json` version (no `obsidian-v` prefix) for BRAT/store compatibility. |
| 107 | + # `make_latest: "false"` keeps the desktop app's `v*` release headlined since Obsidian and BRAT resolve plugins via getReleaseByTag, not the latest flag. |
| 108 | + - name: Create GitHub release |
| 109 | + if: steps.release_mode.outputs.should_publish == 'true' |
| 110 | + uses: softprops/action-gh-release@v3 |
| 111 | + with: |
| 112 | + tag_name: ${{ steps.version.outputs.version }} |
| 113 | + name: SurfSense Obsidian Plugin ${{ steps.version.outputs.version }} |
| 114 | + generate_release_notes: true |
| 115 | + make_latest: "false" |
| 116 | + files: | |
| 117 | + surfsense_obsidian/main.js |
| 118 | + surfsense_obsidian/manifest.json |
| 119 | + surfsense_obsidian/styles.css |
0 commit comments