-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (139 loc) · 5.1 KB
/
Copy pathpublish-dsl.yml
File metadata and controls
155 lines (139 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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