Merge pull request #486 from spotify/rugvip/cache-version

packages/cli: add cli version to build-cache key
This commit is contained in:
Patrik Oldsberg
2020-04-07 12:07:35 +02:00
committed by GitHub
5 changed files with 47 additions and 10 deletions
+15 -2
View File
@@ -20,6 +20,7 @@ import { runPlain, runCheck } from 'helpers/run';
import { Options } from './options';
import { extractArchive, createArchive } from './archive';
import { paths } from 'helpers/paths';
import { version, isDev } from 'helpers/version';
const INFO_FILE = '.backstage-build-cache';
@@ -74,7 +75,14 @@ export class Cache {
static async readInputKey(
inputPaths: string[],
): Promise<CacheKey | undefined> {
const quotedInputPaths = inputPaths.map(input => `'${input}'`);
const allInputPaths = inputPaths.slice();
// If we're executing the cli inside the backstage repo, we add the cli src as cache key as well
if (isDev) {
allInputPaths.unshift(paths.ownDir);
}
const quotedInputPaths = allInputPaths.map(input => `'${input}'`);
// Make sure we don't have any uncommitted changes to the input, in that case we skip caching.
const noChanges = await runCheck(
@@ -90,7 +98,12 @@ export class Cache {
const [, , sha] = output.split(/\s+/, 3);
trees.push(sha);
}
return trees;
if (isDev) {
return trees;
}
// If we're executing as a dependency, use the version as a key
return [version, ...trees];
}
constructor(
@@ -23,6 +23,7 @@ import { resolve as resolvePath } from 'path';
import os from 'os';
import { Task, templatingTask } from 'helpers/tasks';
import { paths } from 'helpers/paths';
import { version } from 'helpers/version';
const exec = promisify(execCb);
async function checkExists(rootDir: string, name: string) {
@@ -108,7 +109,6 @@ export default async () => {
const templateDir = paths.resolveOwn('templates/default-app');
const tempDir = resolvePath(os.tmpdir(), answers.name);
const appDir = resolvePath(paths.targetDir, answers.name);
const version = require(paths.resolveOwn('package.json')).version;
Task.log();
Task.log('Creating the app...');
@@ -27,6 +27,7 @@ import {
getCodeownersFilePath,
} from './lib/codeowners';
import { paths } from 'helpers/paths';
import { version } from 'helpers/version';
import { Task, templatingTask } from 'helpers/tasks';
const exec = promisify(execCb);
@@ -86,7 +87,7 @@ const addExportStatement = async (
export async function addPluginDependencyToApp(
rootDir: string,
pluginName: string,
version: string,
versionStr: string,
) {
const pluginPackage = `@backstage/plugin-${pluginName}`;
const packageFilePath = 'packages/app/package.json';
@@ -103,7 +104,7 @@ export async function addPluginDependencyToApp(
);
}
dependencies[pluginPackage] = `^${version}`;
dependencies[pluginPackage] = `^${versionStr}`;
packageFileJson.dependencies = sortObjectByKeys(dependencies);
const newContents = `${JSON.stringify(packageFileJson, null, 2)}\n`;
@@ -223,7 +224,6 @@ export default async () => {
const templateDir = paths.resolveOwn('templates/default-plugin');
const tempDir = resolvePath(os.tmpdir(), answers.id);
const pluginDir = paths.resolveTargetRoot('plugins', answers.id);
const version = require(paths.resolveOwn('package.json')).version;
const ownerIds = parseOwnerIds(answers.owner);
Task.log();
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'fs-extra';
import { paths } from './paths';
export function findVersion() {
const pkgContent = fs.readFileSync(paths.resolveOwn('package.json'), 'utf8');
return JSON.parse(pkgContent).version;
}
export const version = findVersion();
export const isDev = fs.pathExistsSync(paths.resolveOwn('src'));
+2 -4
View File
@@ -16,12 +16,10 @@
import program from 'commander';
import chalk from 'chalk';
import { exitWithError } from './helpers/errors';
import { paths } from './helpers/paths';
import { exitWithError } from 'helpers/errors';
import { version } from 'helpers/version';
const main = (argv: string[]) => {
const version = require(paths.resolveOwn('package.json')).version;
program.name('backstage-cli').version(version);
program