🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(ci): select size baselines from tested lineage (#19052)
Innei546cc8354e70
diff --git a/.github/scripts/find-size-baseline.cjs b/.github/scripts/find-size-baseline.cjsindex db54699101d..c8f02b180bd 100644--- a/.github/scripts/find-size-baseline.cjs+++ b/.github/scripts/find-size-baseline.cjs@@ -1,16 +1,26 @@/**- * Find the most recent successful `canary` push run of a workflow that- * contains a given size-baseline artifact, and return its run id (or '' when- * none exists). Used with actions/download-artifact's `run-id` input:+ * Find the most recent successful `canary` push run whose commit is an ancestor+ * of the code being measured and contains a given size-baseline artifact. Return+ * its run id (or '' when none exists). Used with actions/download-artifact's+ * `run-id` input:** const finder = require('<workspace>/.github/scripts/find-size-baseline.js');- * return await finder({ github, context, workflowId: 'e2e.yml', artifactName: 'bundle-size-baseline-web' });+ * return await finder({ github, context, workflowId: 'e2e.yml', artifactName: 'bundle-size-baseline-web', targetSha: context.sha });** The returned string becomes the step's `result` output (empty string = no* baseline yet, callers should skip the download step and let the gate degrade* to a warning).*/-const findSizeBaseline = async ({ github, context, workflowId, artifactName, artifactPrefix }) => {+const findSizeBaseline = async ({+ github,+ context,+ workflowId,+ artifactName,+ artifactPrefix,+ targetSha,+}) => {+ if (!targetSha) throw new Error('targetSha is required to select a lineage-safe baseline');+const { data } = await github.rest.actions.listWorkflowRuns({branch: 'canary',event: 'push',@@ -22,6 +32,22 @@ const findSizeBaseline = async ({ github, context, workflowId, artifactName, art});for (const run of data.workflow_runs) {+ const { data: comparison } = await github.request(+ 'GET /repos/{owner}/{repo}/compare/{basehead}',+ {+ basehead: `${run.head_sha}...${targetSha}`,+ owner: context.repo.owner,+ repo: context.repo.repo,+ },+ );++ if (comparison.status !== 'ahead' && comparison.status !== 'identical') {+ console.log(+ `Skipping canary run ${run.id} (${run.head_sha}): not an ancestor of ${targetSha} (${comparison.status})`,+ );+ continue;+ }+const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({owner: context.repo.owner,per_page: 100,diff --git a/.github/scripts/find-size-baseline.test.cjs b/.github/scripts/find-size-baseline.test.cjsnew file mode 100644index 00000000000..94350c8f4b3--- /dev/null+++ b/.github/scripts/find-size-baseline.test.cjs@@ -0,0 +1,40 @@+const assert = require('node:assert/strict');+const { test } = require('node:test');++const findSizeBaseline = require('./find-size-baseline.cjs');++test('selects the newest baseline in the target commit lineage', async () => {+ const artifactRunIds = [];+ const github = {+ request: async (_route, { basehead }) => ({+ data: { status: basehead.startsWith('future...') ? 'diverged' : 'ahead' },+ }),+ rest: {+ actions: {+ listWorkflowRunArtifacts: async ({ run_id }) => {+ artifactRunIds.push(run_id);+ return { data: { artifacts: [{ name: 'baseline' }] } };+ },+ listWorkflowRuns: async () => ({+ data: {+ workflow_runs: [+ { created_at: 'later', head_sha: 'future', id: 300 },+ { created_at: 'earlier', head_sha: 'base', id: 200 },+ ],+ },+ }),+ },+ },+ };++ const result = await findSizeBaseline({+ artifactName: 'baseline',+ context: { repo: { owner: 'lobehub', repo: 'lobehub' } },+ github,+ targetSha: 'head',+ workflowId: 'e2e.yml',+ });++ assert.equal(result, '200');+ assert.deepEqual(artifactRunIds, [200]);+});diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.ymlindex 9b77cbb09e4..b21dba81d11 100644--- a/.github/workflows/e2e.yml+++ b/.github/workflows/e2e.yml@@ -94,7 +94,7 @@ jobs:SKIP_LINT: '1'# ===== Bundle size gate (web dist) =====- # Baseline: artifact uploaded by the latest successful canary push run of this workflow.+ # Baseline: artifact from the latest successful canary commit in the tested SHA's lineage.- name: Find latest canary baseline runif: env.SIZE_GATE_ENABLED == 'true'id: baseline_run@@ -104,7 +104,13 @@ jobs:result-encoding: stringscript: |const finder = require('${{ github.workspace }}/.github/scripts/find-size-baseline.cjs');- return await finder({ github, context, workflowId: 'e2e.yml', artifactName: 'bundle-size-baseline-web' });+ return await finder({+ github,+ context,+ workflowId: 'e2e.yml',+ artifactName: 'bundle-size-baseline-web',+ targetSha: context.payload.pull_request?.head.sha ?? context.sha,+ });- name: Download web dist size baselineif: env.SIZE_GATE_ENABLED == 'true' && steps.baseline_run.outputs.result != ''@@ -141,7 +147,13 @@ jobs:result-encoding: stringscript: |const finder = require('${{ github.workspace }}/.github/scripts/find-size-baseline.cjs');- return await finder({ github, context, workflowId: 'e2e.yml', artifactName: 'bundle-size-baseline-entry-graph' });+ return await finder({+ github,+ context,+ workflowId: 'e2e.yml',+ artifactName: 'bundle-size-baseline-entry-graph',+ targetSha: context.payload.pull_request?.head.sha ?? context.sha,+ });- name: Download entry-graph baselineif: env.SIZE_GATE_ENABLED == 'true' && steps.entry_graph_baseline_run.outputs.result != ''diff --git a/.github/workflows/pr-build-desktop.yml b/.github/workflows/pr-build-desktop.ymlindex f0ad9c5fa8d..f05f6050717 100644--- a/.github/workflows/pr-build-desktop.yml+++ b/.github/workflows/pr-build-desktop.yml@@ -251,7 +251,7 @@ jobs:pattern: asar-size-*merge-multiple: true- # 基线:release-desktop-canary 最近一次成功 run 上传的 asar-size-baseline-* artifacts+ # 基线:被测 merge SHA 祖先中最近一次成功的 release-desktop-canary run- name: Find latest canary baseline runid: baseline_runuses: actions/github-script@v8@@ -260,7 +260,13 @@ jobs:result-encoding: stringscript: |const finder = require('${{ github.workspace }}/.github/scripts/find-size-baseline.cjs');- return await finder({ github, context, workflowId: 'release-desktop-canary.yml', artifactPrefix: 'asar-size-baseline-' });+ return await finder({+ github,+ context,+ workflowId: 'release-desktop-canary.yml',+ artifactPrefix: 'asar-size-baseline-',+ targetSha: context.sha,+ });- name: Download ASAR size baselinesif: steps.baseline_run.outputs.result != ''