Publish to NPM #9
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: Publish to NPM | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: 'Dry run mode (test without publishing)' | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: | | |
| npm ci | |
| npm run prepare | |
| - name: Determine NPM tag | |
| id: npm-tag | |
| run: | | |
| VERSION="${{ github.ref_name }}" | |
| if [[ $VERSION == *"-alpha"* ]]; then | |
| echo "tag=alpha" >> $GITHUB_OUTPUT | |
| echo "π¦ Publishing with tag: alpha" | |
| elif [[ $VERSION == *"-beta"* ]]; then | |
| echo "tag=beta" >> $GITHUB_OUTPUT | |
| echo "π¦ Publishing with tag: beta" | |
| else | |
| echo "tag=" >> $GITHUB_OUTPUT | |
| echo "π¦ Publishing without explicit tag (npm default)" | |
| fi | |
| - name: Verify version matches package.json | |
| run: | | |
| PACKAGE_VERSION=$(npm run version:local --silent) | |
| BRANCH_VERSION="${{ github.ref_name }}" | |
| if [ "$PACKAGE_VERSION" != "$BRANCH_VERSION" ]; then | |
| echo "β Error: Version mismatch!" | |
| echo "Package.json has version $PACKAGE_VERSION but branch name indicates $BRANCH_VERSION" | |
| exit 1 | |
| fi | |
| - name: Check if version already published | |
| run: | | |
| VERSION="${{ github.ref_name }}" | |
| PUBLISHED_VERSION=$(npm run version:published --silent 2>/dev/null || echo "") | |
| if [ "$PUBLISHED_VERSION" == "$VERSION" ]; then | |
| echo "β Error: Version $VERSION is already published on NPM!" | |
| exit 1 | |
| fi | |
| - name: Dry run - Verify package | |
| if: inputs.dry_run == true | |
| run: | | |
| echo "π DRY RUN MODE" | |
| TAG="${{ steps.npm-tag.outputs.tag }}" | |
| if [ -n "$TAG" ]; then | |
| echo "π¦ Tag: $TAG" | |
| npm publish --dry-run --tag "$TAG" | |
| else | |
| echo "π¦ No explicit tag (using npm default)" | |
| npm publish --dry-run | |
| fi | |
| - name: Publish to NPM | |
| if: inputs.dry_run == false | |
| run: | | |
| TAG="${{ steps.npm-tag.outputs.tag }}" | |
| if [ -n "$TAG" ]; then | |
| npm publish --tag "$TAG" | |
| else | |
| npm publish | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create tag | |
| uses: negz/create-tag@v1 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| version: v${{github.ref_name }} | |
| message: New v${{github.ref_name}} tag created! | |
| - name: Verify publication | |
| if: inputs.dry_run == false | |
| run: | | |
| sleep 10 | |
| npm view opentok-react-native@${{ github.ref_name }} version | |
| - name: Summary | |
| if: always() | |
| run: | | |
| echo "## Publish Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Dry Run**: ${{ inputs.dry_run }}" >> $GITHUB_STEP_SUMMARY |