Skip to content

Commit 699c7a0

Browse files
authored
Added download status, added comparison by hash sum (#474)
1 parent daf9d76 commit 699c7a0

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

.github/workflows/publish.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ jobs:
1515
- name: Set CPM version by tag
1616
run: |
1717
mkdir dist
18-
sed "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/CPM.cmake > dist/CPM.cmake
19-
sed "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\/v}/g" cmake/get_cpm.cmake > dist/get_cpm.cmake
18+
sed -e "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\//v}/g" cmake/CPM.cmake > dist/CPM.cmake
19+
sed -e "s/1.0.0-development-version/${GITHUB_REF/refs\/tags\//v}/g" \
20+
-e "s/EMPTY_HASH_SUM/$(sha256sum cmake/CPM.cmake | cut -d' ' -f1)/" cmake/get_cpm.cmake > dist/get_cpm.cmake
2021
2122
- name: Upload CPM.cmake to release
2223
uses: svenstaro/upload-release-action@v1-release

cmake/get_cpm.cmake

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
44

55
set(CPM_DOWNLOAD_VERSION 1.0.0-development-version)
6+
set(CPM_HASH_SUM "HASH_SUM_PLACEHOLDER")
67

78
if(CPM_SOURCE_CACHE)
89
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
@@ -15,23 +16,20 @@ endif()
1516
# Expand relative path. This is important if the provided path contains a tilde (~)
1617
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
1718

18-
function(download_cpm)
19-
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
20-
file(DOWNLOAD
21-
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
22-
${CPM_DOWNLOAD_LOCATION}
23-
)
24-
endfunction()
25-
26-
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
27-
download_cpm()
19+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
20+
file(
21+
DOWNLOAD
22+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
23+
${CPM_DOWNLOAD_LOCATION}
24+
STATUS CPM_DOWNLOAD_STATUS
25+
EXPECTED_HASH SHA256=${CPM_HASH_SUM}
26+
)
27+
list(GET CPM_DOWNLOAD_STATUS 0 CPM_DOWNLOAD_STATUS_CODE)
28+
list(GET CPM_DOWNLOAD_STATUS 1 CPM_DOWNLOAD_ERROR_MESSAGE)
29+
if(${CPM_DOWNLOAD_STATUS_CODE} EQUAL 0)
30+
message(STATUS "CPM: Download completed successfully.")
2831
else()
29-
# resume download if it previously failed
30-
file(READ ${CPM_DOWNLOAD_LOCATION} check)
31-
if("${check}" STREQUAL "")
32-
download_cpm()
33-
endif()
34-
unset(check)
32+
message(FATAL_ERROR "CPM: Error occurred during download: ${CPM_DOWNLOAD_ERROR_MESSAGE}")
3533
endif()
3634

3735
include(${CPM_DOWNLOAD_LOCATION})

0 commit comments

Comments
 (0)