Skip to content

doc: 1.3.9(a) 更新文档 #181

doc: 1.3.9(a) 更新文档

doc: 1.3.9(a) 更新文档 #181

Workflow file for this run

name: Publish yume-dsl-rich-text
on:
push:
branches:
- master
workflow_dispatch:
inputs:
version:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
- custom
custom_version:
description: "Custom version (only when type = custom, e.g. 1.2.3)"
required: false
type: string
registry:
description: "Publish target"
required: true
type: choice
options:
- both
- npm
- github
dry_run:
description: "Dry run (skip actual publish)"
required: false
type: boolean
default: false
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
steps:
- name: Resolve publish mode
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "PUBLISH_REGISTRY=none" >> "$GITHUB_ENV"
echo "DRY_RUN=false" >> "$GITHUB_ENV"
echo "SHOULD_BUMP_VERSION=false" >> "$GITHUB_ENV"
else
echo "PUBLISH_REGISTRY=${{ inputs.registry }}" >> "$GITHUB_ENV"
echo "DRY_RUN=${{ inputs.dry_run }}" >> "$GITHUB_ENV"
echo "SHOULD_BUMP_VERSION=true" >> "$GITHUB_ENV"
fi
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node (npm)
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm install
- name: Build & Test
run: npm test
- name: Bump version
if: ${{ env.SHOULD_BUMP_VERSION == 'true' }}
run: |
if [ "${{ inputs.version }}" = "custom" ]; then
if [ -z "${{ inputs.custom_version }}" ]; then
echo "::error::custom_version is required when version type is 'custom'"
exit 1
fi
npm version "${{ inputs.custom_version }}" --no-git-tag-version --allow-same-version
else
npm version "${{ inputs.version }}" --no-git-tag-version --allow-same-version
fi
echo "PKG_VERSION=$(node -p 'require("./package.json").version')" >> "$GITHUB_ENV"
- name: Verify package contents
if: ${{ env.PUBLISH_REGISTRY != 'none' }}
run: |
if [ ! -s README.md ]; then
echo "::error::README.md is missing or empty — push your docs before publishing"
exit 1
fi
npm pack --dry-run 2>&1 | grep -q 'README.md' || {
echo "::error::README.md is not included in the package"
exit 1
}
- name: Publish to npm
if: ${{ env.DRY_RUN != 'true' && (env.PUBLISH_REGISTRY == 'npm' || env.PUBLISH_REGISTRY == 'both') }}
run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Verify npm publish payload (dry run)
if: ${{ env.DRY_RUN == 'true' && (env.PUBLISH_REGISTRY == 'npm' || env.PUBLISH_REGISTRY == 'both') }}
run: npm pack --dry-run
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup Node (GitHub Packages)
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://npm.pkg.github.com
- name: Publish to GitHub Packages
if: ${{ env.DRY_RUN != 'true' && (env.PUBLISH_REGISTRY == 'github' || env.PUBLISH_REGISTRY == 'both') }}
run: |
cp package.json package.json.bak
node -e "
const pkg = require('./package.json');
pkg.name = '@chiba233/yume-dsl-rich-text';
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
npm publish --access public
mv package.json.bak package.json
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify GitHub Packages publish payload (dry run)
if: ${{ env.DRY_RUN == 'true' && (env.PUBLISH_REGISTRY == 'github' || env.PUBLISH_REGISTRY == 'both') }}
run: |
cp package.json package.json.bak
node -e "
const pkg = require('./package.json');
pkg.name = '@chiba233/yume-dsl-rich-text';
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
npm pack --dry-run
mv package.json.bak package.json
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit version bump
if: ${{ env.SHOULD_BUMP_VERSION == 'true' && env.DRY_RUN != 'true' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git diff --cached --quiet && echo "No version change, skipping commit" && exit 0
git commit -m "release: yume-dsl-rich-text v${PKG_VERSION}"
git tag "dsl-v${PKG_VERSION}"
git push
git push --tags