diff --git a/Dockerfile b/Dockerfile index af3dacb..f75f077 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ FROM alpine:latest -# 安裝必要的工具 -RUN apk add --no-cache --no-check-certificate bash - +RUN apk add --no-cache --no-check-certificate bash curl ca-certificates + COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yaml b/action.yaml index f8849d0..4b20dc9 100644 --- a/action.yaml +++ b/action.yaml @@ -1,20 +1,16 @@ -name: 'Docker Action Template' -description: 'Docker Action 範本' +name: 'CLEANUP OLD NUGET' +description: '清理 Nuget 沒用到的資源' author: 'Jeffery' inputs: runner_token: - description: 'Gitea Runner Token' - required: true - text: - description: '輸入的文字' - default: "Hello, World!" -outputs: - text: - description: '輸出的文字' + description: 'Gitea API token, highest priority source' + required: false runs: using: 'docker' image: 'Dockerfile' env: GITEA_SERVER_URL: ${{ gitea.server_url }} GITEA_REPOSITORY: ${{ gitea.repository }} - RUNNER_TOKEN: ${{ inputs.runner_token || secrets.GITEA_TOKEN || secrets.RUNNER_TOKEN }} \ No newline at end of file + INPUT_RUNNER_TOKEN: ${{ inputs.runner_token }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + RUNNER_TOKEN_SECRET: ${{ secrets.RUNNER_TOKEN }} diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 index 378b552..31986ad --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,51 @@ #!/bin/bash +set -euo pipefail -echo "Gitea Server Url: $GITEA_SERVER_URL" +log() { + printf '%s\n' "$*" >&2 +} -echo "Gitea Repository: $GITEA_REPOSITORY" +fail() { + log "ERROR: $*" + exit 1 +} -echo "Gitea Runner Token: $RUNNER_TOKEN" +resolve_token() { + local source_name env_value + local sources=( + "inputs.RUNNER_TOKEN:INPUT_RUNNER_TOKEN" + "secrets.GITEA_TOKEN:GITEA_TOKEN" + "secrets.RUNNER_TOKEN:RUNNER_TOKEN_SECRET" + ) -echo "Input Text: $INPUT_TEXT" + for source in "${sources[@]}"; do + source_name="${source%%:*}" + env_value="${source#*:}" + log "Trying token from ${source_name}" + if [[ -n "${!env_value:-}" ]]; then + log "Using token from ${source_name}" + printf '%s' "${!env_value}" + return 0 + fi + log "Token not found in ${source_name}, trying next source" + done -echo "text=$INPUT_TEXT" >> "$GITHUB_OUTPUT" \ No newline at end of file + return 1 +} + +main() { + local token + + log "Gitea Server Url: ${GITEA_SERVER_URL:-}" + log "Gitea Repository: ${GITEA_REPOSITORY:-}" + + if ! token="$(resolve_token)"; then + fail "No Gitea token available, exiting" + fi + + export RESOLVED_GITEA_TOKEN="$token" + log "Token source resolved successfully" + log "Stage 1 complete" +} + +main "$@"