chore: auto-sync plugin list #10
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 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| description: "Package to release" | |
| required: true | |
| type: choice | |
| options: | |
| - cc-plugin-lib | |
| - sdd-webapp | |
| - ops-harbor | |
| version_type: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| # ── Alpha: merge時にaffectedパッケージを自動publish ── | |
| alpha: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: publish-alpha | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.3.11" | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Detect affected publishable packages | |
| id: detect | |
| env: | |
| TURBO_SCM_BASE: HEAD~1 | |
| TURBO_SCM_HEAD: HEAD | |
| run: | | |
| AFFECTED=$(bunx turbo run build --affected --dry=json | node -e " | |
| const data = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')); | |
| const publishable = new Set([ | |
| 'packages/cc-plugin-lib', | |
| 'apps/sdd-webapp', | |
| 'apps/ops-harbor', | |
| ]); | |
| const dirs = [...new Set( | |
| data.tasks.map(t => t.directory).filter(d => publishable.has(d)) | |
| )]; | |
| process.stdout.write(dirs.join(' ')); | |
| ") | |
| echo "Affected publishable: ${AFFECTED:-none}" | |
| echo "changed=$AFFECTED" >> "$GITHUB_OUTPUT" | |
| - name: Publish alpha versions | |
| if: steps.detect.outputs.changed != '' | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| CHANGED_DIRS: ${{ steps.detect.outputs.changed }} | |
| COMMIT_SHA: ${{ github.sha }} | |
| run: | | |
| npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}" | |
| SHORT_SHA="${COMMIT_SHA::7}" | |
| for dir in $CHANGED_DIRS; do | |
| echo "::group::Publishing alpha for $dir" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('${dir}/package.json', 'utf8')); | |
| const [major, minor, patch] = pkg.version.split('.').map(Number); | |
| pkg.version = \`\${major}.\${minor}.\${patch + 1}-alpha.${SHORT_SHA}\`; | |
| fs.writeFileSync('${dir}/package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| console.log(\`\${pkg.name}@\${pkg.version}\`); | |
| " | |
| bunx turbo build --filter="./${dir}" | |
| npm publish -w "./${dir}" --access public --tag alpha | |
| echo "::endgroup::" | |
| done | |
| # ── Release: 手動実行でsemver bump & publish ── | |
| release: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: publish-release | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: "1.3.11" | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Resolve workspace directory | |
| id: workspace | |
| env: | |
| PACKAGE: ${{ inputs.package }} | |
| run: | | |
| case "$PACKAGE" in | |
| cc-plugin-lib) | |
| echo "dir=packages/cc-plugin-lib" >> "$GITHUB_OUTPUT" | |
| ;; | |
| sdd-webapp) | |
| echo "dir=apps/sdd-webapp" >> "$GITHUB_OUTPUT" | |
| ;; | |
| ops-harbor) | |
| echo "dir=apps/ops-harbor" >> "$GITHUB_OUTPUT" | |
| ;; | |
| *) | |
| echo "Unknown publish target: $PACKAGE" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| - name: Bump version | |
| id: version | |
| working-directory: ${{ steps.workspace.outputs.dir }} | |
| env: | |
| VERSION_TYPE: ${{ inputs.version_type }} | |
| run: | | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| const [major, minor, patch] = pkg.version.split('.').map(Number); | |
| const type = process.env.VERSION_TYPE; | |
| if (type === 'major') pkg.version = \`\${major+1}.0.0\`; | |
| else if (type === 'minor') pkg.version = \`\${major}.\${minor+1}.0\`; | |
| else pkg.version = \`\${major}.\${minor}.\${patch+1}\`; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Update lockfile | |
| run: bun install | |
| - name: Build with turbo | |
| env: | |
| WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }} | |
| run: bunx turbo build --filter="./${WORKSPACE_DIR}" | |
| - name: Publish to npm | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }} | |
| run: | | |
| npm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}" | |
| npm publish -w "./${WORKSPACE_DIR}" --access public | |
| - name: Commit and tag | |
| env: | |
| HUSKY: "0" | |
| WORKSPACE_DIR: ${{ steps.workspace.outputs.dir }} | |
| PACKAGE: ${{ inputs.package }} | |
| NEW_VERSION: ${{ steps.version.outputs.new_version }} | |
| run: | | |
| git add "${WORKSPACE_DIR}/package.json" bun.lock | |
| git commit -m "release(@r_masseater/${PACKAGE}): v${NEW_VERSION}" | |
| git tag "@r_masseater/${PACKAGE}@${NEW_VERSION}" | |
| git pull --rebase | |
| git push | |
| git push --tags | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PACKAGE: ${{ inputs.package }} | |
| NEW_VERSION: ${{ steps.version.outputs.new_version }} | |
| run: | | |
| gh release create "@r_masseater/${PACKAGE}@${NEW_VERSION}" \ | |
| --title "@r_masseater/${PACKAGE} v${NEW_VERSION}" \ | |
| --generate-notes |