diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d864517..60fb79b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,13 +4,34 @@ on: push jobs: download: - runs-on: self-hosted - steps: - - uses: actions/checkout@v2 - - uses: ./ - with: - url: https://s3.nubificus.com - access-key: ${{ secrets.AWS_ACCESS_KEY }} - secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - local-path: "./" - remote-path: "github/test/test.txt" + runs-on: self-hosted + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Test single file download + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./" + remote-path: "github/minio/test1.txt" + + - name: Test wildcard with extension download + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./" + remote-path: "github/minio/*.txt" + + - name: Test wildcard download + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./" + remote-path: "github/minio/*" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 7e631b6..0000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM cloudkernels/mc - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index 4ebac66..43eacff 100644 --- a/action.yml +++ b/action.yml @@ -21,12 +21,44 @@ inputs: required: true runs: - using: 'docker' - image: 'Dockerfile' - entrypoint: '/entrypoint.sh' - args: - - ${{ inputs.url }} - - ${{ inputs.access-key }} - - ${{ inputs.secret-key }} - - ${{ inputs.local-path }} - - ${{ inputs.remote-path }} + using: composite + steps: + - name: Setup mc + working-directory: /usr/local/bin + run: | + [ -n "$(which mc)" ] && exit 0 + arch=$(dpkg --print-architecture | sed 's/armhf/arm/g') + sudo wget --progres=dot:binary \ + "https://dl.min.io/client/mc/release/linux-${arch}/mc" + sudo chmod +x mc + shell: bash + + - name: Setup s3 alias + run: | + mc alias set s3 "${{ inputs.url }}" \ + "${{ inputs.access-key }}" "${{ inputs.secret-key }}" + shell: bash + + - name: Download objects + run: | + echo "Will download ${{ inputs.remote-path }} to ${{ inputs.local-path }}" + remote_path=${{ inputs.remote-path }} + if [ "${remote_path#*'*'}" != "$remote_path" ]; then + # Handle remote_files with wildcards + remote_dir=$(dirname "$remote_path") + remote_files=$(basename "$remote_path") + path_depth=$(echo "$remote_dir" | awk -F"/" '{print NF-1}') + echo "$remote_dir" + echo "$remote_files" + echo "$path_depth" + IFS=$'\n' + for p in $(mc find "s3/$remote_dir" \ + --name "$remote_files" --maxdepth "$path_depth"); do + echo "$p" + mc cp -r "$p" "${{ inputs.local-path }}"; + done + unset IFS + else + mc cp -r "s3/$remote_path" "${{ inputs.local-path }}" + fi + shell: bash diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 5ea944b..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -LOG_NAME="minio" - -info() { - [ -t 1 ] && [ -n "$TERM" ] \ - && echo "$(tput setaf 2)[$LOG_NAME]$(tput sgr0) $*" \ - || echo "[$LOG_NAME] $*" -} - -err() { - [ -t 2 ] && [ -n "$TERM" ] \ - && echo -e "$(tput setaf 1)[$LOG_NAME]$(tput sgr0) $*" 1>&2 \ - || echo -e "[$LOG_NAME] $*" 1>&2 -} - -die() { - err "$@" - exit 1 -} - -ok_or_die() { - if [ $? -ne 0 ]; then - die "$1" - fi -} - -if [[ $# -ne 5 ]] ; then - die "Usage: $0 url access_key secret_key local_path remote_path" -fi - -url=$1 -access_key=$2 -secret_key=$3 -local_path=$4 -remote_path=$5 - -info "Will fetch $remote_path to $local_path" - -mc alias set s3 "$url" "$access_key" "$secret_key" -ok_or_die "Could not set mc alias" - -if [ "${remote_path#*'*'}" != "$remote_path" ]; then - # Handle remote_dir with wildcard - remote_dir=$(dirname "$remote_path") - remote_files=$(basename "$remote_path") - path_depth=$(echo "$remote_dir" | awk -F"/" '{print NF-1}') - IFS=$'\n' - for p in $(mc find "s3/$remote_dir" \ - --name "$remote_files" --maxdepth "$path_depth"); do - mc cp -r "$p" "$local_path"; - done - unset IFS -else - mc cp -r "s3/$remote_path $local_path" -fi -ok_or_die "Could not fetch object" - -# Fix owner of local path -LOCAL_UID="${ACTION_UID:-"$(stat -c %u .)"}" -LOCAL_GID="${ACTION_GID:-"$(stat -c %g .)"}" -info "Setting owner/group of $local_path to ${LOCAL_UID:-root}:${LOCAL_GID:-root}" -chown -R "${LOCAL_UID:-root}:${LOCAL_GID:-root}" "$local_path"