|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +groupadd --gid ${BUILDER_GID} --force ${BUILDER_NAME} |
| 4 | +adduser --disabled-password --gecos '' --no-create-home $BUILDER_NAME --uid ${BUILDER_UID} --gid ${BUILDER_GID} |
| 5 | +adduser $BUILDER_NAME sudo |
| 6 | +echo "$BUILDER_NAME ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/$BUILDER_NAME |
| 7 | + |
| 8 | +# there may be a better way to continue building as a user builder with the same UID and GID as the host runner |
| 9 | +su -m $BUILDER_NAME << 'EOF' |
| 10 | +echo "User: $(whoami)" |
| 11 | +WORKSPACE=$(pwd) |
| 12 | +echo "Workspace directory: ${WORKSPACE}" |
| 13 | +
|
| 14 | +delete_linux_depends=false |
| 15 | +
|
| 16 | +build_focal=true |
| 17 | +build_windows=true |
| 18 | +build_macos=true |
| 19 | +
|
| 20 | +download_and_check_macos_sdk() { |
| 21 | + url="https://bitcoincore.org/depends-sources/sdks/Xcode-12.1-12A7403-extracted-SDK-with-libcxx-headers.tar.gz" |
| 22 | + output_file="Xcode-12.1-12A7403-extracted-SDK-with-libcxx-headers.tar.gz" |
| 23 | + expected_checksum="be17f48fd0b08fb4dcd229f55a6ae48d9f781d210839b4ea313ef17dd12d6ea5" |
| 24 | +
|
| 25 | + # Check if file exists |
| 26 | + if [[ -f "$output_file" ]]; then |
| 27 | + # Calculate checksum of the file |
| 28 | + actual_checksum=$(sha256sum "$output_file" 2>/dev/null | awk '{print $1}') |
| 29 | + if [[ -n $actual_checksum ]]; then |
| 30 | + # Compare checksums |
| 31 | + if [[ "$actual_checksum" == "$expected_checksum" ]]; then |
| 32 | + echo "MacOS SDK already exists and has the correct checksum. Skipping download." |
| 33 | + return |
| 34 | + fi |
| 35 | + fi |
| 36 | + fi |
| 37 | +
|
| 38 | + echo "Downloading MacOS SDK ..." |
| 39 | + # Download the file |
| 40 | + curl -L -o "$output_file" "$url" |
| 41 | +
|
| 42 | + # Calculate checksum of the downloaded file |
| 43 | + actual_checksum=$(sha256sum "$output_file" | awk '{print $1}') |
| 44 | +
|
| 45 | + # Compare checksums |
| 46 | + if [[ "$actual_checksum" != "$expected_checksum" ]]; then |
| 47 | + echo "ERROR: Downloaded MacOS SDK has an invalid checksum." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + echo "MacOS SDK downloaded successfully and has a valid checksum." |
| 52 | +} |
| 53 | +
|
| 54 | +delete_artefacts() { |
| 55 | + local release_name=$1 |
| 56 | +
|
| 57 | + if [[ "$release_name" = "windows" ]]; then |
| 58 | + ext=".exe" |
| 59 | + else |
| 60 | + ext="" |
| 61 | + fi |
| 62 | +
|
| 63 | + mkdir -p ${WORKSPACE}/releases/${release_name} |
| 64 | +
|
| 65 | + binaries=( |
| 66 | + "src/komodod" |
| 67 | + "src/wallet-utility" |
| 68 | + "src/komodo-tx" |
| 69 | + "src/komodo-cli" |
| 70 | + "src/komodo-test" |
| 71 | + "src/qt/komodo-qt" |
| 72 | + ) |
| 73 | +
|
| 74 | + for binary in "${binaries[@]}" |
| 75 | + do |
| 76 | + rm -f "${WORKSPACE}/${binary}${ext}" || false |
| 77 | + done |
| 78 | +
|
| 79 | + echo "Deleting artefacts from ${WORKSPACE} ..." |
| 80 | + # delete possible artefacts from previous build(s) |
| 81 | + find ${WORKSPACE}/src \( -name "*.a" -o -name "*.la" -o -name "*.o" -o -name "*.lo" -o -name "*.Plo" -o -name "*.Po" -o -name "*.lai" -o -name "*.dirstamp" \) -delete |
| 82 | + find ${WORKSPACE}/src \( -name "*.a" -o -name "*.la" -o -name "*.o" -o -name "*.lo" -o -name "*.Plo" -o -name "*.Po" -o -name "*.lai" -o -name "*.dirstamp" \) -path "*/.*" -delete |
| 83 | + rm -f ${WORKSPACE}/src/qt/moc_*.cpp # delete meta object code files, otherwise we will have MacOS after Linux/Windows build error |
| 84 | +} |
| 85 | +
|
| 86 | +copy_release() { |
| 87 | + local release_name=$1 |
| 88 | +
|
| 89 | + if [[ "$release_name" = "windows" ]]; then |
| 90 | + ext=".exe" |
| 91 | + else |
| 92 | + ext="" |
| 93 | + fi |
| 94 | +
|
| 95 | + mkdir -p ${WORKSPACE}/releases/${release_name} |
| 96 | +
|
| 97 | + binaries=( |
| 98 | + "src/komodod" |
| 99 | + "src/wallet-utility" |
| 100 | + "src/komodo-tx" |
| 101 | + "src/komodo-cli" |
| 102 | + "src/qt/komodo-qt" |
| 103 | + ) |
| 104 | +
|
| 105 | + for binary in "${binaries[@]}" |
| 106 | + do |
| 107 | + case $release_name in |
| 108 | + windows) |
| 109 | + bash -c "/usr/bin/x86_64-w64-mingw32-strip ${WORKSPACE}/${binary}${ext}" || false |
| 110 | + ;; |
| 111 | + macos) |
| 112 | + bash -c "${WORKSPACE}/depends/x86_64-apple-darwin/native/bin/x86_64-apple-darwin-strip ${WORKSPACE}/${binary}${ext}" || false |
| 113 | + ;; |
| 114 | + *) |
| 115 | + strip "${WORKSPACE}/${binary}${ext}" || false |
| 116 | + ;; |
| 117 | + esac |
| 118 | + cp -f "${WORKSPACE}/${binary}${ext}" "${WORKSPACE}/releases/${release_name}/" |
| 119 | + done |
| 120 | +
|
| 121 | + case $release_name in |
| 122 | + xenial) |
| 123 | + echo "Performing actions for Xenial..." |
| 124 | + mv "${WORKSPACE}/releases/${release_name}/komodo-qt" "${WORKSPACE}/releases/${release_name}/komodo-qt-linux" |
| 125 | + ;; |
| 126 | + focal) |
| 127 | + echo "Performing actions for Focal..." |
| 128 | + mv "${WORKSPACE}/releases/${release_name}/komodo-qt" "${WORKSPACE}/releases/${release_name}/komodo-qt-linux" |
| 129 | + ;; |
| 130 | + windows) |
| 131 | + echo "Performing actions for Windows..." |
| 132 | + mv "${WORKSPACE}/releases/${release_name}/komodo-qt${ext}" "${WORKSPACE}/releases/${release_name}/komodo-qt-windows${ext}" |
| 133 | + ;; |
| 134 | + macos) |
| 135 | + echo "Performing actions for MacOS..." |
| 136 | + bash -c "make deploy" || false |
| 137 | + cp -f ${WORKSPACE}/*.dmg "${WORKSPACE}/releases/${release_name}/" |
| 138 | + mv "${WORKSPACE}/releases/${release_name}/komodo-qt${ext}" "${WORKSPACE}/releases/${release_name}/komodo-qt-mac${ext}" |
| 139 | + ;; |
| 140 | + *) |
| 141 | + echo "Unknown release name: $release_name" |
| 142 | + ;; |
| 143 | + esac |
| 144 | +} |
| 145 | +
|
| 146 | +emulate_build() { |
| 147 | + for folder in macos windows focal; do |
| 148 | + mkdir -p ${WORKSPACE}/releases/${folder} |
| 149 | + for file in komodo-qt komodo-cli komodo-tx wallet-utility komodod; do |
| 150 | + extension="" |
| 151 | + case ${folder} in |
| 152 | + focal) |
| 153 | + [[ "$file" == "komodo-qt" ]] && file=${file}-linux |
| 154 | + ;; |
| 155 | + macos) |
| 156 | + [[ "$file" == "komodo-qt" ]] && file=${file}-mac |
| 157 | + ;; |
| 158 | + windows) |
| 159 | + extension=".exe" |
| 160 | + [[ "$file" == "komodo-qt" ]] && file=${file}-windows |
| 161 | + ;; |
| 162 | + esac |
| 163 | + echo test > ${WORKSPACE}/releases/${folder}/${file}${extension} |
| 164 | + done |
| 165 | + done |
| 166 | + echo test > ${WORKSPACE}/releases/macos/KomodoOcean-0.8.1-beta1.dmg |
| 167 | +} |
| 168 | +
|
| 169 | +if true; then |
| 170 | + # Check if awk command exists |
| 171 | + command -v awk >/dev/null 2>&1 || { echo >&2 "ERROR: awk command not found."; exit 1; } |
| 172 | + # Check if sha256sum command exists |
| 173 | + command -v sha256sum >/dev/null 2>&1 || { echo >&2 "ERROR: sha256sum command not found."; exit 1; } |
| 174 | +
|
| 175 | + ### focal |
| 176 | + if [[ "${build_focal}" = "true" ]]; then |
| 177 | +
|
| 178 | + # delete old depends binaries (from previous linux version, bcz it's x86_64-unknown-linux-gnu also) |
| 179 | + if [[ "${delete_linux_depends}" = true ]]; then |
| 180 | + rm -rf ${WORKSPACE}/depends/built/x86_64-unknown-linux-gnu |
| 181 | + rm -rf ${WORKSPACE}/depends/x86_64-unknown-linux-gnu |
| 182 | + fi |
| 183 | + # delete possible artefacts from previous build(s) |
| 184 | + delete_artefacts focal |
| 185 | + bash -c 'zcutil/build.sh -j'$(expr $(nproc) - 1) |
| 186 | + copy_release focal |
| 187 | + fi |
| 188 | +
|
| 189 | + ### windows |
| 190 | + if [[ "${build_windows}" = "true" ]]; then |
| 191 | + delete_artefacts windows |
| 192 | + bash -c 'zcutil/build-win.sh -j'$(expr $(nproc) - 1) |
| 193 | + copy_release windows |
| 194 | + fi |
| 195 | +
|
| 196 | + ### macos |
| 197 | + if [[ "${build_macos}" = "true" ]]; then |
| 198 | + download_and_check_macos_sdk |
| 199 | + delete_artefacts macos |
| 200 | + bash -c 'zcutil/build-mac-cross.sh -j'$(expr $(nproc) - 1) |
| 201 | + copy_release macos |
| 202 | + fi |
| 203 | +else |
| 204 | + emulate_build |
| 205 | + # all environment variables of docker container are accessible here, |
| 206 | + # you can use BUILDER_NAME or GITHUB_SHA, or GITHUB_ACTOR, etc. |
| 207 | +fi |
| 208 | +EOF |
| 209 | + |
| 210 | + |
0 commit comments