Publish CLI #11
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 CLI | |
| on: | |
| # Trigger after native build completes successfully | |
| workflow_run: | |
| workflows: ["Build Native Modules"] | |
| types: | |
| - completed | |
| # Allow manual trigger | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (e.g., 0.1.0)' | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| name: Publish CLI to npm | |
| runs-on: ubuntu-latest | |
| # Only run if native build succeeded (when triggered by workflow_run) | |
| if: | | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_branch || github.ref }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org/ | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build UI | |
| run: npm run ui:build | |
| - name: Get version | |
| id: version | |
| run: | | |
| if [ "${{ github.event.inputs.version }}" != "" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| elif [ "${{ github.event.workflow_run.head_branch }}" != "" ]; then | |
| # Get version from the tag that triggered native build | |
| BRANCH="${{ github.event.workflow_run.head_branch }}" | |
| if [[ "$BRANCH" == v* ]]; then | |
| VERSION="${BRANCH#v}" | |
| else | |
| VERSION="0.0.0-dev" | |
| fi | |
| elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VERSION="${{ github.ref_name }}" | |
| VERSION="${VERSION#v}" | |
| else | |
| VERSION="0.0.0-dev" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| shell: bash | |
| - name: Update version | |
| run: | | |
| npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version | |
| shell: bash | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |