Skip to content

Instantly share code, notes, and snippets.

@makenowjust
Last active July 5, 2024 01:38
Show Gist options
  • Save makenowjust/9ce50dbb914afe07acd95b6d3cfe6bd8 to your computer and use it in GitHub Desktop.
Save makenowjust/9ce50dbb914afe07acd95b6d3cfe6bd8 to your computer and use it in GitHub Desktop.
import { Octokit } from 'octokit';
const { rest: github } = new Octokit();
const OWNER = 'makenowjust-labs';
const REPO = 'recheck';
const BRANCH = 'main';
const STATUS = 'success';
const WORKFLOW_ID = 'main.yml';
const PER_PAGE = 100;
const TOP_N = 10;
const runs = await github.actions.listWorkflowRuns({
owner: OWNER,
repo: REPO,
workflow_id: WORKFLOW_ID,
branch: BRANCH,
status: STATUS,
per_page: 100,
});
const show = (run) => {
const url = `https://github.com/${OWNER}/${REPO}/commit/${run.head_commit.tree_id}`;
return `[\`${run.head_commit.tree_id.substring(0, 7)}\`](${url}) (${run.created_at})`;
};
const data = [];
for (const [index, run] of runs.data.workflow_runs.entries()) {
const time = (Date.parse(run.updated_at) - Date.parse(run.run_started_at)) / 1000 / 60;
data.push({ index, run, time });
}
data.reverse();
console.log(`# 直近 ${PER_PAGE} 件のCIの実行時間`);
console.log();
console.log(`- **対象リポジトリ**: [${OWNER}/${REPO}](https://github.com/${OWNER}/${REPO})`);
console.log(`- **集計期間**: ${show(data[0].run)} .. ${show(data[data.length - 1].run)}`);
console.log(`- **集計件数**: ${data.length} 件`);
console.log();
console.log('(※<u>成功したCIの実行のみを集計しています。</u>)');
console.log();
console.log('## 実行時間の推移');
console.log();
console.log('```mermaid');
console.log('xychart-beta');
console.log(' title "CIの実行時間の推移"');
console.log(' x-axis "コミット (旧→新)"');
console.log(' y-axis "実行時間 (分)"');
console.log(` line [${data.map(x => x.time.toFixed(3)).join(', ')}]`);
console.log('```');
console.log();
const sorted = Array.from(data).sort((x, y) => y.time - x.time);
console.log('## 統計');
console.log();
const avg = data.reduce((sum, x) => sum + x.time, 0) / data.length;
const med = sorted.length % 2 === 0 ?
(sorted[Math.floor(sorted.length / 2)].time + sorted[Math.ceil(sorted.length / 2)].time) / 2 :
sorted[Math.floor(sorted.length / 2)].time;
console.log(`- **平均値**: ${avg.toFixed(3)} 分`);
console.log(`- **中央値**: ${med.toFixed(3)} 分`);
console.log();
console.log(`### 実行時間がかかったコミット上位 ${TOP_N} 件`);
console.log();
for (const x of sorted.slice(0, TOP_N)) {
console.log(`- ${show(x.run)}: ${x.time.toFixed(3)} 分`);
}

直近 100 件のCIの実行時間

(※成功したCIの実行のみを集計しています。)

実行時間の推移

xychart-beta
  title "CIの実行時間の推移"
  x-axis "コミット (旧→新)"
  y-axis "実行時間 (分)"
  line [10.733, 10.067, 14.233, 12.317, 12.867, 11.517, 13.717, 12.767, 15.200, 14.117, 17.317, 15.567, 13.217, 14.783, 11.883, 11.617, 11.450, 16.300, 11.500, 9.867, 14.683, 11.200, 11.133, 11.417, 9.317, 10.317, 9.300, 9.550, 11.800, 9.767, 10.367, 11.683, 12.700, 12.650, 11.333, 11.233, 9.967, 10.433, 11.550, 11.800, 11.983, 10.750, 9.550, 6.283, 8.217, 6.267, 8.750, 6.633, 6.700, 3.883, 6.600, 6.883, 8.133, 8.217, 7.583, 6.617, 6.917, 6.533, 6.533, 7.033, 7.900, 6.633, 6.500, 2.000, 7.083, 6.933, 7.167, 7.150, 6.783, 6.583, 6.967, 7.583, 8.483, 7.817, 7.750, 7.600, 7.667, 6.883, 6.817, 7.283, 7.283, 7.467, 7.133, 7.583, 6.300, 6.667, 6.767, 6.633, 6.667, 6.967, 6.767, 6.667, 6.467, 6.550, 6.283, 6.900, 6.600, 6.583, 6.900, 6.633]
Loading

統計

  • 平均値: 9.087 分
  • 中央値: 7.750 分

実行時間がかかったコミット上位 10 件

  • af16070 (2023-09-23T13:18:00Z): 17.317 分
  • 52bf43e (2023-09-25T12:33:55Z): 16.300 分
  • 5c45253 (2023-09-23T13:26:58Z): 15.567 分
  • 1fa059f (2023-09-23T13:17:11Z): 15.200 分
  • bf48c1b (2023-09-23T13:27:32Z): 14.783 分
  • 219cf07 (2023-09-26T19:57:10Z): 14.683 分
  • e168890 (2023-09-12T17:30:18Z): 14.233 分
  • 789e2fe (2023-09-23T13:17:27Z): 14.117 分
  • 58ad9f2 (2023-09-14T20:36:15Z): 13.717 分
  • f55976e (2023-09-23T13:27:13Z): 13.217 分
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment