Skip to content

Add publication workflow for npmjs.com#782

Open
jdmarshall wants to merge 2 commits into
prometheus:mainfrom
jdmarshall:release
Open

Add publication workflow for npmjs.com#782
jdmarshall wants to merge 2 commits into
prometheus:mainfrom
jdmarshall:release

Conversation

@jdmarshall

Copy link
Copy Markdown
Contributor

First stab at release workflow.

Comment thread .github/workflows/release.yml Outdated
Signed-off-by: Jason Marshall <jdmarshall@users.noreply.github.com>
@jdmarshall

Copy link
Copy Markdown
Contributor Author

Two things with this. First, that project doesn't yet exist in npmjs.org and I don't have the rights to create it so I'm getting a 404.

Second, the NPM_TOKEN needs to be set in secrets and I don't know if it's there or not.

@jdmarshall
jdmarshall requested a review from zbjornson July 19, 2026 03:53

@krajorama krajorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for starting on this, I think the release should be triggered on tag push. I've let Claude take a look and it pointed out a bunch of stuff. Here's its version:

---
name: Publish to npmjs.com

on:
  push:
    tags:
      - 'v*'

permissions: {}

jobs:
  publish:
    environment: release
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write # required for npm publish --provenance

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
      - name: Use Node.js LTS
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: lts/*
          registry-url: 'https://registry.npmjs.org'

      - name: Verify release secrets
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          if [ -z "${NODE_AUTH_TOKEN}" ]; then
            echo "::error::NPM_TOKEN secret is not set for the 'release' environment."
            exit 1
          fi

      - name: Verify tag matches package.json version
        run: |
          TAG="${GITHUB_REF_NAME#v}"
          PKG_VERSION="$(node -p "require('./package.json').version")"
          if [ "${TAG}" != "${PKG_VERSION}" ]; then
            echo "::error::Tag ${GITHUB_REF_NAME} (${TAG}) does not match package.json version (${PKG_VERSION})."
            exit 1
          fi
          echo "Publishing version ${PKG_VERSION}"

      - name: Determine npm dist-tag
        id: disttag
        run: |
          PKG_VERSION="$(node -p "require('./package.json').version")"
          if [[ "${PKG_VERSION}" == *-* ]]; then
            TAG="$(echo "${PKG_VERSION}" | sed -E 's/^[0-9]+\.[0-9]+\.[0-9]+-([0-9A-Za-z-]+).*/\1/')"
          else
            TAG="latest"
          fi
          echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
          echo "Using dist-tag: ${TAG}"

      - run: npm i
      - run: npm test
      - run: npm publish --provenance --access public --tag "${{ steps.disttag.outputs.tag }}"
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/release.yml
Comment thread .npmrc
Comment thread .npmrc
Comment thread .npmrc Outdated
@krajorama

Copy link
Copy Markdown
Member

@jdmarshall I've lost access to NPM as it enforced 2FA - I've asked in the CNCF slack for the Prometheus team for help with it. I think once we get through these initial pain, we'll be fine!

@krajorama

krajorama commented Jul 20, 2026

Copy link
Copy Markdown
Member

@jdmarshall I've lost access to NPM as it enforced 2FA - I've asked in the CNCF slack for the Prometheus team for help with it. I think once we get through these initial pain, we'll be fine!

@jdmarshall Got the access. However I cannot create the prometheus organization on npmjs as it's taken by a package last published 13 years ago: https://www.npmjs.com/package/prometheus

We're looking into resolving the conflict.

Signed-off-by: Jason Marshall <jdmarshall@users.noreply.github.com>
@jdmarshall

Copy link
Copy Markdown
Contributor Author

They don't allow namespaces and packages to overlap? Odd, since they're handled unambiguously.

@jdmarshall
jdmarshall requested a review from krajorama July 20, 2026 18:47
@krajorama

Copy link
Copy Markdown
Member

They don't allow namespaces and packages to overlap? Odd, since they're handled unambiguously.

Nope, I tried creating the namespace and I got an error. However the author of the conflicting package graciously offered to help, see shubik/prometheus_deprecated#20

@jdmarshall

Copy link
Copy Markdown
Contributor Author

good deal


- run: npm i
- run: npm test
- run: npm publish --provenance --access public --tag alpha

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to remove --tag alpha once v16 is ready to go?

#782 (review) had some fancier tag logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. That seemed to be the simplest solution. Push alphas until we are ready to publish.

Until or unless there's a major upheaval of the code, say for native histograms, there's no need to do anything but trunk-based releases that I can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants