Repository navigation
feat(ci): switch to npm trusted publishing with nightly support - #11986
Conversation
User descriptionSummary
Required setupBefore merging:
After verifying a successful publish, the Test plan
PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A["GitHub Events<br/>release/schedule/dispatch"] --> B["Determine Job<br/>Check publish conditions"]
B --> C{{"Should Publish?"}}
C -->|"true"| D["Publish Job<br/>OIDC auth"]
D --> E["npm publish<br/>release or nightly"]
C -->|"false"| F["Skip publish"]
|
| Relevant files | |||
|---|---|---|---|
| Enhancement |
|
PR Code Suggestions ✨Latest suggestions up to 6cbb065
Previous suggestionsSuggestions up to commit e47aae6
Suggestions up to commit b1765d1
Suggestions up to commit 056adae
✅ Suggestions up to commit 00eafbc
✅ Suggestions up to commit 3cbdb96
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code Review by Qodo
1. Nightly version collisions
|
| cd build/package | ||
| CURRENT_VERSION=$(node -p "require('./package.json').version") | ||
| BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-.*//') | ||
| IFS='.' read -r -a V <<< "$BASE_VERSION" | ||
| NIGHTLY_VERSION="${V[0]}.${V[1]}.$((V[2] + 1))-nightly.$(date +'%Y%m%d')" | ||
| npm version "$NIGHTLY_VERSION" --no-git-tag-version |
There was a problem hiding this comment.
1. Nightly version collisions 🐞 Bug ⛯ Reliability
Nightly version is derived from base semver + YYYYMMDD only, so reruns or multiple nightly runs on the same day will compute the same version and cause publish failures due to duplicate versions.
Agent Prompt
### Issue description
Nightly publishing computes a version string that only varies by date (YYYYMMDD). If the workflow is re-run, manually dispatched multiple times, or triggered more than once on the same day, it will attempt to publish the same version again and fail.
### Issue Context
Nightly version is computed in the publish job before `pnpm publish --tag nightly`.
### Fix Focus Areas
- .github/workflows/publish-package.yml[84-93]
### Suggested change
- Keep the existing base-version parsing, but append at least one of:
- `${GITHUB_RUN_NUMBER}`
- short commit SHA (e.g., `${GITHUB_SHA::7}`)
- higher-resolution UTC timestamp (e.g., `date -u +'%Y%m%d%H%M%S'`)
This ensures versions are unique across multiple runs on the same day.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Persistent review updated to latest commit 00eafbc |
|
Persistent review updated to latest commit cbbcc9a |
|
Persistent review updated to latest commit 056adae |
|
Persistent review updated to latest commit b1765d1 |
| publish: | ||
| needs: setup | ||
| runs-on: ubuntu-latest | ||
| environment: npm | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| type: ${{ fromJson(needs.setup.outputs.matrix) }} |
There was a problem hiding this comment.
1. Env/oidc enabled on skip 🐞 Bug ⛨ Security
The publish job always runs in the protected npm environment with id-token: write, even when nightly publishing is skipped due to no new commits. This defeats least privilege and can also cause scheduled runs to block on environment approvals while doing no publish.
Agent Prompt
## Issue description
The workflow always activates the protected npm environment and OIDC permissions even when the run will skip publishing.
## Issue Context
This can introduce unnecessary approval prompts/blocks and violates least-privilege (OIDC token permission granted when not needed).
## Fix Focus Areas
- .github/workflows/publish-package.yml[26-56]
- .github/workflows/publish-package.yml[63-77]
- .github/workflows/publish-package.yml[145-147]
## Suggested direction
- Move the commit/need-to-publish determination into `setup` and output a matrix that excludes entries with no new commits; then `publish` always publishes and never needs a skip path.
- Alternatively, split jobs: `build` (no environment, no id-token) -> `publish` (environment npm, id-token write) with `if:` based on `build` outputs.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Deploying typeorm with
|
| Latest commit: |
e47aae6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5ee33434.typeorm.pages.dev |
| Branch Preview URL: | https://feat-trusted-publishing.typeorm.pages.dev |
|
Persistent review updated to latest commit e47aae6 |
| - name: Set nightly version | ||
| if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'true' | ||
| run: | | ||
| cd build/package | ||
| pnpm publish --provenance --access public | ||
| node -e " | ||
| const pkg = require('./package.json'); | ||
| const base = pkg.version.replace(/-.*/, ''); | ||
| const [major, minor, patch] = base.split('.').map(Number); | ||
| const hasPrerelease = pkg.version.includes('-'); | ||
| pkg.version = major + '.' + minor + '.' + (hasPrerelease ? patch : patch + 1) + '-nightly.' + new Date().toISOString().slice(0,10).replace(/-/g, ''); | ||
| require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | ||
| console.log('Publishing nightly version: ' + pkg.version); | ||
| " | ||
|
|
||
| - name: Publish (release) | ||
| if: matrix.type == 'release' | ||
| run: | | ||
| cd build/package | ||
| pnpm publish --provenance --access public --no-git-checks | ||
|
|
||
| - name: Publish (nightly) | ||
| if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'true' | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| DIST_TAG: ${{ steps.commit_check.outputs.dist_tag }} | ||
| run: | | ||
| cd build/package | ||
| pnpm publish --provenance --access public --no-git-checks --tag "$DIST_TAG" |
There was a problem hiding this comment.
1. Nightly tags undocumented 📘 Rule violation ✓ Correctness
This PR adds new npm nightly dist-tags (master, v0.3) and a nightly publishing workflow, which changes how users can install pre-release builds. No documentation updates are included to describe these new install options.
Agent Prompt
## Issue description
Nightly publishing introduces new user-facing install options (`typeorm@master`, `[email protected]`), but documentation was not updated to reflect how/when to use these dist-tags.
## Issue Context
The workflow now publishes nightlies with `--tag "$DIST_TAG"` and the PR description advertises installation via these tags.
## Fix Focus Areas
- .github/workflows/publish-package.yml[63-143]
- docs/docs/getting-started.md[149-167]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Persistent review updated to latest commit 6cbb065 |
| - name: Publish (release) | ||
| if: matrix.type == 'release' | ||
| run: | | ||
| cd build/package | ||
| pnpm publish --provenance --access public --no-git-checks | ||
|
|
There was a problem hiding this comment.
1. Prerelease tagged as latest 🐞 Bug ✓ Correctness
The release publish step does not set an npm dist-tag, so a master prerelease (e.g. 1.0.0-pre) can be published under the default tag (typically latest) and become the version installed by `npm install typeorm. This conflicts with the repo’s existing prerelease publishing convention (next`) and can unintentionally shift stable users onto v1 prerelease builds.
Agent Prompt
## Issue description
Release publishing currently runs `pnpm publish` without `--tag`, which can push prerelease versions from `master` (e.g. `1.0.0-pre`) under the default npm dist-tag (typically `latest`). This can cause `npm install typeorm` to install v1 prereleases unintentionally.
## Issue Context
The repo already has a gulp task intended to publish with `--tag next`, and docs mention `next` for prereleases, but the workflow does not implement any dist-tag selection for releases.
## Fix Focus Areas
- .github/workflows/publish-package.yml[131-136]
- package.json[1-4]
- gulpfile.ts[84-92]
- DEVELOPER.md[192-200]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
NPM_TOKENsecret with OIDC-based Trusted Publishingmasterandv0.3branches via cron (02:00 UTC daily), with 24h commit check to skip when nothing changedworkflow_dispatchtrigger with choice ofrelease,master-nightly, orv0.3-nightlyscripts,devDependencies,devEngines) from builtpackage.jsonto fix publish lifecycle errorsHow it works
latesttagmaster-nightly+v0.3-nightlyin parallel, skips if no commits in 24hmaster-nightlymaster, publishes astypeorm@masterv0.3-nightlyv0.3, publishes as[email protected]Nightly versioning
masterbranch (1.0.0-pre) →1.0.0-nightly.20260213(replaces prerelease suffix)v0.3branch (0.3.20) →0.3.21-nightly.20260213(bumps patch, adds nightly suffix)Install via:
npm install typeorm@masterornpm install [email protected]Required setup
Before merging:
typeorm/typeormpublish-package.ymlnpmnpmenvironment in repo settings (Settings > Environments)After verifying a successful publish, the
NPM_TOKENsecret can be removed.Test plan
npmGitHub environment1.0.1-nightly.20260213successfullyNPM_TOKENsecret after confirming OIDC worksfeat/trusted-publishingfromnpmenvironment allowed branches