6 Commits

Author SHA1 Message Date
Jeffery
cd5480b334 test: 嘗試修正 INPUT_GITEA_SERVER: unbound variable 問題 2026-03-20 14:25:53 +08:00
Jeffery
ea8b72ce8f feat: 改成 docker action 2026-03-20 14:18:53 +08:00
0d7cdd65ca 更新 .gitea/workflows/master.yaml 2026-03-05 08:07:45 +00:00
99ae6a157b 更新 .gitea/workflows/master.yaml 2026-03-05 08:05:12 +00:00
3bd0ecaa98 更新 .gitea/workflows/master.yaml 2026-03-05 07:59:39 +00:00
Jeffery
146283281b fix: 修正刪除 API 的參數 2025-12-01 15:14:56 +08:00
5 changed files with 45 additions and 31 deletions

View File

@@ -11,17 +11,17 @@ jobs:
steps: steps:
- name: 計算版本號 - name: 計算版本號
id: version id: version
uses: https://gitea.jsc.idv.tw/jiantw83/calculate-version-action@v${{ vars.CALCULATE_VERSION }} uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }}
with: with:
gitea-server: ${{ gitea.server_url }} gitea-server: ${{ gitea.server_url }}
repository: ${{ gitea.repository }} repository: ${{ gitea.repository }}
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
- name: 發布專案 - name: 發布專案
uses: akkuman/gitea-release-action@v1 uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }}
with: with:
tag_name: "v${{ steps.version.outputs.VERSION }}" tag_name: "v${{ steps.version.outputs.VERSION }}"
- name: 清理舊版本 (保留最新2個) - name: 清理舊版本 (保留最新2個)
uses: https://gitea.jsc.idv.tw/jiantw83/cleanup-release-action@v${{ vars.CLEANUP_RELEASE_VERSION }} uses: https://gitea.jsc.idv.tw/actions/cleanup-release@${{ vars.ACTION_CLEANUP_RELEASE_VERSION }}
with: with:
gitea-server: ${{ gitea.server_url }} gitea-server: ${{ gitea.server_url }}
repository: ${{ gitea.repository }} repository: ${{ gitea.repository }}

11
Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM alpine:3.21
RUN apk add --no-cache bash curl jq
COPY cleanup-releases.sh /cleanup-releases.sh
COPY cleanup-images.sh /cleanup-images.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /cleanup-releases.sh /cleanup-images.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -23,30 +23,12 @@ inputs:
required: false required: false
default: 'false' default: 'false'
runs: runs:
using: 'composite' using: 'docker'
steps: image: 'Dockerfile'
- name: 清理舊版本 env:
id: cleanup GITEA_SERVER: ${{ inputs.gitea-server }}
shell: bash REPOSITORY: ${{ inputs.repository }}
run: | PACKAGE_NAME: ${{ inputs.package-name }}
chmod +x "${{ github.action_path }}/cleanup-releases.sh" TOKEN: ${{ inputs.token }}
"${{ github.action_path }}/cleanup-releases.sh" \ KEEP_COUNT: ${{ inputs.keep-count }}
"${{ inputs.gitea-server }}" \ DRY_RUN: ${{ inputs.dry-run }}
"${{ inputs.repository }}" \
"${{ inputs.token }}" \
"${{ inputs.keep-count }}" \
"${{ inputs.dry-run }}"
- name: 清理舊映像
id: cleanup-images
if: inputs.package-name != ''
shell: bash
run: |
chmod +x "${{ github.action_path }}/cleanup-images.sh"
"${{ github.action_path }}/cleanup-images.sh" \
"${{ inputs.gitea-server }}" \
"${{ inputs.repository }}" \
"${{ inputs.package-name }}" \
"${{ inputs.token }}" \
"${{ inputs.keep-count }}" \
"${{ inputs.dry-run }}"

View File

@@ -90,7 +90,7 @@ while IFS= read -r version; do
else else
# 實際刪除 # 實際刪除
DELETE_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ DELETE_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X DELETE "$GITEA_SERVER/api/v1/packages/$OWNER/container/$PACKAGE_NAME/$VERSION_ID?token=$TOKEN" \ -X DELETE "$GITEA_SERVER/api/v1/packages/$OWNER/container/$PACKAGE_NAME/$VERSION_NAME?token=$TOKEN" \
-H "Accept: application/json") -H "Accept: application/json")
DELETE_HTTP_STATUS=$(echo "$DELETE_RESPONSE" | grep -o "HTTP_STATUS:[0-9]*" | cut -d: -f2) DELETE_HTTP_STATUS=$(echo "$DELETE_RESPONSE" | grep -o "HTTP_STATUS:[0-9]*" | cut -d: -f2)

21
entrypoint.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail
GITEA_SERVER="${GITEA_SERVER:-}"
REPOSITORY="${REPOSITORY:-}"
PACKAGE_NAME="${PACKAGE_NAME:-}"
TOKEN="${TOKEN:-}"
KEEP_COUNT="${KEEP_COUNT:-2}"
DRY_RUN="${DRY_RUN:-false}"
if [[ -z "$GITEA_SERVER" ]] || [[ -z "$REPOSITORY" ]] || [[ -z "$TOKEN" ]]; then
echo "❌ 錯誤:缺少必要的 inputs (gitea-server, repository, token)"
exit 1
fi
/cleanup-releases.sh "$GITEA_SERVER" "$REPOSITORY" "$TOKEN" "$KEEP_COUNT" "$DRY_RUN"
if [[ -n "$PACKAGE_NAME" ]]; then
/cleanup-images.sh "$GITEA_SERVER" "$REPOSITORY" "$PACKAGE_NAME" "$TOKEN" "$KEEP_COUNT" "$DRY_RUN"
fi