-
Notifications
You must be signed in to change notification settings - Fork 459
Add app builds controls to releaser #4105
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
Open
joaquimrocha
wants to merge
3
commits into
kubernetes-sigs:main
Choose a base branch
from
headlamp-k8s:add-app-builds-controls-to-releaser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+521
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import chalk from 'chalk'; | ||
| import inquirer from 'inquirer'; | ||
| import { triggerBuildWorkflows } from '../utils/github.js'; | ||
|
|
||
| interface BuildOptions { | ||
| platform?: string; | ||
| force?: boolean; | ||
| } | ||
|
|
||
| const VALID_PLATFORMS = ['all', 'windows', 'mac', 'linux']; | ||
|
|
||
| export async function buildArtifacts(gitRef: string, options: BuildOptions): Promise<void> { | ||
| const platform = options.platform || 'all'; | ||
|
|
||
| // Validate platform | ||
| if (!VALID_PLATFORMS.includes(platform)) { | ||
| console.error(chalk.red(`Error: Invalid platform "${platform}". Valid options are: ${VALID_PLATFORMS.join(', ')}`)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(chalk.blue(`Triggering build artifacts for platform(s): ${platform}`)); | ||
| console.log(chalk.blue(`Using git ref: ${gitRef}`)); | ||
|
|
||
| try { | ||
| // Confirm unless --force is used | ||
| if (!options.force) { | ||
| const { confirmed } = await inquirer.prompt([ | ||
| { | ||
| type: 'confirm', | ||
| name: 'confirmed', | ||
| message: chalk.yellow(`Are you sure you want to trigger build workflows for ${platform} using ref "${gitRef}"?`), | ||
| default: false | ||
| } | ||
| ]); | ||
|
|
||
| if (!confirmed) { | ||
| console.log(chalk.yellow('Build trigger cancelled')); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Trigger the workflows | ||
| const runs = await triggerBuildWorkflows(gitRef, platform); | ||
|
|
||
| console.log(chalk.green(`\n✅ Successfully triggered build workflow(s) for ${platform}`)); | ||
|
|
||
| if (runs.length > 0) { | ||
| console.log(chalk.blue('\nTriggered workflow runs:')); | ||
| runs.forEach(run => { | ||
| console.log(chalk.cyan(` • ${run.name}: ${run.url}`)); | ||
| }); | ||
| } | ||
|
|
||
| console.log(chalk.blue('\nYou can monitor all workflows at:')); | ||
| console.log(chalk.cyan('https://github.com/kubernetes-sigs/headlamp/actions')); | ||
| } catch (error) { | ||
| console.error(chalk.red('Error triggering build workflows:')); | ||
| console.error(error); | ||
| process.exit(1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import chalk from 'chalk'; | ||
| import { getLatestAppRuns } from '../utils/github.js'; | ||
|
|
||
| interface GetAppRunsOptions { | ||
| latest?: number; | ||
| platform?: string; | ||
| output?: string; | ||
| } | ||
|
|
||
| const VALID_PLATFORMS = ['all', 'windows', 'mac', 'linux']; | ||
| const VALID_OUTPUT_FORMATS = ['simple', 'json']; | ||
|
|
||
| export async function getAppRuns(options: GetAppRunsOptions): Promise<void> { | ||
| const limit = options.latest || 1; | ||
| const platform = options.platform || 'all'; | ||
| const output = options.output; | ||
|
|
||
| // Validate platform | ||
| if (!VALID_PLATFORMS.includes(platform)) { | ||
| console.error(chalk.red(`Error: Invalid platform "${platform}". Valid options are: ${VALID_PLATFORMS.join(', ')}`)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Validate output format | ||
| if (output && !VALID_OUTPUT_FORMATS.includes(output)) { | ||
| console.error(chalk.red(`Error: Invalid output format "${output}". Valid options are: ${VALID_OUTPUT_FORMATS.join(', ')}`)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (output !== 'json') { | ||
| const platformDesc = platform === 'all' ? 'each platform' : platform; | ||
| console.log(chalk.blue(`Fetching latest ${limit} app build run${limit > 1 ? 's' : ''} for ${platformDesc}...\n`)); | ||
| } | ||
|
|
||
| try { | ||
| const runs = await getLatestAppRuns(limit, platform); | ||
|
|
||
| if (runs.length === 0) { | ||
| if (output === 'json') { | ||
| console.log(JSON.stringify([], null, 2)); | ||
| } else { | ||
| console.log(chalk.yellow('No workflow runs found')); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // JSON output | ||
| if (output === 'json') { | ||
| console.log(JSON.stringify(runs, null, 2)); | ||
| return; | ||
| } | ||
|
|
||
| // Simple output - just platform name and run URL | ||
| if (output === 'simple') { | ||
| runs.forEach((workflowRuns) => { | ||
| workflowRuns.runs.forEach((run) => { | ||
| console.log(`${workflowRuns.workflowName}: ${run.url}`); | ||
| }); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Default detailed output | ||
| runs.forEach((workflowRuns, index) => { | ||
| if (index > 0) { | ||
| console.log(''); // Add spacing between workflows | ||
| } | ||
|
|
||
| console.log(chalk.bold.cyan(`${workflowRuns.workflowName}:`)); | ||
| console.log(chalk.dim('─'.repeat(60))); | ||
|
|
||
| workflowRuns.runs.forEach((run, runIndex) => { | ||
| const statusIcon = run.status === 'completed' | ||
| ? (run.conclusion === 'success' ? '✅' : run.conclusion === 'failure' ? '❌' : '⚠️') | ||
| : '🔄'; | ||
|
|
||
| const statusColor = run.status === 'completed' | ||
| ? (run.conclusion === 'success' ? chalk.green : run.conclusion === 'failure' ? chalk.red : chalk.yellow) | ||
| : chalk.blue; | ||
|
|
||
| console.log(`\n${runIndex + 1}. ${statusIcon} ${statusColor(run.status.toUpperCase())}${run.conclusion ? ` (${run.conclusion})` : ''}`); | ||
| console.log(chalk.dim(` Run ID: ${run.id}`)); | ||
| console.log(chalk.dim(` Branch: ${run.headBranch}`)); | ||
| console.log(chalk.dim(` Commit: ${run.headSha.substring(0, 7)}`)); | ||
| console.log(chalk.dim(` Created: ${new Date(run.createdAt).toLocaleString()}`)); | ||
| console.log(chalk.cyan(` URL: ${run.url}`)); | ||
|
|
||
| if (run.artifacts.length > 0) { | ||
| console.log(chalk.green(` Artifacts (${run.artifacts.length}):`)); | ||
| run.artifacts.forEach(artifact => { | ||
| console.log(chalk.dim(` • ${artifact.name} (${formatBytes(artifact.size)})`)); | ||
| console.log(chalk.dim(` Download: ${artifact.downloadUrl}`)); | ||
| }); | ||
| } else if (run.status === 'completed' && run.conclusion === 'success') { | ||
| console.log(chalk.yellow(` No artifacts available`)); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| console.log('\n' + chalk.dim('─'.repeat(60))); | ||
| console.log(chalk.blue('\nView all runs at:')); | ||
| console.log(chalk.cyan('https://github.com/kubernetes-sigs/headlamp/actions')); | ||
| } catch (error) { | ||
| if (output === 'json') { | ||
| console.error(JSON.stringify({ error: String(error) }, null, 2)); | ||
| } else { | ||
| console.error(chalk.red('Error fetching app runs:')); | ||
| console.error(error); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| function formatBytes(bytes: number): string { | ||
| if (bytes === 0) return '0 Bytes'; | ||
| const k = 1024; | ||
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; | ||
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
| return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.