Skip to content

A local-first personal finance app

[AI] automated publishing workflow for crdt package (#7805)

Matiss Janis Aboltins83073b3ee080
diff --git a/.github/workflows/crdt-version-check.yml b/.github/workflows/crdt-version-check.yml
new file mode 100644
index 0000000000..da2da6c68f
--- /dev/null
+++ b/.github/workflows/crdt-version-check.yml
@@ -0,0 +1,48 @@
+name: CRDT version bump check
+
+on:
+ pull_request:
+ paths:
+ - 'packages/crdt/**'
+
+permissions:
+ contents: read
+
+jobs:
+ check-version-bump:
+ runs-on: ubuntu-latest
+ name: Ensure @actual-app/crdt version is bumped
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+
+ - name: Verify version bump
+ env:
+ BASE_REF: ${{ github.base_ref }}
+ run: |
+ set -euo pipefail
+
+ if ! git cat-file -e "origin/${BASE_REF}:packages/crdt/package.json" 2>/dev/null; then
+ echo "packages/crdt/package.json does not exist on the base branch; skipping."
+ exit 0
+ fi
+
+ BASE_VERSION=$(git show "origin/${BASE_REF}:packages/crdt/package.json" | jq -r .version)
+ HEAD_VERSION=$(jq -r .version packages/crdt/package.json)
+ echo "Base version: $BASE_VERSION"
+ echo "Head version: $HEAD_VERSION"
+
+ if [ "$BASE_VERSION" = "$HEAD_VERSION" ]; then
+ echo "::error file=packages/crdt/package.json::Files in packages/crdt/ were modified but the @actual-app/crdt version was not bumped. Please update the \"version\" field in packages/crdt/package.json."
+ exit 1
+ fi
+
+ HIGHEST=$(printf '%s\n%s\n' "$BASE_VERSION" "$HEAD_VERSION" | sort -V | tail -n1)
+ if [ "$HIGHEST" != "$HEAD_VERSION" ]; then
+ echo "::error file=packages/crdt/package.json::The @actual-app/crdt version ($HEAD_VERSION) must be greater than the base version ($BASE_VERSION)."
+ exit 1
+ fi
+
+ echo "Version bumped from $BASE_VERSION to $HEAD_VERSION."
diff --git a/.github/workflows/publish-crdt.yml b/.github/workflows/publish-crdt.yml
new file mode 100644
index 0000000000..09fa9df1b2
--- /dev/null
+++ b/.github/workflows/publish-crdt.yml
@@ -0,0 +1,82 @@
+name: Publish @actual-app/crdt
+
+# Automatically publishes @actual-app/crdt when its package.json version
+# changes on master (typically via a merged PR that bumped the version).
+on:
+ push:
+ branches:
+ - master
+ paths:
+ - 'packages/crdt/package.json'
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: publish-crdt
+ cancel-in-progress: false
+
+jobs:
+ check-version:
+ runs-on: ubuntu-latest
+ name: Check if publish is needed
+ outputs:
+ should-publish: ${{ steps.check.outputs.should-publish }}
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Compare local version against npm registry
+ id: check
+ run: |
+ set -euo pipefail
+
+ LOCAL_VERSION=$(jq -r .version packages/crdt/package.json)
+ echo "Local version: $LOCAL_VERSION"
+
+ PUBLISHED_VERSION=$(npm view @actual-app/crdt version 2>/dev/null || echo "")
+ echo "Published version: ${PUBLISHED_VERSION:-<none>}"
+
+ if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
+ echo "Versions match - nothing to publish."
+ echo "should-publish=false" >> "$GITHUB_OUTPUT"
+ else
+ echo "Version changed - publish required."
+ echo "should-publish=true" >> "$GITHUB_OUTPUT"
+ fi
+
+ publish:
+ needs: check-version
+ if: needs.check-version.outputs.should-publish == 'true'
+ runs-on: ubuntu-latest
+ name: Publish @actual-app/crdt to npm
+ permissions:
+ contents: read
+ id-token: write # Required for npm OIDC provenance
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Set up environment
+ uses: ./.github/actions/setup
+ with:
+ download-translations: 'false'
+
+ - name: Build @actual-app/crdt
+ run: yarn workspace @actual-app/crdt build
+
+ - name: Pack @actual-app/crdt
+ run: yarn workspace @actual-app/crdt pack --filename @actual-app/crdt.tgz
+
+ - name: Setup node and npm registry
+ uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
+ with:
+ node-version: 24
+ check-latest: true
+ registry-url: 'https://registry.npmjs.org'
+
+ - name: Publish to npm
+ run: npm publish packages/crdt/@actual-app/crdt.tgz --access public --provenance
diff --git a/upcoming-release-notes/7805.md b/upcoming-release-notes/7805.md
new file mode 100644
index 0000000000..15c3de22a7
--- /dev/null
+++ b/upcoming-release-notes/7805.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Require an `@actual-app/crdt` version bump when files in `packages/crdt` change, and automatically publish the new version to npm once merged.