Skip to content

[CW-27778] feat: add unit_test_than_build_image reusable workflow#39

Merged
and2352000 merged 2 commits into
masterfrom
feat/CW-27778-unit-test-then-build
May 4, 2026
Merged

[CW-27778] feat: add unit_test_than_build_image reusable workflow#39
and2352000 merged 2 commits into
masterfrom
feat/CW-27778-unit-test-then-build

Conversation

@and2352000

@and2352000 and2352000 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • feat: add unit_test_than_build_image reusable workflow
  • docs: list unit_test_than_build_image in README folder structure

⚠️ Notes for callers

  • DEVOPS_READ_PACKAGE_TOKEN 由 optional 變 required:新檔的 npm ci 直接在 runner 上跑,沒 token 會裝不到 private package。caller 切換前請確認 secret 已設定。
  • Artifact 鏈路相容:新檔仍以 name image / path image.tar 上傳(dev/master 分支),下游 push_and_rotate_image.yml 完全不需修改。
  • 切換方式:caller workflow 把 uses: 路徑換成 CoolBitX-Technology/cp-workflow-template/.github/workflows/unit_test_than_build_image.yml@master 即可;舊 build_and_test_image.yml 保留不動,可同時並存。
  • Node 版本:預設 22.16.0,若 caller 需要其他版本可用 with: { node-version: '<x.y.z>' } 覆寫。

Test Plan

  • GitHub workflow parser 解析新檔無語法錯誤(PR 開出來自動驗證)
  • 在某個 service repo 開測試 branch,把 caller 的 uses: 改成此 PR 的 branch 引用
  • 觀察 unit_test job 先跑、log 看得到 npm test 輸出
  • 故意讓 test 失敗一次,確認 build_image job 不會被觸發
  • Test 通過後 build/save/upload artifact 行為與舊檔一致

Related

PR Summary by Typo

Overview

This PR introduces a new reusable GitHub Actions workflow (unit_test_than_build_image.yml) designed to run unit tests directly on the runner before building a Docker image. This approach aims to provide faster feedback and more efficient CI by failing early if tests don't pass, without altering the existing build_and_test_image.yml workflow.

Key Changes

  • Added a new reusable workflow .github/workflows/unit_test_than_build_image.yml with distinct unit_test and build_image jobs.
  • The unit_test job executes npm ci and npm test directly on the GitHub Actions runner, with the build_image job dependent on its success.
  • The workflow exposes a node-version input and requires DEVOPS_READ_PACKAGE_TOKEN for dependency installation.
  • The README.md has been updated to include the new workflow, and a detailed plan document has been added.

Work Breakdown

Category Lines Changed
New Work 297 (100.0%)
Total Changes 297
To turn off PR summary, please visit Notification settings.

and2352000 and others added 2 commits May 4, 2026 16:29
Add a new reusable workflow that runs `npm test` directly on the GitHub
Actions runner BEFORE the docker build/save/upload steps, so test failures
fail-fast without paying the image build cost.

The existing `build_and_test_image.yml` is kept untouched (callers that
still depend on its in-container test behavior remain unaffected).

1. New workflow exposes `inputs.node-version` (default '22.16.0') so
   callers can override the Node version without touching the template.
2. `DEVOPS_READ_PACKAGE_TOKEN` is `required: true` in the new workflow
   (vs `required: false` in the old one) because `npm ci` now runs on
   the runner and needs the token for private packages.
3. Artifact contract preserved: still uploads `image.tar` under name
   `image` on dev/master, so downstream `push_and_rotate_image.yml`
   keeps working with no changes on the caller side.

Includes the implementation plan under docs/plans/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@typo-app

typo-app Bot commented May 4, 2026

Copy link
Copy Markdown

Static Code Review 📊

✅ All quality checks passed!

@and2352000 and2352000 merged commit ade170c into master May 4, 2026
6 of 10 checks passed
@and2352000 and2352000 deleted the feat/CW-27778-unit-test-then-build branch May 4, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants