Merge branch 'main' into dependabot/npm_and_yarn/cli/chalk-5.6.2 #38
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 | |
| push: | |
| #branches: | |
| # - main | |
| paths: | |
| - '.github/workflows/cli-publish.yml' | |
| - 'cli/package.json' | |
| - 'cli/package-lock.json' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write # Required for OIDC to npm registry | |
| 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@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| - 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: Check if version is already published | |
| id: check_published | |
| run: | | |
| PACKAGE_NAME=$(node -p 'require("./package.json").name') | |
| VERSION="${{ steps.version.outputs.version }}" | |
| echo "Checking npm registry for ${PACKAGE_NAME}@${VERSION}..." | |
| if npm view "${PACKAGE_NAME}@${VERSION}" version 2>&1; then | |
| echo "Version ${VERSION} is already published to npm. Skipping publish." | |
| echo "already_published=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Version ${VERSION} is not yet published. Proceeding with publish." | |
| echo "already_published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish to npm | |
| if: ${{ !inputs.dry_run && steps.check_published.outputs.already_published != 'true' }} | |
| run: NODE_AUTH_TOKEN="" npm publish | |
| - name: Dry run publish | |
| if: ${{ inputs.dry_run }} | |
| run: NODE_AUTH_TOKEN="" npm publish public --dry-run | |
| - name: Commit version bump and create PR | |
| if: ${{ !inputs.dry_run && steps.check_published.outputs.already_published != 'true' }} | |
| 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: | | |
| { | |
| if [ "${{ steps.check_published.outputs.already_published }}" = "true" ]; then | |
| echo "## CLI Package Publish Skipped ⏭️" | |
| echo "" | |
| echo "Version **v${{ steps.version.outputs.version }}** is already published to npm." | |
| else | |
| echo "## CLI Package Published 📦" | |
| echo "" | |
| echo "- **Version:** v${{ steps.version.outputs.version }}" | |
| echo "- **Bump:** ${{ inputs.version_bump }}" | |
| echo "- **Dry run:** ${{ inputs.dry_run }}" | |
| echo "" | |
| if [ "${{ inputs.dry_run }}" = "false" ]; then | |
| echo "Install with: \`npx @rajbos/ai-engineering-fluency\`" | |
| echo "" | |
| echo "A PR has been opened to merge the version bump back to main." | |
| fi | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" |