diff --git a/scripts/push-charts.test.ts b/scripts/push-charts.test.ts index 778e0d6..79d7a84 100644 --- a/scripts/push-charts.test.ts +++ b/scripts/push-charts.test.ts @@ -57,6 +57,12 @@ describe("push-charts", () => { }); describe("getChangedCharts", () => { + test("should return empty if archive folder does not exist", async () => { + fs.access.mockRejectedValue(new Error("not found")); + child_process.execSync.mockReturnValue(Buffer.from("")); + await expect(getChangedChartsArchives(["my-chart"])).resolves.toEqual([]); + }); + test("should return changed chart if only one exists", async () => { fs.readdir.mockResolvedValue([myChartDirentMock]); child_process.execSync.mockReturnValue(Buffer.from("")); diff --git a/scripts/push-charts.ts b/scripts/push-charts.ts index 5df72fe..bf21816 100644 --- a/scripts/push-charts.ts +++ b/scripts/push-charts.ts @@ -15,6 +15,11 @@ export async function main(rawArgs: string[]) { const args = rawArgs.slice(2); const archives = await getChangedChartsArchives(args); + if (archives.length === 0) { + console.log("No charts to push"); + return; + } + console.log("Pushing charts"); for (const archive of archives) { const cmd = `helm push "${archive.path}" "oci://ghcr.io/${process.env.GITHUB_REPOSITORY}"`; @@ -45,6 +50,13 @@ export async function getChangedChartsArchives( } async function getChartArchives(): Promise> { + try { + await fs.access(CR_RELEASE_PACKAGE_PATH); + } catch (e) { + console.log("No chart archives found"); + return {}; + } + const archiveList = await fs.readdir(CR_RELEASE_PACKAGE_PATH, { withFileTypes: true, });