@@ -25,6 +25,7 @@ defaults:
2525
2626permissions :
2727 contents : write
28+ pull-requests : write
2829
2930jobs :
3031 build-prebuilds :
@@ -115,18 +116,68 @@ jobs:
115116 run : npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
116117
117118 - name : Publish to npm
118- run : npm publish --access public --tag ${{ inputs.tag }}
119119 env :
120120 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
121+ PACKAGE_NAME : " @memtensor/memos-local-plugin"
122+ RELEASE_VERSION : ${{ inputs.version }}
123+ NPM_DIST_TAG : ${{ inputs.tag }}
124+ run : |
125+ if npm view "${PACKAGE_NAME}@${RELEASE_VERSION}" version >/dev/null 2>&1; then
126+ echo "${PACKAGE_NAME}@${RELEASE_VERSION} already exists on npm; skipping publish."
127+ else
128+ npm publish --access public --tag "${NPM_DIST_TAG}"
129+ fi
121130
122- - name : Create git tag and push
131+ - name : Create release tag and PR
123132 working-directory : .
133+ env :
134+ GH_TOKEN : ${{ github.token }}
135+ RELEASE_VERSION : ${{ inputs.version }}
136+ DEFAULT_BRANCH : ${{ github.event.repository.default_branch }}
124137 run : |
138+ set -euo pipefail
125139 git config user.name "github-actions[bot]"
126140 git config user.email "github-actions[bot]@users.noreply.github.com"
127- git add apps/memos-local-plugin/package.json
141+
142+ release_tag="memos-local-plugin-v${RELEASE_VERSION}"
143+ release_branch="release/${release_tag}"
144+ release_title="release: @memtensor/memos-local-plugin v${RELEASE_VERSION}"
145+
146+ git add apps/memos-local-plugin/package.json apps/memos-local-plugin/package-lock.json
147+ created_release_commit=false
128148 if ! git diff --staged --quiet; then
129- git commit -m "release: @memtensor/memos-local-plugin v${{ inputs.version }}"
149+ git commit -m "${release_title}"
150+ created_release_commit=true
151+ fi
152+
153+ if [ "${created_release_commit}" = "true" ]; then
154+ remote_branch_sha="$(git ls-remote --heads origin "${release_branch}" | awk '{print $1}')"
155+ if [ -n "${remote_branch_sha}" ]; then
156+ git push --force-with-lease="refs/heads/${release_branch}:${remote_branch_sha}" origin "HEAD:refs/heads/${release_branch}"
157+ else
158+ git push origin "HEAD:refs/heads/${release_branch}"
159+ fi
160+ fi
161+
162+ if git ls-remote --exit-code --tags origin "refs/tags/${release_tag}" >/dev/null 2>&1; then
163+ echo "Tag ${release_tag} already exists on origin; leaving it unchanged."
164+ else
165+ git tag "${release_tag}"
166+ git push origin "refs/tags/${release_tag}"
167+ fi
168+
169+ if [ "${created_release_commit}" = "true" ]; then
170+ if gh pr view "${release_branch}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
171+ echo "Release PR already exists for ${release_branch}."
172+ else
173+ gh pr create \
174+ --repo "${GITHUB_REPOSITORY}" \
175+ --base "${DEFAULT_BRANCH}" \
176+ --head "${release_branch}" \
177+ --title "${release_title}" \
178+ --body "Bumps apps/memos-local-plugin/package.json for the published npm release ${RELEASE_VERSION}." \
179+ || echo "::warning::Failed to create release PR automatically. Open a PR from ${release_branch} to ${DEFAULT_BRANCH}."
180+ fi
181+ else
182+ echo "No version bump changes to open as a PR."
130183 fi
131- git tag "memos-local-plugin-v${{ inputs.version }}"
132- git push origin HEAD --tags
0 commit comments