Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binary-builder): defer version asset upload #1089

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/commands/binary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { mkdir } from 'node:fs/promises';
import { setFailed } from '@actions/core';
import chalk from 'chalk';
import { getArg, getWorkspace } from '../../util';
import { addHostRule, getBuildList } from '../../utils/builds';
import {
type BuildsResult,
addHostRule,
getBuildList,
} from '../../utils/builds';
import { init } from '../../utils/docker/buildx';
import {
type GitHubOctokit,
downloadAsset,
getOctokit,
hasAsset,
Expand All @@ -15,6 +20,7 @@ import {
} from '../../utils/github';
import log from '../../utils/logger';
import { createChecksum } from '../../utils/sum';
import type { BinaryBuilderConfig } from '../../utils/types';
import { createBuilderImage, getConfig, runBuilder } from './utils';

let toBuild = 99;
Expand Down Expand Up @@ -61,18 +67,6 @@ export async function run(): Promise<void> {
await updateRelease(api, cfg, version, builds.latestStable);
}

if (!(await hasVersionAsset(api, version))) {
if (cfg.dryRun) {
log.warn(
chalk.yellow('[DRY_RUN] Would upload version asset:'),
builds.latestStable ?? version,
);
} else {
log('Uploading version file:', builds.latestStable ?? version);
await uploadVersionAsset(api, cfg, version, builds.latestStable);
}
}

if (await hasAsset(api, cfg, version)) {
if (!(await hasAsset(api, cfg, version, true))) {
log('Creating checksum for existing version:', version);
Expand All @@ -92,6 +86,8 @@ export async function run(): Promise<void> {
log('Uploading release:', version);
await uploadAsset(api, cfg, version, builds.latestStable, true);
}

await uploadVersionAssetIfNeeded(api, version, cfg, builds);
} catch (e) {
failed.push(version);
// eslint-disable-next-line
Expand Down Expand Up @@ -134,6 +130,8 @@ export async function run(): Promise<void> {
await uploadAsset(api, cfg, version, builds.latestStable);
await uploadAsset(api, cfg, version, builds.latestStable, true);
}

await uploadVersionAssetIfNeeded(api, version, cfg, builds);
} catch (e) {
failed.push(version);
// eslint-disable-next-line
Expand All @@ -149,3 +147,22 @@ export async function run(): Promise<void> {
setFailed(error as Error);
}
}

async function uploadVersionAssetIfNeeded(
api: GitHubOctokit,
version: string,
cfg: BinaryBuilderConfig,
builds: BuildsResult,
): Promise<void> {
if (!(await hasVersionAsset(api, version))) {
if (cfg.dryRun) {
log.warn(
chalk.yellow('[DRY_RUN] Would upload version asset:'),
builds.latestStable ?? version,
);
} else {
log('Uploading version file:', builds.latestStable ?? version);
await uploadVersionAsset(api, cfg, version, builds.latestStable);
}
}
}
2 changes: 1 addition & 1 deletion src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { BinaryBuilderConfig } from './types';

export { getOctokit };

type GitHubOctokit = InstanceType<typeof GitHub>;
export type GitHubOctokit = InstanceType<typeof GitHub>;

interface GhAsset {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion test/commands/binary/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('commands/binary/index', () => {
await run();

expect(docker.dockerRun).not.toHaveBeenCalled();
expect(github.uploadVersionAsset).toHaveBeenCalled();
expect(github.uploadVersionAsset).not.toHaveBeenCalled();
});

it('works ruby (dry-run)', async () => {
Expand Down
Loading