From e48e09b6cb273129900929042c5e4551e9058865 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 20 Mar 2026 14:43:40 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Revert=20"fix:=20=E5=AE=89=E8=A3=9D=20docke?= =?UTF-8?q?r=20=E5=A5=97=E4=BB=B6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8b979c483d28027c4dc6cf55c8b7412518a4ac9e. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index eeb3e2e..14b2525 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 RUN apt-get update \ - && apt-get install -y --no-install-recommends curl jq unzip docker \ + && apt-get install -y --no-install-recommends curl jq unzip \ && rm -rf /var/lib/apt/lists/* COPY entrypoint.sh /entrypoint.sh From ced4e937146ec7cd114bf0368dfaf25cafabd552 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 20 Mar 2026 14:43:44 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Revert=20"fix:=20=E8=A7=A3=E6=B1=BA=20error?= =?UTF-8?q?:=20Unrecognized=20option=20'--allow-insecure-connections'"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c0b75dbdcc1e1bf96aac6929dc2bc1a6c013dd2f. --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2ba4d2e..244272f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,7 +69,7 @@ for package in "${output_dir}"/*.nupkg; do fi packages_found=1 - dotnet nuget push "${package}" --source "${nuget_source}" --api-key "${api_key}" --skip-duplicate + dotnet nuget push "${package}" --source "${nuget_source}" --api-key "${api_key}" --skip-duplicate --allow-insecure-connections done if [ "${packages_found}" -eq 0 ]; then From 7405c7ea2d0a11b3760ba756a42aea254750f659 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 20 Mar 2026 14:43:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Revert=20"feat:=20=E6=94=B9=E6=88=90=20dock?= =?UTF-8?q?er=20action"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 049673f18299c42dd5a78c64826cb5dbbf9188a0. --- Dockerfile | 11 -------- action.yaml | 25 +++++++++++++++-- entrypoint.sh | 78 --------------------------------------------------- 3 files changed, 23 insertions(+), 91 deletions(-) delete mode 100644 Dockerfile delete mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 14b2525..0000000 --- a/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 - -RUN apt-get update \ - && apt-get install -y --no-install-recommends curl jq unzip \ - && rm -rf /var/lib/apt/lists/* - -COPY entrypoint.sh /entrypoint.sh - -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/action.yaml b/action.yaml index 61c8479..eacba41 100644 --- a/action.yaml +++ b/action.yaml @@ -13,5 +13,26 @@ inputs: index: default: 0 runs: - using: 'docker' - image: 'Dockerfile' + using: "composite" + steps: + - run: | + HEADER="Authorization: token ${{ inputs.token }}" + SOURCE="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/tags/v${{ inputs.version }}" + echo "HEADER: $HEADER" + echo "SOURCE: $SOURCE" + + RELEASE_JSON="$(curl -s -H "$HEADER" "$SOURCE")" + DOWNLOAD_NAME="$(echo "$RELEASE_JSON" | jq -r ".assets[${{ inputs.index }}].name")" + DOWNLOAD_URL="$(echo "$RELEASE_JSON" | jq -r ".assets[${{ inputs.index }}].browser_download_url")" + + echo "DOWNLOAD_NAME: $DOWNLOAD_NAME" + echo "DOWNLOAD_URL: $DOWNLOAD_URL" + + echo "ARTIFACT DOWNLOADING..." + curl -s -H "$HEADER" "$DOWNLOAD_URL" -o "$DOWNLOAD_NAME" + + echo "ARTIFACT UNZIPPING..." + unzip "$DOWNLOAD_NAME" -d output + + echo "ARTIFACT PUSHING..." + dotnet nuget push "output/*.nupkg" --source "${{ inputs.source }}" --api-key "${{ inputs.api_key }}" --skip-duplicate --allow-insecure-connections \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 244272f..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh -set -eu - -token="${INPUT_TOKEN:-}" -version="${INPUT_VERSION:?INPUT_VERSION is required}" -nuget_source="${INPUT_SOURCE:?INPUT_SOURCE is required}" -api_key="${INPUT_API_KEY:?INPUT_API_KEY is required}" -asset_index="${INPUT_INDEX:-0}" -server_url="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL:-}}" -repository="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY:-}}" - -if [ -z "${server_url}" ]; then - echo "GITEA_SERVER_URL or GITHUB_SERVER_URL is required" >&2 - exit 1 -fi - -if [ -z "${repository}" ]; then - echo "GITEA_REPOSITORY or GITHUB_REPOSITORY is required" >&2 - exit 1 -fi - -release_url="${server_url}/api/v1/repos/${repository}/releases/tags/v${version}" -work_dir="/tmp/nuget-push" -archive_dir="${work_dir}/archive" -output_dir="${work_dir}/output" - -mkdir -p "${archive_dir}" "${output_dir}" - -fetch_json() { - if [ -n "${token}" ]; then - curl -fsSL -H "Authorization: token ${token}" "$1" - return - fi - - curl -fsSL "$1" -} - -download_file() { - if [ -n "${token}" ]; then - curl -fsSL -H "Authorization: token ${token}" "$1" -o "$2" - return - fi - - curl -fsSL "$1" -o "$2" -} - -echo "RELEASE_URL: ${release_url}" - -release_json="$(fetch_json "${release_url}")" -download_name="$(printf '%s' "${release_json}" | jq -er ".assets[${asset_index}].name")" -download_url="$(printf '%s' "${release_json}" | jq -er ".assets[${asset_index}].browser_download_url")" -archive_path="${archive_dir}/${download_name}" - -echo "DOWNLOAD_NAME: ${download_name}" -echo "DOWNLOAD_URL: ${download_url}" - -echo "ARTIFACT DOWNLOADING..." -download_file "${download_url}" "${archive_path}" - -echo "ARTIFACT UNZIPPING..." -unzip -o "${archive_path}" -d "${output_dir}" >/dev/null - -packages_found=0 - -echo "ARTIFACT PUSHING..." -for package in "${output_dir}"/*.nupkg; do - if [ ! -f "${package}" ]; then - continue - fi - - packages_found=1 - dotnet nuget push "${package}" --source "${nuget_source}" --api-key "${api_key}" --skip-duplicate --allow-insecure-connections -done - -if [ "${packages_found}" -eq 0 ]; then - echo "No .nupkg files found after extracting ${download_name}" >&2 - exit 1 -fi \ No newline at end of file From 81cedc70d9a297a5d29153f89a4c0f8e50ac566e Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 20 Mar 2026 15:21:40 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E9=87=8D=E6=A7=8B=20nuget=20push?= =?UTF-8?q?=20=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 +++++++++ action.yaml | 46 ++++++++++---------------------- entrypoint.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 32 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62fd762 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 + +# 更新並安裝必要的工具後清理暫存檔案以減小映像檔大小 +RUN apt update \ + && apt install -y curl jq unzip \ + && rm -rf /var/lib/apt/lists/* + +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/action.yaml b/action.yaml index eacba41..ca579ad 100644 --- a/action.yaml +++ b/action.yaml @@ -1,38 +1,20 @@ name: 'NUGET PUSH' -description: '打包套件' +description: '推送 NUGET 套件' author: 'Jeffery' inputs: - token: - default: '' - version: + RELEASE_VERSION: required: true - source: - required: true - api_key: - required: true - index: + description: '要推送的版本號,ex: ${{ needs.calculate.outputs.version }}' + RELEASE_INDEX: default: 0 + description: '要推送的版本中第幾個成品,預設為 0' runs: - using: "composite" - steps: - - run: | - HEADER="Authorization: token ${{ inputs.token }}" - SOURCE="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/tags/v${{ inputs.version }}" - echo "HEADER: $HEADER" - echo "SOURCE: $SOURCE" - - RELEASE_JSON="$(curl -s -H "$HEADER" "$SOURCE")" - DOWNLOAD_NAME="$(echo "$RELEASE_JSON" | jq -r ".assets[${{ inputs.index }}].name")" - DOWNLOAD_URL="$(echo "$RELEASE_JSON" | jq -r ".assets[${{ inputs.index }}].browser_download_url")" - - echo "DOWNLOAD_NAME: $DOWNLOAD_NAME" - echo "DOWNLOAD_URL: $DOWNLOAD_URL" - - echo "ARTIFACT DOWNLOADING..." - curl -s -H "$HEADER" "$DOWNLOAD_URL" -o "$DOWNLOAD_NAME" - - echo "ARTIFACT UNZIPPING..." - unzip "$DOWNLOAD_NAME" -d output - - echo "ARTIFACT PUSHING..." - dotnet nuget push "output/*.nupkg" --source "${{ inputs.source }}" --api-key "${{ inputs.api_key }}" --skip-duplicate --allow-insecure-connections \ No newline at end of file + using: 'docker' + image: 'Dockerfile' + env: + GITEA_SERVER_URL: ${{ gitea.server_url }} + GITEA_REPOSITORY: ${{ gitea.repository }} + RELEASE_VERSION: ${{ inputs.RELEASE_VERSION }} + RELEASE_INDEX: ${{ inputs.RELEASE_INDEX }} + RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }} + NUGET_AUTHOR: ${{ gitea.author }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..047df25 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +echo "==================================================" + +echo "參數檢查" + +echo "--------------------------------------------------" + +# 顯示 GITEA_SERVER_URL 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "GITEA_SERVER_URL=$GITEA_SERVER_URL" && ([ -z "$GITEA_SERVER_URL" ] || [ "$GITEA_SERVER_URL" = "null" ]) && exit 1 + +# 顯示 GITEA_REPOSITORY 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "GITEA_REPOSITORY=$GITEA_REPOSITORY" && ([ -z "$GITEA_REPOSITORY" ] || [ "$GITEA_REPOSITORY" = "null" ]) && exit 1 + +# 顯示 RELEASE_VERSION 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "RELEASE_VERSION=$RELEASE_VERSION" && ([ -z "$RELEASE_VERSION" ] || [ "$RELEASE_VERSION" = "null" ]) && exit 1 + +# 顯示 RELEASE_INDEX 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "RELEASE_INDEX=$RELEASE_INDEX" && ([ -z "$RELEASE_INDEX" ] || [ "$RELEASE_INDEX" = "null" ]) && exit 1 + +# 顯示 RUNNER_TOKEN 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "RUNNER_TOKEN=$RUNNER_TOKEN" && ([ -z "$RUNNER_TOKEN" ] || [ "$RUNNER_TOKEN" = "null" ]) && exit 1 + +# 顯示 NUGET_AUTHOR 參數,並檢查是否為空或 "null",如果是則輸出錯誤訊息並退出 +echo "NUGET_AUTHOR=$NUGET_AUTHOR" && ([ -z "$NUGET_AUTHOR" ] || [ "$NUGET_AUTHOR" = "null" ]) && exit 1 + +echo "==================================================" + +echo "取得成品連結" + +echo "--------------------------------------------------" + +# 組合 RELEASE_HEADER 參數,並顯示出來 +RELEASE_HEADER="Authorization: token $RUNNER_TOKEN" && echo "RELEASE_HEADER=$RELEASE_HEADER" + +# 組合 RELEASE_URL 參數,並顯示出來 +RELEASE_URL="$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/releases/tags/v$RELEASE_VERSION" && echo "RELEASE_URL=$RELEASE_URL" + +# 取得成品資訊 +RELEASE_JSON="$(curl -s -H "$RELEASE_HEADER" "$RELEASE_URL")" + +# 從成品資訊取得名稱與連結 +RELEASE_NAME="$(echo "$RELEASE_JSON" | jq -r ".assets[$RELEASE_INDEX].name")" && echo "RELEASE_NAME=$RELEASE_NAME" +RELEASE_URL="$(echo "$RELEASE_JSON" | jq -r ".assets[$RELEASE_INDEX].browser_download_url")" && echo "RELEASE_URL=$RELEASE_URL" + +echo "==================================================" + +echo "下載成品" + +echo "--------------------------------------------------" + +curl -H "$RELEASE_HEADER" "$RELEASE_URL" -o "$RELEASE_NAME" + +echo "==================================================" + +echo "解壓縮成品" + +echo "--------------------------------------------------" + +unzip "$RELEASE_NAME" -d output + +echo "==================================================" + +echo "推送 NUGET 套件" + +echo "--------------------------------------------------" + +# 組合 NUGET_SOURCE 參數,並顯示出來 +NUGET_SOURCE="$GITEA_SERVER_URL/api/packages/$NUGET_AUTHOR/nuget/index.json" && echo "NUGET_SOURCE=$NUGET_SOURCE" + +dotnet nuget push "output/*.nupkg" --source "$NUGET_SOURCE" --api-key "$RUNNER_TOKEN" --skip-duplicate --allow-insecure-connections + +echo "==================================================" \ No newline at end of file