swartzrock_obsidian-setting.../.github/workflows/publish.yml
2026-07-21 15:32:24 -07:00

130 lines
3.5 KiB
YAML

name: Publish Release
on:
workflow_call:
push:
tags:
- "0*"
- "1*"
- "2*"
- "3*"
- "4*"
- "5*"
- "6*"
- "7*"
- "8*"
- "9*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to create, for example 0.1.0. Defaults to manifest version."
required: false
type: string
permissions:
attestations: write
contents: write
id-token: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
publish:
name: Build and publish release
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6.0.3
- name: Set up Bun
uses: oven-sh/setup-bun@v2.2.0
with:
bun-version: 1.3.14
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Typecheck
run: bun run typecheck
- name: Lint
run: bun run lint
- name: Test
run: bun run test
- name: Build
run: bun run build
- name: Prepare release metadata
id: release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_TAG: ${{ github.event.inputs.tag }}
run: |
VERSION="$(node -p "require('./manifest.json').version")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
TAG_NAME="${GITHUB_REF_NAME}"
if [ "${VERSION}" != "${PACKAGE_VERSION}" ]; then
echo "::error::manifest.json version (${VERSION}) must match package.json version (${PACKAGE_VERSION})."
exit 1
fi
if [ "${GITHUB_EVENT_NAME}" != "push" ] || [ "${GITHUB_REF_TYPE}" != "tag" ]; then
TAG_NAME="${INPUT_TAG}"
if [ -z "${TAG_NAME}" ]; then
TAG_NAME="${VERSION}"
fi
fi
if [[ ! "${TAG_NAME}" =~ ^[0-9] ]]; then
echo "::error::Release tag must start with a digit and match manifest.json version (${VERSION})."
exit 1
fi
if [ "${TAG_NAME}" != "${VERSION}" ]; then
echo "::error::Release tag (${TAG_NAME}) must match manifest.json version (${VERSION})."
exit 1
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "tag_name=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
if gh release view "${TAG_NAME}" >/dev/null 2>&1; then
echo "release_exists=true" >> "${GITHUB_OUTPUT}"
else
echo "release_exists=false" >> "${GITHUB_OUTPUT}"
fi
- name: Attest release assets
if: steps.release.outputs.release_exists != 'true'
uses: actions/attest@v4.2.0
with:
subject-path: |
main.js
styles.css
- name: Create GitHub release
if: steps.release.outputs.release_exists != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NOTES_FILE="docs/release-notes/${{ steps.release.outputs.version }}.md"
NOTES_ARGS=()
if [ -f "${NOTES_FILE}" ]; then
NOTES_ARGS=(--notes-file "${NOTES_FILE}")
else
NOTES_ARGS=(--generate-notes)
fi
gh release create "${{ steps.release.outputs.tag_name }}" \
manifest.json \
main.js \
styles.css \
--title "Settings Float ${{ steps.release.outputs.version }}" \
--target "${GITHUB_SHA}" \
"${NOTES_ARGS[@]}"