Skip to content

Commit 79030b1

Browse files
authored
Single release CMake file that contains all required links/hashes. (#4631)
This PR aims to autogenerate cmake file containing all required hash/url combinations so that other repositories can simply pull this file and forget about changing all url/hash occurences in their code. The output assets look like this now: https://github.com/dudoslav/TileDB/releases/tag/t01 Please let me know if the produced CMake file is ok, or should be changed to a different format. --- TYPE: BUILD DESC: Single release CMake file that contains all required links/hashes.
1 parent 619f3ae commit 79030b1

File tree

3 files changed

+215
-1
lines changed

3 files changed

+215
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Append Release CMake
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'Ref to be used as release'
8+
default: 'latest'
9+
required: true
10+
type: string
11+
workflow_call:
12+
inputs:
13+
ref:
14+
description: 'Ref to be used as release'
15+
default: 'latest'
16+
required: true
17+
type: string
18+
19+
jobs:
20+
generate_cmake_files:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout TileDB
24+
uses: actions/checkout@v3
25+
26+
- name: Make release and output directories
27+
run: |
28+
mkdir release output
29+
30+
- name: Github release data
31+
id: release_data
32+
uses: KevinRohn/[email protected]
33+
with:
34+
# repository: 'TileDB-Inc/TileDB'
35+
version: ${{ inputs.ref }}
36+
asset-file: '*.zip,*.tar.gz'
37+
asset-output: './release/'
38+
39+
- name: Render template
40+
run: |
41+
PATTERN="tiledb-([^-]+)-([^-]+)(-noavx2)?-([^-]+).(tar.gz|zip)$"
42+
RELLIST="output/releases.csv"
43+
MODULE="output/DownloadPrebuiltTileDB.cmake"
44+
cp cmake/inputs/DownloadPrebuiltTileDB.cmake $MODULE
45+
echo "platform,url,sha256" > $RELLIST
46+
47+
for FILE in $(ls release)
48+
do
49+
if [[ $FILE =~ $PATTERN ]]
50+
then
51+
OS=${BASH_REMATCH[1]^^}
52+
ARCH=${BASH_REMATCH[2]^^}
53+
NOAVX2=${BASH_REMATCH[3]^^}
54+
PLATFORM=${OS}-${ARCH}${NOAVX2}
55+
56+
URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${{ inputs.ref }}/$FILE"
57+
HASH=$(cat release/$FILE.sha256 | cut -d \t -f 1)
58+
59+
echo "${PLATFORM},${URL},${HASH}" >> $RELLIST
60+
fi
61+
done
62+
63+
SOURCE_FILE_NAME=$(ls release/tiledb-source-*.tar.gz)
64+
URL_TILEDB_SOURCE="${{ github.server_url }}/${{ github.repository }}/releases/download/${{ inputs.ref }}/$(basename $SOURCE_FILE_NAME)"
65+
HASH_TILEDB_SOURCE=$(cat $SOURCE_FILE_NAME.sha256 | cut -d \t -f 1)
66+
67+
echo "source,${URL_TILEDB_SOURCE},${HASH_TILEDB_SOURCE}" >> $RELLIST
68+
69+
HASH=$(sha256sum $RELLIST | cut -d " " -f 1)
70+
echo $HASH > $RELLIST.sha256
71+
72+
cat $RELLIST
73+
74+
- name: Upload template to release
75+
uses: svenstaro/upload-release-action@v2
76+
with:
77+
file: output/*
78+
tag: ${{ steps.release_data.outputs.tag_name }}
79+
overwrite: true
80+
file_glob: true

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
- 'release-*'
88
tags:
99
- '*'
10-
workflow_dispatch:
1110

1211
jobs:
1312
Package-Source-Release:
@@ -175,6 +174,13 @@ jobs:
175174
});
176175
}
177176
177+
Generate-Release-List:
178+
needs:
179+
- Publish-Release
180+
uses: ./.github/workflows/append-release-cmake.yml
181+
with:
182+
ref: ${{ github.ref_name }}
183+
178184
Create-Issue-On-Fail:
179185
permissions:
180186
issues: write
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#
2+
# FindTileDB_EP.cmake
3+
#
4+
#
5+
# The MIT License
6+
#
7+
# Copyright (c) 2023 TileDB, Inc.
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
# THE SOFTWARE.
26+
27+
include(FetchContent)
28+
29+
function(fetch_tiledb_release_list VERSION EXPECTED_HASH)
30+
# Local constants
31+
set(UPSTREAM_URL "https://github.com/TileDB-Inc/TileDB/releases/download")
32+
33+
if(NOT VERSION)
34+
set(VERSION latest)
35+
endif()
36+
37+
if(${EXPECTED_HASH})
38+
file(DOWNLOAD
39+
${UPSTREAM_URL}/${VERSION}/releases.csv
40+
releases.csv
41+
SHOW_PROGRESS
42+
EXPECTED_HASH ${EXPECTED_HASH}
43+
)
44+
else()
45+
message(WARNING "Downloading release list without SHA checksum!")
46+
file(DOWNLOAD
47+
${UPSTREAM_URL}/${VERSION}/releases.csv
48+
releases.csv
49+
SHOW_PROGRESS
50+
)
51+
endif()
52+
53+
file(STRINGS
54+
${CMAKE_CURRENT_BINARY_DIR}/releases.csv
55+
RELLIST
56+
)
57+
58+
# Remove csv table headers
59+
list(POP_FRONT RELLIST)
60+
61+
foreach(LINE ${RELLIST})
62+
string(REPLACE "," ";" LINE ${LINE})
63+
list(LENGTH LINE LENGTH)
64+
65+
list(GET LINE 0 PLATFORM)
66+
list(GET LINE 1 URL)
67+
list(GET LINE 2 SHA)
68+
69+
set(RELEASE_VAR TILEDB_${PLATFORM})
70+
set(URL_${RELEASE_VAR} ${URL} PARENT_SCOPE)
71+
set(HASH_${RELEASE_VAR} ${SHA} PARENT_SCOPE)
72+
endforeach()
73+
endfunction()
74+
75+
function(detect_artifact_name OUT_VAR)
76+
if (WIN32) # Windows
77+
SET(${OUT_VAR} TILEDB_WINDOWS-X86_64 PARENT_SCOPE)
78+
elseif(APPLE) # OSX
79+
if (DEFINED CMAKE_OSX_ARCHITECTURES)
80+
set(ACTUAL_TARGET ${CMAKE_OSX_ARCHITECTURES})
81+
else()
82+
set(ACTUAL_TARGET ${CMAKE_SYSTEM_PROCESSOR})
83+
endif()
84+
85+
86+
if (ACTUAL_TARGET MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
87+
SET(${OUT_VAR} TILEDB_MACOS-X86_64 PARENT_SCOPE)
88+
elseif (ACTUAL_TARGET STREQUAL arm64 OR ACTUAL_TARGET MATCHES "^aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
89+
SET(${OUT_VAR} TILEDB_MACOS-ARM64 PARENT_SCOPE)
90+
endif()
91+
else() # Linux
92+
SET(${OUT_VAR} TILEDB_LINUX-X86_64 PARENT_SCOPE)
93+
endif()
94+
endfunction()
95+
96+
function(fetch_prebuilt_tiledb)
97+
# Arguments
98+
set(options RELLIST_HASH)
99+
set(oneValueArgs VERSION ARTIFACT_NAME)
100+
set(multiValueArgs)
101+
cmake_parse_arguments(
102+
FETCH_PREBUILT_TILEDB
103+
"${options}"
104+
"${oneValueArgs}"
105+
"${multiValueArgs}"
106+
${ARGN}
107+
)
108+
109+
fetch_tiledb_release_list(${FETCH_PREBUILT_TILEDB_VERSION} ${FETCH_PREBUILT_TILEDB_RELLIST_HASH})
110+
111+
if(NOT FETCH_PREBUILT_TILEDB_ARTIFACT_NAME)
112+
detect_artifact_name(FETCH_PREBUILT_TILEDB_ARTIFACT_NAME)
113+
endif()
114+
115+
string(STRIP ${HASH_${FETCH_PREBUILT_TILEDB_ARTIFACT_NAME}} HASH_${FETCH_PREBUILT_TILEDB_ARTIFACT_NAME})
116+
FetchContent_Declare(
117+
tiledb-prebuilt
118+
URL ${URL_${FETCH_PREBUILT_TILEDB_ARTIFACT_NAME}}
119+
URL_HASH SHA256=${HASH_${FETCH_PREBUILT_TILEDB_ARTIFACT_NAME}}
120+
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
121+
)
122+
123+
FetchContent_MakeAvailable(
124+
tiledb-prebuilt
125+
)
126+
127+
set(TileDB_DIR "${tiledb-prebuilt_SOURCE_DIR}/lib/cmake/TileDB" PARENT_SCOPE)
128+
endfunction()

0 commit comments

Comments
 (0)