Skip to content

Commit

Permalink
chore: merge pull request #18 from YangHanlin/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghanlin authored May 13, 2023
2 parents 3b6048c + 7360ff2 commit b3038e1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
13 changes: 10 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ inputs:
description: 'Whether to enable debug logging'
required: false
default: 'false'
ossutil-version-:
description: 'Version of ossutil to download if none is found in PATH; this input parameter is undocumented and NOT guaranteed to be stable'
required: false
default: '1.7.15'

runs:
using: 'composite'
steps:
- name: Run script to prepare variables
run: ${{ github.action_path }}/bin/prepare-variables.sh
run: "'${{ github.action_path }}/bin/prepare-variables.sh'"
shell: bash
id: prepare-variables
env:
OSSUTIL_VERSION: 1.7.14
OSSUTIL_VERSION: ${{ inputs.ossutil-version- }}
DEBUG: ${{ inputs.debug }}
- name: Set up cache
uses: actions/cache@v3
Expand All @@ -64,7 +68,7 @@ runs:
path: ${{ steps.prepare-variables.outputs.workspace }}
key: ${{ steps.prepare-variables.outputs.cache-key }}
- name: Run script to deploy
run: ${{ github.action_path }}/bin/deploy.sh
run: "'${{ github.action_path }}/bin/deploy.sh'"
shell: bash
env:
OSS_ENDPOINT: ${{ inputs.oss-endpoint }}
Expand All @@ -78,6 +82,9 @@ runs:
FORCE_SETUP_OSSUTIL: ${{ inputs.force-setup-ossutil }}
DEBUG: ${{ inputs.DEBUG }}
WORKSPACE: ${{ steps.prepare-variables.outputs.workspace }}
OS_TYPE: ${{ steps.prepare-variables.outputs.os-type }}
OSSUTIL_EXECUTABLE_NAME: ${{ steps.prepare-variables.outputs.ossutil-executable-name }}
OSSUTIL_SPEC: ${{ steps.prepare-variables.outputs.ossutil-spec }}
OSSUTIL_DOWNLOAD_URL: ${{ steps.prepare-variables.outputs.ossutil-download-url }}

branding:
Expand Down
22 changes: 19 additions & 3 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ setup_workspace() {
mkdir -p "$WORKSPACE"
}

setup_temp_dir() {
log "Setting up temporary directory"

TEMP_DIR="$(mktemp -d)"
}

try_ossutil() {
log "Trying to find existing ossutil from PATH"

Expand All @@ -26,16 +32,25 @@ try_ossutil() {
setup_ossutil() {
log "Setting up ossutil"

OSSUTIL_BINARY="$WORKSPACE/ossutil"
if [[ "$OS_TYPE" == "windows" ]]; then
OSSUTIL_EXTENSION=".exe"
else
OSSUTIL_EXTENSION=""
fi
OSSUTIL_DOWNLOAD_DIR="$TEMP_DIR"
OSSUTIL_DOWNLOAD_DEST="ossutil.zip"
OSSUTIL_BINARY="$WORKSPACE/ossutil$OSSUTIL_EXTENSION"
OSSUTIL_CONFIG_FILE="$WORKSPACE/.ossutilconfig"
OSSUTIL_OUTPUT_DIR="$WORKSPACE/ossutil-output"
OSSUTIL_OUTPUT_DIR="$TEMP_DIR/ossutil-output"
OSSUTIL="$OSSUTIL_BINARY --config-file=$OSSUTIL_CONFIG_FILE"

if [[ -f "$OSSUTIL_BINARY" ]]; then
log "Using ossutil from cache"
else
log "Downloading ossutil"
curl -L -o "$OSSUTIL_BINARY" "$OSSUTIL_DOWNLOAD_URL"
curl --create-dirs --fail --location --output "$OSSUTIL_DOWNLOAD_DIR/$OSSUTIL_DOWNLOAD_DEST" "$OSSUTIL_DOWNLOAD_URL"
(cd "$OSSUTIL_DOWNLOAD_DIR" && unzip -o "$OSSUTIL_DOWNLOAD_DEST")
mv "$OSSUTIL_DOWNLOAD_DIR/$OSSUTIL_SPEC/$OSSUTIL_EXECUTABLE_NAME" "$OSSUTIL_BINARY"
fi
chmod u+x "$OSSUTIL_BINARY"

Expand Down Expand Up @@ -74,6 +89,7 @@ setup_environment() {
start_group "Set up environment"

setup_workspace
setup_temp_dir
if [[ "$FORCE_SETUP_OSSUTIL" == "" ]]; then
find_ossutil
fi
Expand Down
37 changes: 34 additions & 3 deletions bin/prepare-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,40 @@ source "$(dirname $0)/common.sh"
prepare_variables() {
start_group "Prepare variables"

set_output workspace "$RUNNER_TEMP/oss-deployment-action"
set_output ossutil-download-url "https://gosspublic.alicdn.com/ossutil/$OSSUTIL_VERSION/ossutil64"
set_output cache-key "oss-deployment-action-$RUNNER_OS-$OSSUTIL_VERSION"
if [[ "$RUNNER_OS" == "Windows" ]]; then
OS_TYPE=windows
OSSUTIL_EXECUTABLE_NAME=ossutil64.exe
elif [[ "$RUNNER_OS" == "Linux" ]]; then
OS_TYPE=linux
OSSUTIL_EXECUTABLE_NAME=ossutil64
elif [[ "$RUNNER_OS" == "macOS" ]]; then
OS_TYPE=mac
OSSUTIL_EXECUTABLE_NAME=ossutilmac64
else
log "Error: unsupported runner OS '$RUNNER_OS'"
exit 1
fi

# Currently only AMD64 architecture is supported
if [[ "$RUNNER_ARCH" == "X64" ]]; then
ARCH_TYPE=amd64
else
log "Error: unsupported runner architecture '$RUNNER_ARCH'"
exit 1
fi

WORKSPACE="$RUNNER_TEMP/oss-deployment-action"
OSSUTIL_SPEC="ossutil-v$OSSUTIL_VERSION-$OS_TYPE-$ARCH_TYPE"
OSSUTIL_DOWNLOAD_URL="https://gosspublic.alicdn.com/ossutil/$OSSUTIL_VERSION/$OSSUTIL_SPEC.zip"
CACHE_KEY="oss-deployment-action-$OSSUTIL_SPEC"

set_output os-type "$OS_TYPE"
set_output arch-type "$ARCH_TYPE"
set_output workspace "$WORKSPACE"
set_output ossutil-executable-name "$OSSUTIL_EXECUTABLE_NAME"
set_output ossutil-spec "$OSSUTIL_SPEC"
set_output ossutil-download-url "$OSSUTIL_DOWNLOAD_URL"
set_output cache-key "$CACHE_KEY"

end_group
}
Expand Down

0 comments on commit b3038e1

Please sign in to comment.