Files
2026-11-05 04:44:29 +00:00

50 lines
2.1 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: ci-run
description: "跑一個 CI 工作:checkout → 還原快取(ci-cache,key 由 cache_files 的內容雜湊決定)→ 在 ci-env 容器裡執行指令。內部用的版本取自呼叫端的 Gitea 變數:ACTION_CHECKOUT_VERSION、ACTION_CI_CACHE_VERSION、ACTION_CI_ENV_VERSION。需要工具鏈時呼叫的工作流要有 env: GO_VERSION、NODE_VERSION"
inputs:
command:
description: "要在 ci-env 容器裡執行的 shell 指令"
required: true
cache_files:
description: "決定快取 key 的檔案(空白分隔,例如 go.sum web/package-lock.json);內容變了才換快取。不存在的檔案略過"
default: go.sum
cache_key:
description: "直接指定快取 key(有值就不用 cache_files 算)"
default: ""
cache_prefix:
description: "快取 key 的前綴,找不到完全相同的 key 時也用它還原最近的快取"
default: ci-home-
checkout:
description: "true=先 checkout;false=呼叫端已經 checkout"
default: "true"
name:
description: "執行指令的步驟名稱"
default: ci
runs:
using: composite
steps:
- name: checkout
if: ${{ inputs.checkout == 'true' }}
uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
- name: 算快取 key
id: key
shell: bash
env:
FILES: ${{ inputs.cache_files }}
KEY: ${{ inputs.cache_key }}
PREFIX: ${{ inputs.cache_prefix }}
run: |
if [ -z "$KEY" ]; then
# shellcheck disable=SC2086 # 依空白拆成檔案清單
KEY="$PREFIX$( (for f in $FILES; do [ ! -f "$f" ] || cat "$f"; done) | sha256sum | cut -c1-40)"
fi
echo "key=$KEY" >> "$GITHUB_OUTPUT"
echo "快取 key:$KEY"
- uses: https://gitea.jsc.idv.tw/actions/ci-cache@${{ vars.ACTION_CI_CACHE_VERSION }}
with:
key: ${{ steps.key.outputs.key }}
restore_keys: ${{ inputs.cache_prefix }}
- name: ${{ inputs.name }}
uses: https://gitea.jsc.idv.tw/actions/ci-env@${{ vars.ACTION_CI_ENV_VERSION }}
with:
command: ${{ inputs.command }}