From 606f2c1f71a851feebbc1adc09f307f7d8939156 Mon Sep 17 00:00:00 2001 From: Hellgren Heikki Date: Fri, 12 Sep 2025 09:19:43 +0300 Subject: [PATCH] chore: use BACKSTAGE_VERSIONS_BASE_URL instead Signed-off-by: Hellgren Heikki --- .changeset/heavy-chicken-find.md | 2 +- .../migrate/commands/versions/bump.test.ts | 17 +++++++---------- .../modules/migrate/commands/versions/bump.ts | 10 +++++----- packages/yarn-plugin/README.md | 2 +- .../src/util/getPackageVersion.test.ts | 12 +++++++----- .../yarn-plugin/src/util/getPackageVersion.ts | 2 +- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.changeset/heavy-chicken-find.md b/.changeset/heavy-chicken-find.md index 96308ed2b8..645984b1bd 100644 --- a/.changeset/heavy-chicken-find.md +++ b/.changeset/heavy-chicken-find.md @@ -6,7 +6,7 @@ Allow using custom manifest location in the yarn plugin and version bump. The Backstage yarn plugin and version bump allows two new environment variables to configure custom manifest location: -- `BACKSTAGE_MANIFEST_BASE_URL`: The base URL for fetching the Backstage version +- `BACKSTAGE_VERSIONS_BASE_URL`: The base URL for fetching the Backstage version manifest. Defaults to `https://versions.backstage.io/v1/releases/VERSION/manifest.json`. Useful for running the plugin in environment without direct access to the internet, for example by using a mirror of the versions API or a proxy. diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.test.ts b/packages/cli/src/modules/migrate/commands/versions/bump.test.ts index bea7a551a1..c045ae26e6 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.test.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.test.ts @@ -1061,18 +1061,19 @@ describe('environment variables', () => { beforeEach(() => { delete process.env.BACKSTAGE_MANIFEST_FILE; - delete process.env.BACKSTAGE_MANIFEST_BASE_URL; + process.env.BACKSTAGE_VERSIONS_BASE_URL = 'https://custom.example.com'; }); afterEach(() => { jest.resetAllMocks(); - delete process.env.BACKSTAGE_MANIFEST_FILE; - delete process.env.BACKSTAGE_MANIFEST_BASE_URL; }); - it('should use custom base URL when BACKSTAGE_MANIFEST_BASE_URL is set', async () => { - process.env.BACKSTAGE_MANIFEST_BASE_URL = 'https://custom.example.com'; + afterAll(() => { + delete process.env.BACKSTAGE_MANIFEST_FILE; + delete process.env.BACKSTAGE_VERSIONS_BASE_URL; + }); + it('should use custom base URL when BACKSTAGE_VERSIONS_BASE_URL is set', async () => { mockDir.setContent({ 'yarn.lock': lockfileMock, 'package.json': JSON.stringify({ @@ -1230,9 +1231,7 @@ describe('environment variables', () => { }); }); - it('should use custom base URL for yarn plugin when BACKSTAGE_MANIFEST_BASE_URL is set with yarn plugin', async () => { - process.env.BACKSTAGE_MANIFEST_BASE_URL = 'https://custom.example.com'; - + it('should use custom base URL for yarn plugin when BACKSTAGE_VERSIONS_BASE_URL is set with yarn plugin', async () => { mockDir.setContent({ '.yarnrc.yml': yarnRcMock, 'yarn.lock': lockfileMock, @@ -1331,8 +1330,6 @@ describe('environment variables', () => { }); it('should handle network errors when using custom base URL', async () => { - process.env.BACKSTAGE_MANIFEST_BASE_URL = 'https://custom.example.com'; - mockDir.setContent({ 'yarn.lock': lockfileMock, 'package.json': JSON.stringify({ diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.ts b/packages/cli/src/modules/migrate/commands/versions/bump.ts index b4c21be58c..6bce65cb10 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.ts @@ -114,11 +114,11 @@ export default async (opts: OptionValues) => { if (opts.release === 'next') { const next = await getManifestByReleaseLine({ releaseLine: 'next', - versionsBaseUrl: env.BACKSTAGE_MANIFEST_BASE_URL, + versionsBaseUrl: env.BACKSTAGE_VERSIONS_BASE_URL, }); const main = await getManifestByReleaseLine({ releaseLine: 'main', - versionsBaseUrl: env.BACKSTAGE_MANIFEST_BASE_URL, + versionsBaseUrl: env.BACKSTAGE_VERSIONS_BASE_URL, }); // Prefer manifest with the latest release version releaseManifest = semver.gt(next.releaseVersion, main.releaseVersion) @@ -127,7 +127,7 @@ export default async (opts: OptionValues) => { } else { releaseManifest = await getManifestByReleaseLine({ releaseLine: opts.release, - versionsBaseUrl: env.BACKSTAGE_MANIFEST_BASE_URL, + versionsBaseUrl: env.BACKSTAGE_VERSIONS_BASE_URL, }); } findTargetVersion = createVersionFinder({ @@ -143,8 +143,8 @@ export default async (opts: OptionValues) => { ); console.log(); - const yarnPluginUrl = env.BACKSTAGE_MANIFEST_BASE_URL - ? `${env.BACKSTAGE_MANIFEST_BASE_URL}/v1/releases/${releaseManifest.releaseVersion}/yarn-plugin` + const yarnPluginUrl = env.BACKSTAGE_VERSIONS_BASE_URL + ? `${env.BACKSTAGE_VERSIONS_BASE_URL}/v1/releases/${releaseManifest.releaseVersion}/yarn-plugin` : `https://versions.backstage.io/v1/releases/${releaseManifest.releaseVersion}/yarn-plugin`; await run('yarn', ['plugin', 'import', yarnPluginUrl]); diff --git a/packages/yarn-plugin/README.md b/packages/yarn-plugin/README.md index fe90cebe7b..3249d4279c 100644 --- a/packages/yarn-plugin/README.md +++ b/packages/yarn-plugin/README.md @@ -29,7 +29,7 @@ backstage.json. The plugin functionality can be configured with environment variables: -- `BACKSTAGE_MANIFEST_BASE_URL` - The base URL for fetching the Backstage version +- `BACKSTAGE_VERSIONS_BASE_URL` - The base URL for fetching the Backstage version manifest. Defaults to `https://versions.backstage.io/v1/releases/VERSION/manifest.json`. Useful for running the plugin in environment without direct access to the internet, for example by using a mirror of the versions API or a proxy. diff --git a/packages/yarn-plugin/src/util/getPackageVersion.test.ts b/packages/yarn-plugin/src/util/getPackageVersion.test.ts index d093a8f3ad..9eca738da1 100644 --- a/packages/yarn-plugin/src/util/getPackageVersion.test.ts +++ b/packages/yarn-plugin/src/util/getPackageVersion.test.ts @@ -43,8 +43,6 @@ describe('getPackageVersion', () => { const mockConfiguration = {} as Configuration; beforeEach(() => { - jest.clearAllMocks(); - mockGetCurrentBackstageVersion.mockReturnValue('1.23.4'); mockStructUtils.stringifyIdent.mockImplementation( (descriptor: any) => @@ -59,6 +57,10 @@ describe('getPackageVersion', () => { })); }); + afterEach(() => { + jest.clearAllMocks(); + }); + describe('successful package resolution', () => { beforeEach(() => { mockHttpUtils.get.mockResolvedValue({ @@ -96,8 +98,8 @@ describe('getPackageVersion', () => { }); it('uses custom versionsBaseUrl from environment when provided', async () => { - const originalEnv = process.env.BACKSTAGE_MANIFEST_BASE_URL; - process.env.BACKSTAGE_MANIFEST_BASE_URL = 'https://custom.example.com'; + const originalEnv = process.env.BACKSTAGE_VERSIONS_BASE_URL; + process.env.BACKSTAGE_VERSIONS_BASE_URL = 'https://custom.example.com'; const descriptor = { scope: '@backstage', @@ -113,7 +115,7 @@ describe('getPackageVersion', () => { fetch: expect.any(Function), }); - process.env.BACKSTAGE_MANIFEST_BASE_URL = originalEnv; + process.env.BACKSTAGE_VERSIONS_BASE_URL = originalEnv; }); it('uses yarn httpUtils for fetching with proper response format', async () => { diff --git a/packages/yarn-plugin/src/util/getPackageVersion.ts b/packages/yarn-plugin/src/util/getPackageVersion.ts index ed1c1ee6d8..9ff7198c30 100644 --- a/packages/yarn-plugin/src/util/getPackageVersion.ts +++ b/packages/yarn-plugin/src/util/getPackageVersion.ts @@ -52,7 +52,7 @@ export const getPackageVersion = async ( ? await xfs.readJsonSync(manifestFile as PortablePath) : await getManifestByVersion({ version: backstageVersion, - versionsBaseUrl: env.BACKSTAGE_MANIFEST_BASE_URL, + versionsBaseUrl: env.BACKSTAGE_VERSIONS_BASE_URL, // We override the fetch function used inside getManifestByVersion with a // custom implementation that calls yarn's built-in `httpUtils` method // instead. This has a couple of benefits: