Check obsidian-headless Version #37
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: Check obsidian-headless Version | |
| on: | |
| schedule: | |
| - cron: '0 6 * * *' | |
| workflow_dispatch: | |
| concurrency: | |
| group: check-obsidian-version | |
| cancel-in-progress: false | |
| jobs: | |
| check-version: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| new_version: ${{ steps.compare.outputs.new_version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get latest obsidian-headless npm version | |
| id: npm | |
| run: | | |
| set -euo pipefail | |
| VERSION=$(npm view obsidian-headless version) | |
| if [[ -z "${VERSION}" ]]; then | |
| echo "::error::Could not determine obsidian-headless npm version" | |
| exit 1 | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| - name: Get latest repo tag | |
| id: tag | |
| run: | | |
| LATEST=$(git tag --sort=-version:refname | head -n1) | |
| # Default to 0.0.0 when no tags exist yet | |
| LATEST=${LATEST:-v0.0.0} | |
| # Strip leading 'v' for comparison | |
| echo "version=${LATEST#v}" >> "$GITHUB_OUTPUT" | |
| - name: Compare versions | |
| id: compare | |
| run: | | |
| NPM_VER="${{ steps.npm.outputs.version }}" | |
| TAG_VER="${{ steps.tag.outputs.version }}" | |
| if [[ "${NPM_VER}" == "${TAG_VER}" ]]; then | |
| echo "Already up to date (${NPM_VER}). No build needed." | |
| echo "new_version=" >> "$GITHUB_OUTPUT" | |
| BUILD_STATUS="✅ Already up to date — no build triggered" | |
| else | |
| echo "New version detected: ${NPM_VER} (was ${TAG_VER}) — triggering build" | |
| echo "new_version=${NPM_VER}" >> "$GITHUB_OUTPUT" | |
| BUILD_STATUS="🚀 New version detected — building \`v${NPM_VER}\` (tag pushed after a successful build)" | |
| fi | |
| { | |
| echo "## 🔍 obsidian-headless Version Check" | |
| echo "" | |
| echo "| | |" | |
| echo "|---|---|" | |
| echo "| **npm version** | \`${NPM_VER}\` |" | |
| echo "| **Repo tag** | \`${TAG_VER}\` |" | |
| echo "| **Status** | ${BUILD_STATUS} |" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| build: | |
| needs: check-version | |
| if: needs.check-version.outputs.new_version != '' | |
| uses: ./.github/workflows/docker-publish.yml | |
| with: | |
| version: ${{ needs.check-version.outputs.new_version }} | |
| secrets: inherit | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| # Tag only after a successful build, so a failed build is retried on the | |
| # next scheduled run instead of being skipped forever. | |
| tag: | |
| needs: [check-version, build] | |
| if: needs.check-version.outputs.new_version != '' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Push version tag | |
| run: | | |
| set -euo pipefail | |
| VERSION="${{ needs.check-version.outputs.new_version }}" | |
| if git rev-parse -q --verify "refs/tags/v${VERSION}" >/dev/null; then | |
| echo "Tag v${VERSION} already exists — nothing to do." | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag "v${VERSION}" | |
| git push origin "v${VERSION}" | |
| { | |
| echo "## 🏷️ Tag pushed" | |
| echo "" | |
| echo "\`v${VERSION}\` — image built and published successfully." | |
| } >> "$GITHUB_STEP_SUMMARY" |