Skip to content

Commit 5742ed4

Browse files
masseaterclaude
andcommitted
ci: unify publish workflows into single publish.yml
- Alpha: auto-publish changed packages on merge to master - Release: manual workflow_dispatch with semver bump Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5065e33 commit 5742ed4

2 files changed

Lines changed: 190 additions & 113 deletions

File tree

.github/workflows/publish-package.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
inputs:
9+
package:
10+
description: "Package to release"
11+
required: true
12+
type: choice
13+
options:
14+
- cc-plugin-lib
15+
- sdd-webapp
16+
- ops-harbor
17+
version_type:
18+
description: "Version bump type"
19+
required: true
20+
type: choice
21+
options:
22+
- patch
23+
- minor
24+
- major
25+
26+
concurrency:
27+
group: publish
28+
cancel-in-progress: false
29+
30+
jobs:
31+
# ── Alpha: merge時に変更パッケージを自動publish ──
32+
alpha:
33+
if: github.event_name == 'push'
34+
runs-on: ubuntu-latest
35+
permissions:
36+
contents: read
37+
steps:
38+
- uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 2
41+
42+
- name: Setup Bun
43+
uses: oven-sh/setup-bun@v2
44+
with:
45+
bun-version: "1.3.11"
46+
47+
- name: Install dependencies
48+
run: bun install --frozen-lockfile
49+
50+
- name: Detect changed publishable packages
51+
id: detect
52+
run: |
53+
CHANGED_DIRS=""
54+
for dir in packages/cc-plugin-lib apps/sdd-webapp apps/ops-harbor; do
55+
if git diff --quiet HEAD~1 -- "$dir"; then
56+
echo "No changes in $dir"
57+
else
58+
echo "Changes detected in $dir"
59+
CHANGED_DIRS="${CHANGED_DIRS:+$CHANGED_DIRS }$dir"
60+
fi
61+
done
62+
echo "changed=$CHANGED_DIRS" >> "$GITHUB_OUTPUT"
63+
64+
- name: Publish alpha versions
65+
if: steps.detect.outputs.changed != ''
66+
env:
67+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
68+
CHANGED_DIRS: ${{ steps.detect.outputs.changed }}
69+
COMMIT_SHA: ${{ github.sha }}
70+
run: |
71+
npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}"
72+
SHORT_SHA="${COMMIT_SHA::7}"
73+
74+
for dir in $CHANGED_DIRS; do
75+
echo "::group::Publishing alpha for $dir"
76+
77+
node -e "
78+
const fs = require('fs');
79+
const pkg = JSON.parse(fs.readFileSync('${dir}/package.json', 'utf8'));
80+
const [major, minor, patch] = pkg.version.split('.').map(Number);
81+
pkg.version = \`\${major}.\${minor}.\${patch + 1}-alpha.${SHORT_SHA}\`;
82+
fs.writeFileSync('${dir}/package.json', JSON.stringify(pkg, null, 2) + '\n');
83+
console.log(\`\${pkg.name}@\${pkg.version}\`);
84+
"
85+
86+
bunx turbo build --filter="./${dir}"
87+
npm publish -w "./${dir}" --access public --tag alpha
88+
89+
echo "::endgroup::"
90+
done
91+
92+
# ── Release: 手動実行でsemver bump & publish ──
93+
release:
94+
if: github.event_name == 'workflow_dispatch'
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: write
98+
steps:
99+
- uses: actions/checkout@v6
100+
with:
101+
token: ${{ secrets.GITHUB_TOKEN }}
102+
103+
- name: Setup Bun
104+
uses: oven-sh/setup-bun@v2
105+
with:
106+
bun-version: "1.3.11"
107+
108+
- name: Install dependencies
109+
run: bun install --frozen-lockfile
110+
111+
- name: Configure Git
112+
run: |
113+
git config user.name "github-actions[bot]"
114+
git config user.email "github-actions[bot]@users.noreply.github.com"
115+
116+
- name: Resolve workspace directory
117+
id: workspace
118+
env:
119+
PACKAGE: ${{ inputs.package }}
120+
run: |
121+
case "$PACKAGE" in
122+
cc-plugin-lib)
123+
echo "dir=packages/cc-plugin-lib" >> "$GITHUB_OUTPUT"
124+
;;
125+
sdd-webapp)
126+
echo "dir=apps/sdd-webapp" >> "$GITHUB_OUTPUT"
127+
;;
128+
ops-harbor)
129+
echo "dir=apps/ops-harbor" >> "$GITHUB_OUTPUT"
130+
;;
131+
*)
132+
echo "Unknown publish target: $PACKAGE" >&2
133+
exit 1
134+
;;
135+
esac
136+
137+
- name: Bump version
138+
id: version
139+
working-directory: ${{ steps.workspace.outputs.dir }}
140+
env:
141+
VERSION_TYPE: ${{ inputs.version_type }}
142+
run: |
143+
node -e "
144+
const fs = require('fs');
145+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
146+
const [major, minor, patch] = pkg.version.split('.').map(Number);
147+
const type = process.env.VERSION_TYPE;
148+
if (type === 'major') pkg.version = \`\${major+1}.0.0\`;
149+
else if (type === 'minor') pkg.version = \`\${major}.\${minor+1}.0\`;
150+
else pkg.version = \`\${major}.\${minor}.\${patch+1}\`;
151+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
152+
"
153+
NEW_VERSION=$(node -p "require('./package.json').version")
154+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
155+
156+
- name: Build with turbo
157+
env:
158+
WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }}
159+
run: bunx turbo build --filter="./${WORKSPACE_DIR}"
160+
161+
- name: Publish to npm
162+
env:
163+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
164+
WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }}
165+
run: |
166+
npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}"
167+
npm publish -w "./${WORKSPACE_DIR}" --access public
168+
169+
- name: Commit and tag
170+
env:
171+
HUSKY: "0"
172+
WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }}
173+
PACKAGE: ${{ inputs.package }}
174+
NEW_VERSION: ${{ steps.version.outputs.new_version }}
175+
run: |
176+
git add "${WORKSPACE_DIR}/package.json"
177+
git commit -m "release(@r_masseater/${PACKAGE}): v${NEW_VERSION}"
178+
git tag "@r_masseater/${PACKAGE}@${NEW_VERSION}"
179+
git push
180+
git push --tags
181+
182+
- name: Create GitHub Release
183+
env:
184+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
PACKAGE: ${{ inputs.package }}
186+
NEW_VERSION: ${{ steps.version.outputs.new_version }}
187+
run: |
188+
gh release create "@r_masseater/${PACKAGE}@${NEW_VERSION}" \
189+
--title "@r_masseater/${PACKAGE} v${NEW_VERSION}" \
190+
--generate-notes

0 commit comments

Comments
 (0)