2020-12-13 08:03:02 +00:00
|
|
|
import { logger } from '../../logger';
|
|
|
|
import { Http } from '../../util/http';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
|
2020-12-13 08:03:02 +00:00
|
|
|
|
|
|
|
const http = new Http('batect-wrapper');
|
|
|
|
|
|
|
|
async function updateArtifact(
|
|
|
|
path: string,
|
|
|
|
fileName: string,
|
|
|
|
version: string
|
|
|
|
): Promise<UpdateArtifactsResult> {
|
|
|
|
const url = `https://github.com/batect/batect/releases/download/${version}/${fileName}`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await http.get(url);
|
|
|
|
const contents = response.body;
|
|
|
|
|
|
|
|
return {
|
|
|
|
file: {
|
|
|
|
name: path,
|
|
|
|
contents,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} catch (err) {
|
|
|
|
const errorDescription: string = err.toString();
|
|
|
|
|
|
|
|
return {
|
|
|
|
artifactError: {
|
|
|
|
lockFile: path,
|
|
|
|
stderr: `HTTP GET ${url} failed: ${errorDescription}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateArtifacts({
|
|
|
|
packageFileName,
|
|
|
|
config,
|
|
|
|
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
|
2021-02-16 11:33:44 +00:00
|
|
|
const version = config.newVersion;
|
2020-12-13 08:03:02 +00:00
|
|
|
|
|
|
|
logger.debug({ version, packageFileName }, 'Updating Batect wrapper scripts');
|
|
|
|
|
|
|
|
return [
|
|
|
|
await updateArtifact(packageFileName, 'batect', version),
|
|
|
|
await updateArtifact(`${packageFileName}.cmd`, 'batect.cmd', version),
|
|
|
|
];
|
|
|
|
}
|