Files
action-ci/action.yml
T
bot 2cac19095b
ci / test (pull_request) Successful in 4s
cd / tag (pull_request) Successful in 3s
調整:第三方 action 與工具的版本也從 Gitea 變數取得
2026-11-05 04:44:27 +00:00

54 lines
2.6 KiB
YAML
Raw 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: action-ci
description: "action repo 的共用 CI:checkout → shellcheck → Go 腳本測試(有 go.mod 與 test/ 才跑,在 ci-env 容器裡,Go 版本取 go.mod)→ 建置映像檔(有 Dockerfile 才跑,可選擇實際執行並檢查輸出)。自動偵測,各 repo 的 ci.yaml 不必設開關。版本都取自呼叫端的 Gitea 變數:ACTION_CHECKOUT_VERSION、ACTION_SHELLCHECK_VERSION、ACTION_CI_ENV_VERSION、TOOL_SHELLCHECK_VERSION(shellcheck 本身)"
inputs:
checkout:
description: "true=先 checkout;false=呼叫端已經 checkout(例如要用 uses: ./ 測自己)"
default: "true"
shellcheck_files:
description: "shellcheck 要檢查的檔案(空白分隔,可用萬用字元);沒有符合的檔案就略過"
default: "*.sh"
go_test_command:
description: "有 go.mod 與 test/ 時執行的指令"
default: "go vet ./... && go test ./test/"
docker_run_args:
description: "docker build 之後實際執行容器的參數(entrypoint 的參數,每行一個);空=只建置不執行"
default: ""
docker_run_options:
description: "執行容器的 docker create 選項(每行一個,例如 --env=INPUT_TASK=resolve-channel)"
default: ""
docker_run_expect:
description: "容器輸出必須包含的字串;空=只檢查結束碼"
default: ""
runs:
using: composite
steps:
- name: checkout
if: ${{ inputs.checkout == 'true' }}
uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
- name: 偵測
id: detect
shell: bash
run: |
[ -f go.mod ] && [ -d test ] && echo "go=true" >> "$GITHUB_OUTPUT" || echo "go=false" >> "$GITHUB_OUTPUT"
[ -f Dockerfile ] && echo "docker=true" >> "$GITHUB_OUTPUT" || echo "docker=false" >> "$GITHUB_OUTPUT"
- name: shellcheck
uses: https://gitea.jsc.idv.tw/actions/shellcheck@${{ vars.ACTION_SHELLCHECK_VERSION }}
with:
files: ${{ inputs.shellcheck_files }}
version: ${{ vars.TOOL_SHELLCHECK_VERSION }}
- name: Go 測試
if: ${{ steps.detect.outputs.go == 'true' }}
uses: https://gitea.jsc.idv.tw/actions/ci-env@${{ vars.ACTION_CI_ENV_VERSION }}
env:
GO_VERSION: go.mod
with:
command: ${{ inputs.go_test_command }}
- name: 建置映像檔
if: ${{ steps.detect.outputs.docker == 'true' }}
shell: bash
env:
RUN_ARGS: ${{ inputs.docker_run_args }}
RUN_OPTIONS: ${{ inputs.docker_run_options }}
RUN_EXPECT: ${{ inputs.docker_run_expect }}
run: bash "${{ github.action_path }}/docker-check.sh"