FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(release): align repository url for npm trust by osnoser1 · Pull Request #58 · limitless-angular/limitless-angular · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (1) .md  (1) .mjs  (5) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion packages/sanity/package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/limitless-angular/limitless-angular.git"
"url": "https://github.com/limitless-angular/limitless-angular"
},
"bugs": {
"url": "https://github.com/limitless-angular/limitless-angular/issues"
Expand Down
4 changes: 3 additions & 1 deletion tools/release/README.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ before publishing.
The npm package must trust the GitHub Actions publisher for
`limitless-angular/limitless-angular`, workflow `release-and-publish.yml`, and
environment `npm-release`; the publish job uses npm trusted publishing instead
of a long-lived npm token.
of a long-lived npm token. The package `repository.url` must exactly match
`https://github.com/limitless-angular/limitless-angular` so npm can match the
OIDC publisher to the package metadata.
13 changes: 12 additions & 1 deletion tools/release/src/pipeline.test.mjs
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,18 @@ function createReleaseFixture() {

writeFileSync(
packageJsonPath,
`${JSON.stringify({ name: '@limitless-angular/sanity', version: '1.0.0' }, null, 2)}\n`,
`${JSON.stringify(
{
name: '@limitless-angular/sanity',
repository: {
type: 'git',
url: 'https://github.com/limitless-angular/limitless-angular',
},
version: '1.0.0',
},
null,
2,
)}\n`,
);
writeFileSync(changelogPath, '## 1.0.0\n');

Expand Down
10 changes: 10 additions & 0 deletions tools/release/src/plan.mjs
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function createReleasePlan(options = {}) {
const commandCapture = options.capture ?? defaultCapture;
const packageJson = readJson(paths.packageJsonPath);
const currentVersion = packageJson.version;
const packageRepositoryUrl = getRepositoryUrl(packageJson.repository);
const latestTag = getLatestTag(currentVersion, {
capture: commandCapture,
releaseTagPrefix: options.releaseTagPrefix ?? releaseTagPrefix,
Expand Down Expand Up @@ -59,6 +60,7 @@ export function createReleasePlan(options = {}) {
nextVersion,
npmDistTag: isPrerelease ? prereleaseNpmDistTag : stableNpmDistTag,
packageName: packageJson.name,
packageRepositoryUrl,
paths,
prerelease: isPrerelease,
releaseTag,
Expand Down Expand Up @@ -106,6 +108,14 @@ function resolveReleasePaths(paths = {}) {
};
}

function getRepositoryUrl(repository) {
if (typeof repository === 'string') {
return repository;
}

return repository?.url;
}

function resolveVersionSpecifier(currentVersion, specifier, options = {}) {
const trimmedSpecifier = specifier.trim();

Expand Down
17 changes: 16 additions & 1 deletion tools/release/src/plan.test.mjs
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ test('release plan infers the next version from conventional commits', () => {
assert.equal(plan.currentVersion, '1.0.0');
assert.equal(plan.nextVersion, '1.1.0');
assert.equal(plan.npmDistTag, 'latest');
assert.equal(
plan.packageRepositoryUrl,
'https://github.com/limitless-angular/limitless-angular',
);
assert.equal(plan.prerelease, false);
assert.equal(plan.releaseTag, 'sanity@1.1.0');
assert.match(plan.changelogSection, /## 1\.1\.0 \(2026-06-08\)/);
Expand Down Expand Up @@ -135,7 +139,18 @@ function createReleaseFixture({ version = '1.0.0' } = {}) {

writeFileSync(
packageJsonPath,
`${JSON.stringify({ name: '@limitless-angular/sanity', version }, null, 2)}\n`,
`${JSON.stringify(
{
name: '@limitless-angular/sanity',
repository: {
type: 'git',
url: 'https://github.com/limitless-angular/limitless-angular',
},
version,
},
null,
2,
)}\n`,
);
writeFileSync(changelogPath, '## 1.0.0\n');

Expand Down
14 changes: 14 additions & 0 deletions tools/release/src/preflight.mjs
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { capture as defaultCapture, run as defaultRun } from './commands.mjs';
import { repoUrl } from './config.mjs';

const defaultReleaseBranch = 'main';
const npmRegistry = 'https://registry.npmjs.org';
Expand All @@ -11,6 +12,7 @@ export function assertPublishPreconditions(plan, options = {}) {

assertGitHubReleaseToken(env);
assertReleaseRef({ capture: commandCapture, env, releaseBranch });
assertTrustedPublishingRepository(plan);
assertCleanWorktree(commandCapture);
syncReleaseBranch(commandRun, releaseBranch);
assertHeadMatchesRemote(commandCapture, releaseBranch);
Expand Down Expand Up @@ -64,6 +66,14 @@ function assertReleaseRef({ capture, env, releaseBranch }) {
}
}

function assertTrustedPublishingRepository(plan) {
if (plan.packageRepositoryUrl !== repoUrl) {
throw new Error(
`Refusing to publish because package repository.url ${formatValue(plan.packageRepositoryUrl)} must exactly match ${repoUrl} for npm trusted publishing.`,
);
}
}

function assertCleanWorktree(capture) {
const status = capture('git', ['status', '--porcelain']).trim();
if (status) {
Expand Down Expand Up @@ -168,6 +178,10 @@ function normalizeNpmVersions(value) {
return value ? [value] : [];
}

function formatValue(value) {
return value ? JSON.stringify(value) : 'is missing';
}

function commandSucceeds(capture, command, args) {
try {
capture(command, args);
Expand Down
21 changes: 21 additions & 0 deletions tools/release/src/preflight.test.mjs
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
const plan = {
nextVersion: '1.1.0',
packageName: '@limitless-angular/sanity',
packageRepositoryUrl:
'https://github.com/limitless-angular/limitless-angular',
releaseTag: 'sanity@1.1.0',
};

Expand Down Expand Up @@ -48,6 +50,25 @@ test('publish preflight rejects dirty worktrees', () => {
);
});

test('publish preflight rejects repository URLs that cannot satisfy npm trust', () => {
assert.throws(
() =>
assertPublishPreconditions(
{
...plan,
packageRepositoryUrl:
'git+https://github.com/limitless-angular/limitless-angular.git',
},
{
capture: createCapture(),
env: { GITHUB_REF: 'refs/heads/main', GITHUB_TOKEN: 'token' },
run: recordRun(),
},
),
/repository\.url .* must exactly match .* npm trusted publishing/,
);
});

test('publish preflight rejects already-published npm versions', () => {
assert.throws(
() =>
Expand Down
Loading

Back | FazBrowse Home | New Git URL