Skip to content

Commit

Permalink
Refactor github outputs into install script
Browse files Browse the repository at this point in the history
This allows removing some globbing in favor of the
respective variables.

Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Oct 6, 2024
1 parent 15a618d commit fb134d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
32 changes: 5 additions & 27 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ inputs:
outputs:
sdk-path:
description: "Root directory of the OpenHarmony SDK installation"
value: ${{ steps.set_outputs.outputs.sdk-path }}
value: ${{ steps.install_ohos_sdk.outputs.sdk-path }}
ohos_sdk_native:
description: "The `native` directory inside the OpenHarmony SDK"
value: ${{ steps.set_outputs.outputs.ohos_sdk_native }}
value: ${{ steps.install_ohos_sdk.outputs.ohos_sdk_native }}
sdk-version:
description: "Specific version of the OpenHarmony SDK (e.g. 4.1.7.5)"
value: ${{ steps.set_outputs.outputs.sdk-version }}
value: ${{ steps.install_ohos_sdk.outputs.sdk-version }}
api-version:
description: "OpenHarmony API version of the SDK"
value: ${{ steps.set_outputs.outputs.api-version }}
value: ${{ steps.install_ohos_sdk.outputs.api-version }}
ohos-base-sdk-home:
description: "Path to the OpenHarmony SDK for the host platform"
value: ${{ steps.set_outputs.outputs.ohos-base-sdk-home }}
value: ${{ steps.install_ohos_sdk.outputs.ohos-base-sdk-home }}
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -66,26 +66,4 @@ runs:
INPUT_FIXUP_PATH: ${{ inputs.fixup-path }}
INPUT_MIRROR: "${{ inputs.mirror }}"
GH_TOKEN: "${{ github.token }}"
- name: Set Outputs
id: set_outputs
shell: bash
env:
INPUT_FIXUP_PATH: ${{ inputs.fixup-path }}
run: |
echo "sdk-path=$HOME/ohos-sdk" >> "$GITHUB_OUTPUT"
OHOS_BASE_SDK_HOME=$(cd $HOME/ohos-sdk/*/ && pwd)
if [ "${INPUT_FIXUP_PATH}" = "true" ]; then
OHOS_SDK_NATIVE="$(cd $HOME/ohos-sdk/*/*/native && pwd)"
else
OHOS_SDK_NATIVE="$(cd $HOME/ohos-sdk/*/native && pwd)"
fi
cd "${OHOS_SDK_NATIVE}"
SDK_VERSION="$(jq -r .version < oh-uni-package.json )"
API_VERSION="$(jq -r .apiVersion < oh-uni-package.json )"
echo "OHOS_BASE_SDK_HOME=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_ENV"
echo "ohos-base-sdk-home=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_OUTPUT"
echo "OHOS_SDK_NATIVE=${OHOS_SDK_NATIVE}" >> "$GITHUB_ENV"
echo "ohos_sdk_native=${OHOS_SDK_NATIVE}" >> "$GITHUB_OUTPUT"
echo "sdk-version=${SDK_VERSION}" >> "$GITHUB_OUTPUT"
echo "api-version=${API_VERSION}" >> "$GITHUB_OUTPUT"

24 changes: 23 additions & 1 deletion install_ohos_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ else
exit 1
fi

cd "${HOME}"
WORK_DIR="${HOME}/setup-ohos-sdk"
mkdir -p "${WORK_DIR}"
cd "${WORK_DIR}"

MIRROR_DOWNLOAD_SUCCESS=false
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
Expand Down Expand Up @@ -69,6 +71,7 @@ else
fi
rm "${OS_FILENAME}" "${OS_FILENAME}.sha256"
cd ohos-sdk
echo "sdk-path=$PWD" >> "${GITHUB_OUTPUT}"

if [[ "${OS}" == "linux" ]]; then
rm -rf windows
Expand All @@ -80,15 +83,34 @@ else
cd darwin
fi

OHOS_BASE_SDK_HOME="$PWD"

IFS=";" read -ra COMPONENTS <<< "${INPUT_COMPONENTS}"
for COMPONENT in "${COMPONENTS[@]}"
do
echo "Extracting component ${COMPONENT}"
echo "::group::Unzipping archive"
unzip "${COMPONENT}"-*.zip
echo "::endgroup::"
API_VERSION=$(cat "${COMPONENT}/oh-uni-package.json" | jq -r '.apiVersion')
if [ "$INPUT_FIXUP_PATH" = "true" ]; then
mkdir -p "${API_VERSION}"
mv "${COMPONENT}" "${API_VERSION}/"
fi
done
rm ./*.zip

if [ "${INPUT_FIXUP_PATH}" = "true" ]; then
OHOS_SDK_NATIVE="${OHOS_BASE_SDK_HOME}/${API_VERSION}/native"
else
OHOS_SDK_NATIVE="${OHOS_BASE_SDK_HOME}/native"
fi
cd "${OHOS_SDK_NATIVE}"
SDK_VERSION="$(jq -r .version < oh-uni-package.json )"
API_VERSION="$(jq -r .apiVersion < oh-uni-package.json )"
echo "OHOS_BASE_SDK_HOME=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_ENV"
echo "ohos-base-sdk-home=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_OUTPUT"
echo "OHOS_SDK_NATIVE=${OHOS_SDK_NATIVE}" >> "$GITHUB_ENV"
echo "ohos_sdk_native=${OHOS_SDK_NATIVE}" >> "$GITHUB_OUTPUT"
echo "sdk-version=${SDK_VERSION}" >> "$GITHUB_OUTPUT"
echo "api-version=${API_VERSION}" >> "$GITHUB_OUTPUT"

0 comments on commit fb134d4

Please sign in to comment.