初始版本:從 feather-vault 搬出
ci / test (push) Successful in 36s

This commit is contained in:
bot
2026-11-05 02:54:21 +00:00
commit c2221c4281
9 changed files with 120 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
.git
.gitea
test
*.md
go.mod
icon.*
+19
View File
@@ -0,0 +1,19 @@
name: ci
on:
push:
branches: [main]
pull_request:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: docker-ubuntu
steps:
- uses: actions/checkout@v4
- name: shellcheck
run: |
curl -fsSL https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz | tar -xJ -C "$RUNNER_TEMP" --strip-components=1
"$RUNNER_TEMP/shellcheck" -x -S warning ./*.sh
- name: 建置映像檔
run: docker build -t "action-test:$GITHUB_SHA" .
+8
View File
@@ -0,0 +1,8 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# 上傳套件用 curl,讀 zip 的第一個項目用 python3,推標籤用 git;沒有 Go、Node,映像檔很小
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl git python3 \
&& rm -rf /var/lib/apt/lists/*
# 腳本打包進映像檔(action 在獨立的 repo,呼叫端的 workspace 裡沒有這些檔案);發佈新版時要換標籤,runner 才會重建映像檔
COPY . /action
ENTRYPOINT ["/bin/bash", "/action/entrypoint.sh"]
+29
View File
@@ -0,0 +1,29 @@
# publish-go
上傳 `build-go` 打包的 zip 到 Gitea 的 Go 套件庫,成功才推送版本標籤;套件已存在(409)視為已上傳,接著推標籤,所以失敗後可以安全重跑。
## 用法
版本由呼叫端的 Gitea Actions 變數決定(例如 `vars.ACTION_PUBLISH_GO_VERSION`),不要用分支名稱:runner 依 ref 重用舊映像檔,改了腳本不會生效,所以每次改動都發新標籤。
```yaml
- uses: https://gitea.jsc.idv.tw/actions/publish-go@${{ vars.ACTION_PUBLISH_GO_VERSION }}
with:
version: ...
zip: ...
token: ...
```
## 輸入
|名稱|必填|預設|說明|
|---|---|---|---|
|`version`|是||要發佈的版本,要和 build-go 的相同|
|`zip`|是||build-go 輸出的模組 zip 路徑|
|`token`|是||推送標籤與上傳套件用的權杖(需要 write:repository、write:package)|
## 開發
`ci.yaml` 跑 shellcheck、、建置映像檔。
圖示:`icon.svg`(Gitea 儲存庫頭像用 `icon.png`)。
+15
View File
@@ -0,0 +1,15 @@
name: publish-go
description: "發佈(Docker action,bash+git+curl+python3):把 build-go 打包的模組 zip 上傳到 Gitea 的 Go 套件庫,成功才推送版本標籤。套件已存在(409)視為已上傳,接著推標籤"
inputs:
version:
description: 要發佈的版本,要和 build-go 的相同
required: true
zip:
description: build-go 輸出的模組 zip 路徑
required: true
token:
description: 推送標籤與上傳套件用的權杖(需要 write:repository、write:package)
required: true
runs:
using: docker
image: Dockerfile
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# 發佈:上傳 build-go 產生的 zip → 成功才推送標籤。失敗不留遠端標籤;重跑時套件已存在(409)也視為已上傳,接著推標籤
set -euo pipefail
cd "${GITHUB_WORKSPACE:-$PWD}"
git config --global --add safe.directory "$PWD"
version=${INPUT_VERSION:?缺少 version}; token=${INPUT_TOKEN:?缺少 token}; zip=${INPUT_ZIP:?缺少 zip(build-go 的輸出)}
[ -f "$zip" ] || { echo "找不到 $zip:先執行 build-go" >&2; exit 1; }
git rev-parse -q --verify "refs/tags/$version" >/dev/null || { echo "本機沒有標籤 $version:先執行 build-go" >&2; exit 1; }
if ! out=$(GITEA_TOKEN="$token" GITEA_URL="$GITHUB_SERVER_URL" GITEA_OWNER="${GITHUB_REPOSITORY%%/*}" bash "$(dirname "${BASH_SOURCE[0]}")/go-module-upload.sh" "$zip" 2>&1); then
echo "$out" >&2
case "$out" in *已經存在*) echo "套件 $version 已上傳過,繼續推送標籤" >&2 ;; *) exit 1 ;; esac
else
echo "$out"
fi
remote="${GITHUB_SERVER_URL%%://*}://oauth2:${token}@${GITHUB_SERVER_URL#*://}/${GITHUB_REPOSITORY}.git"
git push "$remote" "refs/tags/$version"
echo "已推送標籤 $version"
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# 把 build-go 的 go-module-zip.sh 產生的模組 zip 上傳到 Gitea 的 Go 套件庫。由 publish-go 的 entrypoint.sh 呼叫。
# GITEA_TOKEN=<權杖,需要 write:package> go-module-upload.sh <zip 路徑>
# GITEA_URL(預設 GITHUB_SERVER_URL)、GITEA_OWNER(預設 GITHUB_REPOSITORY_OWNER)
set -euo pipefail
zip=${1:?用法:go-module-upload.sh <zip 路徑>}
: "${GITEA_TOKEN:?請設定 GITEA_TOKEN(需要 write:package 權限)}"
[ -f "$zip" ] || { echo "找不到 $zip" >&2; exit 1; }
base=${GITEA_URL:-${GITHUB_SERVER_URL:?請設定 GITEA_URL}}
owner=${GITEA_OWNER:-${GITHUB_REPOSITORY_OWNER:?請設定 GITEA_OWNER}}
# zip 裡的路徑是 <模組路徑>@<版本>/...,從第一個項目取出模組與標籤
modtag=$(python3 -I -c 'import sys, zipfile; n = zipfile.ZipFile(sys.argv[1]).namelist()[0]; print(n[:n.index("/", n.index("@"))])' "$zip" | tr -d '\r')
module=${modtag%@*}
tag=${modtag##*@}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
code=$(curl -sS -o "$work/resp" -w '%{http_code}' -X PUT -H "Authorization: token $GITEA_TOKEN" \
--upload-file "$zip" "$base/api/packages/$owner/go/upload")
cat "$work/resp"; echo
case "$code" in
2*) echo "已發佈 $module@$tag:$base/$owner/-/packages/go/$(printf %s "$module" | sed 's#/#%2f#g')/$tag" ;;
409) echo "$module@$tag 已經存在,Go 套件庫不能覆寫同一個版本" >&2; exit 1 ;;
*) echo "上傳失敗(HTTP $code)" >&2; exit 1 ;;
esac
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><rect width="512" height="512" rx="104" fill="#0891b2"/><path fill="none" stroke="#fff" stroke-width="28" stroke-linecap="round" stroke-linejoin="round" d="M120 310v78h272v-78"/><path fill="none" stroke="#fff" stroke-width="28" stroke-linecap="round" stroke-linejoin="round" d="M256 330V116M176 196 256 116l80 80"/></svg>

After

Width:  |  Height:  |  Size: 408 B