Publish Package #1
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 Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| npm_tag: | |
| description: "npm dist-tag" | |
| required: true | |
| default: "next" | |
| type: choice | |
| options: | |
| - next | |
| - latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: "22" | |
| registry-url: "https://registry.npmjs.org/" | |
| scope: "@gmx-io" | |
| - name: Upgrade npm for OIDC Trusted Publishing | |
| run: npm install -g npm@latest | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: Get pnpm store directory | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - name: Setup pnpm cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ env.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run tests | |
| run: pnpm test:run | |
| - name: Type check | |
| run: pnpm type-check | |
| - name: Build | |
| run: pnpm build | |
| - name: Test package | |
| run: npm pack --dry-run | |
| - name: Validate npm publish target | |
| run: | | |
| PACKAGE_NAME=$(jq -r .name package.json) | |
| VERSION=$(jq -r .version package.json) | |
| if [ "${{ inputs.npm_tag }}" = "latest" ] && [[ "$VERSION" == *-* ]]; then | |
| echo "Refusing to publish prerelease version $VERSION with latest tag" | |
| exit 1 | |
| fi | |
| if npm view "$PACKAGE_NAME@$VERSION" version > /dev/null 2>&1; then | |
| echo "$PACKAGE_NAME@$VERSION is already published" | |
| exit 1 | |
| fi | |
| - name: Publish to npm | |
| run: npm publish --provenance --access public --tag "${{ inputs.npm_tag }}" | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |