CLI - Publish to npm and GitHub #5
Workflow file for this run
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: CLI - Publish to npm | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_bump: | |
| description: 'Version bump type' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| dry_run: | |
| description: 'Dry run (do not actually publish)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| jobs: | |
| publish: | |
| name: Publish CLI to npm | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: cli | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version: 20 | |
| - name: Install extension dependencies | |
| run: npm ci | |
| working-directory: . | |
| - name: Install CLI dependencies | |
| run: npm ci | |
| - name: Build production bundle | |
| run: npm run build:production | |
| - name: Validate CLI works | |
| run: node dist/cli.js --help | |
| - name: Bump version | |
| run: npm version ${{ inputs.version_bump }} --no-git-tag-version | |
| - name: Get new version | |
| id: version | |
| run: echo "version=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT" | |
| - name: Publish to npm | |
| if: ${{ !inputs.dry_run }} | |
| uses: npm/publish@v2 | |
| with: | |
| access: public | |
| provenance: true | |
| - name: Dry run publish | |
| if: ${{ inputs.dry_run }} | |
| run: npm publish --access public --dry-run | |
| - name: Commit version bump and create PR | |
| if: ${{ !inputs.dry_run }} | |
| run: | | |
| cd .. | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git checkout -b cli/bump-version-v${{ steps.version.outputs.version }} | |
| git add cli/package.json cli/package-lock.json | |
| git commit -m "chore(cli): bump version to v${{ steps.version.outputs.version }}" | |
| git push origin cli/bump-version-v${{ steps.version.outputs.version }} | |
| gh pr create \ | |
| --title "chore(cli): bump version to v${{ steps.version.outputs.version }}" \ | |
| --body "Automated version bump after publishing \`@rajbos/ai-engineering-fluency@${{ steps.version.outputs.version }}\` to npm." \ | |
| --base main \ | |
| --head cli/bump-version-v${{ steps.version.outputs.version }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| run: | | |
| echo "## CLI Package Published 📦" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- **Version:** v${{ steps.version.outputs.version }}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- **Bump:** ${{ inputs.version_bump }}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- **Dry run:** ${{ inputs.dry_run }}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| if [ "${{ inputs.dry_run }}" = "false" ]; then | |
| echo "Install with: \`npx @rajbos/ai-engineering-fluency\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "A PR has been opened to merge the version bump back to main." >> "$GITHUB_STEP_SUMMARY" | |
| fi |