Skip to content

Comments

修复构建产物收集逻辑缺陷#134

Merged
WhiteElephant-abc merged 2 commits intomainfrom
opencode/issue132-20260124182714
Jan 24, 2026
Merged

修复构建产物收集逻辑缺陷#134
WhiteElephant-abc merged 2 commits intomainfrom
opencode/issue132-20260124182714

Conversation

@opencode-agent
Copy link
Contributor

问题分析与解决

问题根源

构建工作流 build-with-bazel 在 GitHub Actions 中运行时报错:"No files were found with the provided path: release_artifacts/. No artifacts will be uploaded。"经过分析,发现原脚本的构建产物收集逻辑存在缺陷。

原脚本问题

.github/workflows/build.yml:21-32 中的构建产物收集脚本使用以下逻辑:

for dir in "$BIN_PATH"/*/ ; do
    dir_name=$(basename "$dir")
    zip_file="$dir/${dir_name}.zip"
    if [ -f "$zip_file" ]; then
        cp "$zip_file" release_artifacts/
    fi
done

这个逻辑假设:

  1. Bazel 输出目录 ($BIN_PATH) 下每个子目录都对应一个数据包
  2. 每个数据包的 ZIP 文件命名格式为 目录名.zip

但实际构建输出结构是:

  • bazel-bin/subprojects/stone-disappearance/stone-disappearance.zip
  • bazel-bin/subprojects/auto-lucky-block/auto-lucky-block.zip

原脚本在 $BIN_PATH/subprojects/ 目录下查找 subprojects.zip,显然无法找到正确的构建产物。

解决方案

将构建产物收集逻辑从目录扫描改为使用 find 命令递归查找所有 ZIP 文件:

修改内容 .github/workflows/build.yml:21-32

- name: Prepare artifacts for upload
  run: |
    mkdir -p release_artifacts
    BIN_PATH=$(bazel info bazel-bin)
    find "$BIN_PATH" -name "*.zip" -exec cp {} release_artifacts/ \;

验证测试

  1. 使用 bazel build //subprojects/stone-disappearance 测试构建成功
  2. 验证 find 命令能正确找到构建产物:/home/runner/.cache/bazel/.../bin/subprojects/stone-disappearance/stone-disappearance.zip
  3. 确认修改后的脚本能正确复制所有数据包的 ZIP 文件到 release_artifacts/ 目录

提交记录

已按照项目提交规范创建提交:6bea609 👷 ci: fix build artifact collection

影响范围

  • 修复后,所有数据包的构建产物都能正确收集并上传到 GitHub Actions Artifacts
  • 不影响现有的发布工作流 (release.yml) 和其他 CI/CD 流程
  • 提高构建产物收集的可靠性,避免因目录结构变化导致的问题

Closes #132

New%20session%20-%202026-01-24T18%3A27%3A14.401Z
opencode session  |  github run

Replace directory scanning with find command to locate all zip files in bazel output directory.
Fix build artifact collection logic to only search within subprojects directory, avoiding inclusion of other ZIP files.

The previous find command recursively searched all ZIP files in bazel-bin, which could include unintended artifacts. The new loop specifically targets subprojects/*/ directories and looks for directory-named ZIP files, matching the original workflow's intent.

Addresses review feedback from PR #??.
@opencode-agent
Copy link
Contributor Author

工作总结

根据Pull Request中的review反馈,我已修复构建产物收集逻辑中的缺陷。

问题分析

原PR中的修改使用find "$BIN_PATH" -name "*.zip"递归查找所有ZIP文件,这会包含bazel输出目录中可能存在的其他ZIP文件(如外部依赖等)。根据review意见,应该保持原有的扫描机制,仅调整搜索路径以适应项目结构调整。

解决方案

.github/workflows/build.yml:23-25的构建产物收集逻辑修改为:

mkdir -p release_artifacts
BIN_PATH=$(bazel info bazel-bin)
for dir in "$BIN_PATH/subprojects"/*/ ; do
  dir_name=$(basename "$dir")
  zip_file="$dir/${dir_name}.zip"
  if [ -f "$zip_file" ]; then
    cp "$zip_file" release_artifacts/
  fi
done

关键改进

  1. 精确范围:仅搜索$BIN_PATH/subprojects/目录下的数据包构建产物
  2. 保持原有机制:延续原有的"目录名.zip"命名约定和扫描逻辑
  3. 避免误包含:防止收集到bazel输出目录中的其他ZIP文件

提交记录

已按照项目提交规范创建提交:73b932f 👷 ci: fix artifact collection for subprojects directory

此修改确保构建产物收集仅针对subprojects目录中的数据包,与项目结构调整后的构建输出结构完全匹配。

New%20session%20-%202026-01-24T18%3A49%3A22.639Z
opencode session  |  github run

@WhiteElephant-abc WhiteElephant-abc merged commit dbb1a42 into main Jan 24, 2026
8 checks passed
@WhiteElephant-abc WhiteElephant-abc deleted the opencode/issue132-20260124182714 branch January 24, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build工作流找不到构建产物

1 participant