Tunnelize - publish package to npmjs #26
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: Tunnelize - publish package to npmjs | |
| on: | |
| release: | |
| types: [created] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Optional version override (e.g. 2.3.0 or v2.3.0)." | |
| required: false | |
| type: string | |
| jobs: | |
| publish-npm: | |
| runs-on: ubuntu-latest | |
| environment: VARIABLES | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org/ | |
| always-auth: true | |
| - name: Log in to NPM | |
| run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Install dependencies | |
| working-directory: ./TunnelizeClient | |
| run: npm install | |
| - name: Verify NPM authentication | |
| working-directory: ./TunnelizeClient | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| if [ -z "$NODE_AUTH_TOKEN" ]; then | |
| echo "NPM_TOKEN is not set." | |
| exit 1 | |
| fi | |
| NPM_USER=$(npm whoami) | |
| echo "Authenticated as: $NPM_USER" | |
| npm owner ls tunnelize | |
| if ! npm owner ls tunnelize | grep -q "^$NPM_USER "; then | |
| echo "Authenticated user '$NPM_USER' is not an owner of 'tunnelize'." | |
| exit 1 | |
| fi | |
| - name: Resolve package version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| RAW_VERSION="${{ github.event.release.tag_name }}" | |
| elif [ -n "${{ inputs.version }}" ]; then | |
| RAW_VERSION="${{ inputs.version }}" | |
| else | |
| RAW_VERSION=$(node -p "require('./TunnelizeClient/package.json').version") | |
| fi | |
| VERSION="${RAW_VERSION#v}" | |
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then | |
| echo "Invalid version: $RAW_VERSION" | |
| exit 1 | |
| fi | |
| echo "Using version: $VERSION" | |
| echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV" | |
| - name: Update Package Version | |
| working-directory: ./TunnelizeClient | |
| run: | | |
| npm version "$PACKAGE_VERSION" --no-git-tag-version | |
| echo "Updated package version to $PACKAGE_VERSION" | |
| - name: Publish dry-run | |
| working-directory: ./TunnelizeClient | |
| run: npm publish --access public --dry-run | |
| - name: Publish to NPM | |
| working-directory: ./TunnelizeClient | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: npm publish --access public |