Skip to content

Commit cf99cdf

Browse files
committed
Fix Setting build outputs on cache hits
Also adds a test, which simulates behavior on cache-hits. Signed-off-by: Jonathan Schwender <[email protected]>
1 parent 0ee4782 commit cf99cdf

File tree

3 files changed

+159
-91
lines changed

3 files changed

+159
-91
lines changed

.github/workflows/workflow.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,33 @@ jobs:
2525
with:
2626
cache: false
2727
version: ${{ matrix.version }}
28+
fixup-path: 'false'
2829
- name: Test
29-
run: bash -c '"${OHOS_SDK_NATIVE}/llvm/bin/clang" --version'
30+
shell: bash
31+
run: |
32+
"${OHOS_SDK_NATIVE}/llvm/bin/clang" --version
33+
${{steps.initial-setup.outputs.ohos_sdk_native}}/llvm/bin/clang --version
34+
- name: Simulate action on cache-hit
35+
run: ./install_ohos_sdk.sh
36+
shell: bash
37+
env:
38+
INPUT_VERSION: "${{ matrix.version }}"
39+
INPUT_COMPONENTS: "all"
40+
INPUT_FIXUP_PATH: "false"
41+
INPUT_MIRROR: "true"
42+
INPUT_CACHE: "true"
43+
INPUT_WAS_CACHED: "true"
44+
GH_TOKEN: "${{ github.token }}"
45+
- name: Test
46+
shell: bash
47+
run: |
48+
"${OHOS_SDK_NATIVE}/llvm/bin/clang" --version
49+
${{steps.initial-setup.outputs.ohos_sdk_native}}/llvm/bin/clang --version
3050
- name: Remove previous SDK installation
51+
shell: bash
3152
env:
3253
SDK_PATH: "${{ steps.initial-setup.outputs.sdk-path }}"
33-
run: bash -c 'rm -rf "${SDK_PATH}"'
54+
run: rm -rf "${SDK_PATH}"
3455
- name: Setup SDK with Components
3556
id: sdk-with-components
3657
uses: ./
@@ -49,9 +70,10 @@ jobs:
4970
exit 1
5071
fi
5172
- name: Remove previous SDK installation
73+
shell: bash
5274
env:
5375
SDK_PATH: "${{ steps.sdk-with-components.outputs.sdk-path }}"
54-
run: bash -c 'rm -rf "${SDK_PATH}"'
76+
run: rm -rf "${SDK_PATH}"
5577
- name: Setup SDK and fixup the path
5678
id: sdk-with-fixup
5779
uses: ./
@@ -65,7 +87,29 @@ jobs:
6587
SDK_PATH: "${{ steps.sdk-with-fixup.outputs.sdk-path }}"
6688
API_VERSION: "${{ steps.sdk-with-fixup.outputs.api-version }}"
6789
run: |
68-
${SDK_PATH}/*/${API_VERSION}/native/llvm/bin/clang --version
90+
cd "${SDK_PATH}/*/${API_VERSION}/native/llvm/bin" && clang --version && cd -
91+
"${OHOS_SDK_NATIVE}/llvm/bin/clang" --version
92+
- name: Simulate action on cache-hit
93+
id: on_cache_hit_with_fixup
94+
run: ./install_ohos_sdk.sh
95+
shell: bash
96+
env:
97+
INPUT_VERSION: "${{ matrix.version }}"
98+
INPUT_COMPONENTS: "all"
99+
INPUT_FIXUP_PATH: "true"
100+
INPUT_MIRROR: "true"
101+
INPUT_CACHE: "true"
102+
INPUT_WAS_CACHED: "true"
103+
GH_TOKEN: "${{ github.token }}"
104+
- name: Test
105+
shell: bash
106+
env:
107+
SDK_PATH: "${{ steps.on_cache_hit_with_fixup.outputs.sdk-path }}"
108+
API_VERSION: "${{ steps.on_cache_hit_with_fixup.outputs.api-version }}"
109+
run: |
110+
cd "${SDK_PATH}/*/${API_VERSION}/native/llvm/bin" && clang --version && cd -
111+
"${OHOS_SDK_NATIVE}/llvm/bin/clang" --version
112+
${{steps.on_cache_hit_with_fixup.outputs.ohos_sdk_native}}/llvm/bin/clang --version
69113
70114
71115
build_result:

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ runs:
5959
id: install_ohos_sdk
6060
run: install_ohos_sdk.sh
6161
shell: bash
62-
if: ${{ inputs.cache != 'true' || steps.cache.outputs.cache-hit != 'true' }}
6362
env:
6463
INPUT_VERSION: "${{ inputs.version }}"
6564
INPUT_COMPONENTS: "${{ inputs.components }}"
6665
INPUT_FIXUP_PATH: ${{ inputs.fixup-path }}
6766
INPUT_MIRROR: "${{ inputs.mirror }}"
67+
INPUT_CACHE: "${{ inputs.cache }}"
68+
INPUT_WAS_CACHED: "${{ steps.cache.outputs.cache-hit }}"
6869
GH_TOKEN: "${{ github.token }}"

install_ohos_sdk.sh

Lines changed: 109 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -56,109 +56,132 @@ function select_version() {
5656
fi
5757
}
5858

59-
MIRROR_DOWNLOAD_SUCCESS=false
60-
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
61-
RESOLVED_MIRROR_VERSION_TAG="v${INPUT_VERSION}"
62-
select_version # This will update RESOLVED_MIRROR_VERSION_TAG.
63-
gh release download "${RESOLVED_MIRROR_VERSION_TAG}" --pattern "${OS_FILENAME}*" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
64-
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" == "true" ]]; then
65-
# The mirror may have split the archives due to the Github releases size limits.
66-
# First rename the sha256 file, so we don't glob it.
67-
mv "${OS_FILENAME}.sha256" "sha256.${OS_FILENAME}"
68-
# Now get all the .aa .ab etc. output of the split command for our filename
69-
shopt -s nullglob
70-
split_files=("${OS_FILENAME}".*)
71-
if [ ${#split_files[@]} -ne 0 ]; then
72-
cat "${split_files[@]}" > "${OS_FILENAME}"
73-
rm "${split_files[@]}"
59+
# Assumption: cwd contains the zipped components.
60+
# Outputs: API_VERSION
61+
function extract_sdk_components() {
62+
if [[ "${INPUT_COMPONENTS}" == "all" ]]; then
63+
COMPONENTS=(*.zip)
64+
else
65+
IFS=";" read -ra COMPONENTS <<< "${INPUT_COMPONENTS}"
66+
resolved_components=()
67+
for COMPONENT in "${COMPONENTS[@]}"
68+
do
69+
resolved_components+=("${COMPONENT}"-*.zip)
70+
done
71+
COMPONENTS=(${resolved_components[@]})
7472
fi
75-
# Rename the shafile back again to the original name
76-
mv "sha256.${OS_FILENAME}" "${OS_FILENAME}.sha256"
77-
elif [[ "${INPUT_MIRROR}" == "force" ]]; then
78-
echo "Downloading from mirror failed, and mirror=force. Failing the job."
79-
echo "Note: mirror=force is for internal test purposes, and should not be selected by users."
80-
exit 1
81-
else
82-
echo "Failed to download SDK from mirror. Falling back to downloading from upstream."
83-
fi
84-
fi
85-
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" != "true" ]]; then
86-
DOWNLOAD_URL="${URL_BASE}/${INPUT_VERSION}-Release/${OS_FILENAME}"
87-
echo "Downloading OHOS SDK from ${DOWNLOAD_URL}"
88-
curl --fail -L -O "${DOWNLOAD_URL}"
89-
curl --fail -L -O "${DOWNLOAD_URL}.sha256"
90-
fi
9173

92-
VERSION_MAJOR=${INPUT_VERSION%%.*}
74+
for COMPONENT in "${COMPONENTS[@]}"
75+
do
76+
echo "Extracting component ${COMPONENT}"
77+
echo "::group::Unzipping archive"
78+
#shellcheck disable=SC2144
79+
if [[ -f "${COMPONENT}" ]]; then
80+
unzip "${COMPONENT}"
81+
else
82+
echo "Failed to find component ${COMPONENT}"
83+
ls -la
84+
exit 1
85+
fi
86+
echo "::endgroup::"
87+
# Removing everything after the first dash should give us the component dir
88+
component_dir=${COMPONENT%%-*}
89+
API_VERSION=$(jq -r '.apiVersion' < "${component_dir}/oh-uni-package.json")
90+
if [ "$INPUT_FIXUP_PATH" = "true" ]; then
91+
mkdir -p "${API_VERSION}"
92+
mv "${component_dir}" "${API_VERSION}/"
93+
fi
94+
done
95+
rm ./*.zip
96+
}
9397

94-
if [[ "${OS}" == "mac" ]]; then
95-
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | shasum -a 256 --check --status
96-
tar -xf "${OS_FILENAME}" --strip-components=3
97-
else
98-
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | sha256sum --check --status
99-
if (( VERSION_MAJOR >= 5 )); then
100-
tar -xf "${OS_FILENAME}"
98+
function download_and_extract_sdk() {
99+
MIRROR_DOWNLOAD_SUCCESS=false
100+
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
101+
RESOLVED_MIRROR_VERSION_TAG="v${INPUT_VERSION}"
102+
select_version # This will update RESOLVED_MIRROR_VERSION_TAG.
103+
gh release download "${RESOLVED_MIRROR_VERSION_TAG}" --pattern "${OS_FILENAME}*" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
104+
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" == "true" ]]; then
105+
# The mirror may have split the archives due to the Github releases size limits.
106+
# First rename the sha256 file, so we don't glob it.
107+
mv "${OS_FILENAME}.sha256" "sha256.${OS_FILENAME}"
108+
# Now get all the .aa .ab etc. output of the split command for our filename
109+
shopt -s nullglob
110+
split_files=("${OS_FILENAME}".*)
111+
if [ ${#split_files[@]} -ne 0 ]; then
112+
cat "${split_files[@]}" > "${OS_FILENAME}"
113+
rm "${split_files[@]}"
114+
fi
115+
# Rename the shafile back again to the original name
116+
mv "sha256.${OS_FILENAME}" "${OS_FILENAME}.sha256"
117+
elif [[ "${INPUT_MIRROR}" == "force" ]]; then
118+
echo "Downloading from mirror failed, and mirror=force. Failing the job."
119+
echo "Note: mirror=force is for internal test purposes, and should not be selected by users."
120+
exit 1
121+
else
122+
echo "Failed to download SDK from mirror. Falling back to downloading from upstream."
123+
fi
124+
fi
125+
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" != "true" ]]; then
126+
DOWNLOAD_URL="${URL_BASE}/${INPUT_VERSION}-Release/${OS_FILENAME}"
127+
echo "Downloading OHOS SDK from ${DOWNLOAD_URL}"
128+
curl --fail -L -O "${DOWNLOAD_URL}"
129+
curl --fail -L -O "${DOWNLOAD_URL}.sha256"
130+
fi
131+
132+
VERSION_MAJOR=${INPUT_VERSION%%.*}
133+
134+
if [[ "${OS}" == "mac" ]]; then
135+
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | shasum -a 256 --check --status
136+
tar -xf "${OS_FILENAME}" --strip-components=3
101137
else
102-
tar -xf "${OS_FILENAME}" --strip-components=1
138+
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | sha256sum --check --status
139+
if (( VERSION_MAJOR >= 5 )); then
140+
tar -xf "${OS_FILENAME}"
141+
else
142+
tar -xf "${OS_FILENAME}" --strip-components=1
143+
fi
103144
fi
104-
fi
105-
rm "${OS_FILENAME}" "${OS_FILENAME}.sha256"
106-
echo "sdk-path=$PWD" >> "${GITHUB_OUTPUT}"
145+
rm "${OS_FILENAME}" "${OS_FILENAME}.sha256"
107146

108-
if [[ "${OS}" == "linux" ]]; then
109-
rm -rf windows
110-
cd linux
111-
elif [[ "${OS}" == "windows" ]]; then
112-
rm -rf linux
113-
cd windows
114-
else
115-
cd darwin
116-
fi
147+
if [[ "${OS}" == "linux" ]]; then
148+
rm -rf windows
149+
cd linux
150+
elif [[ "${OS}" == "windows" ]]; then
151+
rm -rf linux
152+
cd windows
153+
else
154+
cd darwin
155+
fi
156+
OHOS_BASE_SDK_HOME="$PWD"
157+
extract_sdk_components
158+
}
117159

118-
OHOS_BASE_SDK_HOME="$PWD"
160+
echo "sdk-path=$PWD" >> "${GITHUB_OUTPUT}"
119161

120-
if [[ "${INPUT_COMPONENTS}" == "all" ]]; then
121-
COMPONENTS=(*.zip)
162+
if [[ "${INPUT_CACHE}" != "true" || "${INPUT_WAS_CACHED}" != "true" ]]; then
163+
download_and_extract_sdk
122164
else
123-
IFS=";" read -ra COMPONENTS <<< "${INPUT_COMPONENTS}"
124-
resolved_components=()
125-
for COMPONENT in "${COMPONENTS[@]}"
126-
do
127-
resolved_components+=("${COMPONENT}"-*.zip)
128-
done
129-
COMPONENTS=(${resolved_components[@]})
130-
fi
131-
132-
for COMPONENT in "${COMPONENTS[@]}"
133-
do
134-
echo "Extracting component ${COMPONENT}"
135-
echo "::group::Unzipping archive"
136-
#shellcheck disable=SC2144
137-
if [[ -f "${COMPONENT}" ]]; then
138-
unzip "${COMPONENT}"
165+
if [[ "${OS}" == "linux" ]]; then
166+
cd linux
167+
elif [[ "${OS}" == "windows" ]]; then
168+
cd windows
139169
else
140-
echo "Failed to find component ${COMPONENT}"
141-
ls -la
142-
exit 1
170+
cd darwin
143171
fi
144-
echo "::endgroup::"
145-
# Removing everything after the first dash should give us the component dir
146-
component_dir=${COMPONENT%%-*}
147-
API_VERSION=$(cat "${component_dir}/oh-uni-package.json" | jq -r '.apiVersion')
148-
if [ "$INPUT_FIXUP_PATH" = "true" ]; then
149-
mkdir -p "${API_VERSION}"
150-
mv "${component_dir}" "${API_VERSION}/"
151-
fi
152-
done
153-
rm ./*.zip
172+
OHOS_BASE_SDK_HOME="$PWD"
173+
fi
154174

155175
if [ "${INPUT_FIXUP_PATH}" = "true" ]; then
156-
OHOS_NDK_HOME="${OHOS_BASE_SDK_HOME}/${API_VERSION}"
157-
OHOS_SDK_NATIVE="${OHOS_BASE_SDK_HOME}/${API_VERSION}/native"
176+
# When we are restoring from cache we don't know the API version, so we glob for now.
177+
# In the future we should do something more robust, like copying `oh-uni-package.json` to the root.
178+
OHOS_NDK_HOME=$(cd "${OHOS_BASE_SDK_HOME}"/* && pwd)
179+
OHOS_SDK_NATIVE="${OHOS_NDK_HOME}"/native
158180
else
159181
OHOS_NDK_HOME="${OHOS_BASE_SDK_HOME}"
160182
OHOS_SDK_NATIVE="${OHOS_BASE_SDK_HOME}/native"
161183
fi
184+
162185
cd "${OHOS_SDK_NATIVE}"
163186
SDK_VERSION="$(jq -r .version < oh-uni-package.json )"
164187
API_VERSION="$(jq -r .apiVersion < oh-uni-package.json )"

0 commit comments

Comments
 (0)