ci(publish-npm): restrict to manual trigger and auto-sync version
Remove push tag trigger so the workflow only runs on manual dispatch. Add steps to automatically sync package.json and scripts/defines.ts version before publishing, create the git tag, and skip typecheck. Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
This commit is contained in:
parent
de53813db3
commit
a23ebc0303
44
.github/workflows/publish-npm.yml
vendored
44
.github/workflows/publish-npm.yml
vendored
|
|
@ -1,9 +1,6 @@
|
|||
name: Publish to npm
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
|
|
@ -35,27 +32,36 @@ jobs:
|
|||
RAW="${{ github.event.inputs.version || github.ref_name }}"
|
||||
RAW_NO_V="${RAW#v}"
|
||||
TAG="v${RAW_NO_V}"
|
||||
echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
if git rev-parse "${TAG}" >/dev/null 2>&1; then
|
||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "ref=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
elif git rev-parse "${RAW}" >/dev/null 2>&1; then
|
||||
echo "tag=${RAW}" >> "$GITHUB_OUTPUT"
|
||||
echo "ref=${RAW}" >> "$GITHUB_OUTPUT"
|
||||
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
- name: Sync package version
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && !github.event.inputs.dry_run }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.raw }}"
|
||||
# Update package.json
|
||||
jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
|
||||
# Update scripts/defines.ts
|
||||
sed -i "s/\"MACRO.VERSION\": JSON.stringify(\"[^\"]*\")/\"MACRO.VERSION\": JSON.stringify(\"$VERSION\")/" scripts/defines.ts
|
||||
# Commit and push version bump
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add package.json scripts/defines.ts
|
||||
git commit -m "chore(release): bump version to ${VERSION}"
|
||||
git push origin HEAD
|
||||
|
||||
- name: Create tag if missing
|
||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
||||
run: |
|
||||
TAG="${{ steps.version.outputs.tag }}"
|
||||
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag "${TAG}"
|
||||
git push origin "${TAG}"
|
||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "ref=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Error: tag ${TAG} does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- run: git checkout "${{ steps.version.outputs.ref }}"
|
||||
- run: git checkout "${{ steps.version.outputs.tag }}"
|
||||
|
||||
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6, 2026-04-25
|
||||
with:
|
||||
|
|
@ -69,8 +75,8 @@ jobs:
|
|||
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
- name: Type check
|
||||
run: bun run typecheck
|
||||
# - name: Type check
|
||||
# run: bun run typecheck
|
||||
|
||||
- name: Run tests
|
||||
run: bun test
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user