Publish yume-dsl-rich-text #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish yume-dsl-rich-text | |
| on: | |
| 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 | |
| steps: | |
| - 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 | |
| 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 | |
| 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: ${{ !inputs.dry_run && inputs.registry != 'github' }} | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish to npm (dry run) | |
| if: ${{ inputs.dry_run && inputs.registry != 'github' }} | |
| run: npm publish --access public --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: ${{ !inputs.dry_run && inputs.registry != 'npm' }} | |
| 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: Publish to GitHub Packages (dry run) | |
| if: ${{ inputs.dry_run && inputs.registry != 'npm' }} | |
| 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 --dry-run | |
| mv package.json.bak package.json | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Commit version bump | |
| if: ${{ !inputs.dry_run }} | |
| 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 |