diff --git a/action.yml b/action.yml index 35854e4..e31bd52 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} @@ -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: diff --git a/bin/deploy.sh b/bin/deploy.sh index 9a57fd7..910951f 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -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" @@ -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" @@ -74,6 +89,7 @@ setup_environment() { start_group "Set up environment" setup_workspace + setup_temp_dir if [[ "$FORCE_SETUP_OSSUTIL" == "" ]]; then find_ossutil fi diff --git a/bin/prepare-variables.sh b/bin/prepare-variables.sh index 11a06c7..373cc9c 100755 --- a/bin/prepare-variables.sh +++ b/bin/prepare-variables.sh @@ -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 }