From 8e92cf6768c0c570cb49477eb3e65cd9dd1b6f50 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sun, 12 May 2024 13:22:22 +0200 Subject: [PATCH] Add initial version --- .github/workflows/workflow.yml | 26 +++++++++++++++ README.md | 4 +++ action.yml | 58 ++++++++++++++++++++++++++++++++++ install_ohos_sdk.sh | 58 ++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 .github/workflows/workflow.yml create mode 100644 README.md create mode 100644 action.yml create mode 100755 install_ohos_sdk.sh diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..620b025 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,26 @@ +name: Tests + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: ./ + id: setup_sdk + with: + cache: false + - name: Test clang is installed + run: "${OHOS_SDK_NATIVE}/llvm/bin/clang" --version + shell: bash + diff --git a/README.md b/README.md new file mode 100644 index 0000000..895ec19 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# OHOS SDK + +This is a simple GitHub action to automatically download and install the OpenHarmony SDK, +so you can use it in your GitHub actions workflow. \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..7c41823 --- /dev/null +++ b/action.yml @@ -0,0 +1,58 @@ +name: 'Setup OpenHarmony SDK' +description: 'Download an install the OpenHarmony SDK' +inputs: + version: + description: 'OpenHarmony SDK release version' + required: false + default: '4.1' + cache: + description: "Whether to cache the SDK or not" + required: false + default: true +outputs: + sdk-path: + description: "Directory of the OpenHarmony SDK" + value: ${{ steps.set_outputs.outputs.sdk-path }} + ohos_sdk_native: + description: "The `native` directory inside the OpenHarmony SDK" + value: ${{ steps.set_outputs.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 }} + api-version: + description: "OpenHarmony API version of the SDK" + api-version: ${{ steps.set_outputs.outputs.api-version }} +runs: + using: "composite" + steps: + - name: Set Greeting + run: echo "Hello ${{ inputs.version }}." + shell: bash + - name: Cache SDK + id: cache + uses: actions/cache@v4 + with: + path: ohos-sdk + key: ${{ runner.os }}-ohos-sdk-${{ inputs.version }} + if: ${{ inputs.cache }} == 'true' + - name: Download and install OpenHarmony SDK + id: install_ohos_sdk + run: ./install_ohos_sdk.sh + shell: bash + if: ${{ inputs.cache }} != 'true' || steps.cache.outputs.cache-hit != 'true' + env: + INPUT_VERSION: "${{ inputs.version }}" + - name: Set Outputs + id: set_outputs + shell: bash + run: | + echo "sdk-path=$HOME/ohos-sdk" >> "$GITHUB_OUTPUT" + OHOS_SDK_NATIVE="$HOME/ohos-sdk/*/native" + echo "OHOS_SDK_NATIVE=${OHOS_SDK_NATIVE}" >> "$GITHUB_ENV" + echo "ohos_sdk_native=${OHOS_SDK_NATIVE}" >> "$GITHUB_OUTPUT" + cd "${OHOS_SDK_NATIVE}" + SDK_VERSION="$(jq .version < oh-uni-package.json )" + API_VERSION="$(jq .apiVersion < oh-uni-package.json )" + echo "sdk-version=${SDK_VERSION}" >> "$GITHUB_OUTPUT" + echo "api-version=${API_VERSION}" >> "$GITHUB_OUTPUT" + diff --git a/install_ohos_sdk.sh b/install_ohos_sdk.sh new file mode 100755 index 0000000..bdb0e53 --- /dev/null +++ b/install_ohos_sdk.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -eu + +: "${INPUT_VERSION:?INPUT_VERSION needs to be set}" + +# https://repo.huaweicloud.com/openharmony/os/4.0-Release/ohos-sdk-windows_linux-public.tar.gz + +URL_BASE="https://repo.huaweicloud.com/openharmony/os" + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + OS_FILENAME="ohos-sdk-windows_linux-public.tar.gz" + OS=linux +elif [[ "$OSTYPE" == "darwin"* ]]; then + if [[ $(uname -m) == 'arm64' ]]; then + OS_FILENAME="L2-SDK-MAC-M1-PUBLIC.tar.gz" + else + OS_FILENAME="ohos-sdk-mac-public.tar.gz" + fi + OS=mac +elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then + OS_FILENAME="ohos-sdk-windows_linux-public.tar.gz" + OS=windows +else + echo "Unknown OS type. The OHOS SDK is only available for Windows, Linux and Mqd." +fi + +DOWNLOAD_URL="${URL_BASE}/${INPUT_VERSION}-Release/${OS_FILENAME}" + +echo "Downloading OHOS SDK from ${DOWNLOAD_URL}" + +curl --fail -L -o "${HOME}/openharmony-sdk.tar.gz" "${DOWNLOAD_URL}" +cd "${HOME}" +if [[ "${OS}" == "linux" ]]; then + tar -xvf openharmony-sdk.tar.gz --strip-components=2 +else + tar -xvf openharmony-sdk.tar.gz +fi +rm openharmony-sdk.tar.gz +cd ohos-sdk + +if [[ "${OS}" == "linux" ]]; then + rm -rf windows + cd linux +elif [[ "${OS}" == "windows" ]]; then + rm -rf linux + cd windows +else + cd darwin +fi + +# Todo: expose available components via an input variable. +# For now just extract native, to save disk space + +unzip native-*.zip +rm ./*.zip + +cd native