Bump .backstage.json version

Signed-off-by: Vincenzo Scamporlino <me@vinzscam.dev>
This commit is contained in:
Vincenzo Scamporlino
2021-11-10 23:51:42 +01:00
parent 085edcfc5f
commit b6b4d4b73f
7 changed files with 121 additions and 8 deletions
+3 -1
View File
@@ -1,7 +1,9 @@
---
'@backstage/cli': patch
'@backstage/cli-common': patch
'@backstage/create-app': patch
---
Add .backstage-version file
`@backstage/create-app` will create a new `.backstage-version` file containing the version of `@backstage/create-app` that has been used for creating the application.
`@backstage/create-app` will create a new `.backstage.json` file containing the version of `@backstage/create-app` used for creating the application.
+5
View File
@@ -3,6 +3,11 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
// Warning: (ae-missing-release-tag) "BACKSTAGE_JSON" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const BACKSTAGE_JSON = '.backstage.json';
// @public
export function findPaths(searchDir: string): Paths;
+1 -1
View File
@@ -20,6 +20,6 @@
* @packageDocumentation
*/
export { findPaths } from './paths';
export { findPaths, BACKSTAGE_JSON } from './paths';
export { isChildPath } from './isChildPath';
export type { Paths, ResolveFunc } from './paths';
+5
View File
@@ -167,3 +167,8 @@ export function findPaths(searchDir: string): Paths {
resolveTargetRoot: (...paths) => resolvePath(getTargetRoot(), ...paths),
};
}
/**
* The name of the backstage's config file
*/
export const BACKSTAGE_JSON = '.backstage.json';
@@ -20,7 +20,7 @@ import { resolve as resolvePath } from 'path';
import { paths } from '../../lib/paths';
import { mapDependencies } from '../../lib/versioning';
import * as runObj from '../../lib/run';
import bump from './bump';
import bump, { bumpBackstageJsonVersion } from './bump';
import { withLogCollector } from '@backstage/test-utils';
// Remove log coloring to simplify log matching
@@ -141,7 +141,7 @@ describe('bump', () => {
'Version bump complete!',
]);
expect(runObj.runPlain).toHaveBeenCalledTimes(3);
expect(runObj.runPlain).toHaveBeenCalledTimes(4);
expect(runObj.runPlain).toHaveBeenCalledWith(
'yarn',
'info',
@@ -245,3 +245,64 @@ describe('bump', () => {
});
});
});
describe('bumpBackstageJsonVersion', () => {
afterEach(() => {
mockFs.restore();
jest.resetAllMocks();
});
it('should bump version in .backstage.json', async () => {
mockFs({
'/.backstage.json': JSON.stringify({ version: '0.0.1' }),
});
paths.targetDir = '/';
const latest = '1.4.1';
jest
.spyOn(paths, 'resolveTargetRoot')
.mockImplementation((...path) => resolvePath('/', ...path));
jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) =>
JSON.stringify({
type: 'inspect',
data: {
name,
'dist-tags': {
latest,
},
},
}),
);
jest.spyOn(runObj, 'run').mockResolvedValue(undefined);
await bumpBackstageJsonVersion();
const json = await fs.readJson('/.backstage.json');
expect(json).toEqual({ version: '1.4.1' });
});
it("should create .backstage.json if doesn't exist", async () => {
mockFs({});
paths.targetDir = '/';
const latest = '1.4.1';
jest
.spyOn(paths, 'resolveTargetRoot')
.mockImplementation((...path) => resolvePath('/', ...path));
jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) =>
JSON.stringify({
type: 'inspect',
data: {
name,
'dist-tags': {
latest,
},
},
}),
);
jest.spyOn(runObj, 'run').mockResolvedValue(undefined);
await bumpBackstageJsonVersion();
const json = await fs.readJson('/.backstage.json');
expect(json).toEqual({ version: '1.4.1' });
});
});
@@ -27,6 +27,7 @@ import {
Lockfile,
} from '../../lib/versioning';
import { includedFilter, forbiddenDuplicatesFilter } from './lint';
import { BACKSTAGE_JSON } from '@backstage/cli-common';
const DEP_TYPES = [
'dependencies',
@@ -182,6 +183,10 @@ export default async () => {
await fs.writeJson(pkgPath, pkgJson, { spaces: 2 });
});
console.log();
await bumpBackstageJsonVersion();
console.log();
console.log(
`Running ${chalk.blue('yarn install')} to install new versions`,
@@ -271,6 +276,41 @@ function createVersionFinder() {
};
}
export async function bumpBackstageJsonVersion() {
const backstageJsonPath = paths.resolveTargetRoot(BACKSTAGE_JSON);
const backstageJson = await fs.readJSON(backstageJsonPath).catch(e => {
if (e.code === 'ENOENT') {
// gracefully continue in case the file doesn't exist
return;
}
throw e;
});
const info = await fetchPackageInfo('@backstage/create-app');
const { latest } = info['dist-tags'];
if (backstageJson?.version === latest) {
return;
}
console.log(
chalk.yellow(
typeof backstageJson === 'undefined'
? 'Creating .backstage.json'
: 'Bumping version in .backstage.json',
),
);
await fs.writeJson(
backstageJsonPath,
{ ...backstageJson, version: latest },
{
spaces: 2,
encoding: 'utf8',
},
);
}
async function workerThreads<T>(
count: number,
items: IterableIterator<T>,
+4 -4
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { BACKSTAGE_JSON } from '@backstage/cli-common';
import chalk from 'chalk';
import fs from 'fs-extra';
import handlebars from 'handlebars';
@@ -126,11 +127,10 @@ export async function templatingTask(
});
}
}
const backstageVersionFileName = '.backstage-version';
await Task.forItem('creating', backstageVersionFileName, () =>
await Task.forItem('creating', BACKSTAGE_JSON, () =>
fs.writeFile(
join(destinationDir, backstageVersionFileName),
`${version}\n`,
join(destinationDir, BACKSTAGE_JSON),
`{\n "version": ${JSON.stringify(version)}\n}\n`,
),
);
}