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
|
name: Publish to npm
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
|
|
@ -35,27 +32,36 @@ jobs:
|
||||||
RAW="${{ github.event.inputs.version || github.ref_name }}"
|
RAW="${{ github.event.inputs.version || github.ref_name }}"
|
||||||
RAW_NO_V="${RAW#v}"
|
RAW_NO_V="${RAW#v}"
|
||||||
TAG="v${RAW_NO_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
|
- name: Sync package version
|
||||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
if: ${{ github.event_name == 'workflow_dispatch' && !github.event.inputs.dry_run }}
|
||||||
echo "ref=${TAG}" >> "$GITHUB_OUTPUT"
|
run: |
|
||||||
elif git rev-parse "${RAW}" >/dev/null 2>&1; then
|
VERSION="${{ steps.version.outputs.raw }}"
|
||||||
echo "tag=${RAW}" >> "$GITHUB_OUTPUT"
|
# Update package.json
|
||||||
echo "ref=${RAW}" >> "$GITHUB_OUTPUT"
|
jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
|
||||||
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
# 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.name "github-actions[bot]"
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git tag "${TAG}"
|
git tag "${TAG}"
|
||||||
git push origin "${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
|
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
|
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6, 2026-04-25
|
||||||
with:
|
with:
|
||||||
|
|
@ -69,8 +75,8 @@ jobs:
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
- name: Type check
|
# - name: Type check
|
||||||
run: bun run typecheck
|
# run: bun run typecheck
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: bun test
|
run: bun test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user