|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -o errexit -o noclobber -o nounset -o pipefail |
| 3 | + |
| 4 | +: "${ARTIFACTS_DIR:=$(realpath -m artifacts)}" |
| 5 | +: "${ASSETS_DIR:=$(realpath -m assets)}" |
| 6 | +readonly ARTIFACTS_DIR ASSETS_DIR TAG_NAME="${1:?Usage: ${BASH_SOURCE[0]} <tag-name>}" |
| 7 | +[[ ! -a "${ARTIFACTS_DIR}" && ! -a "${ASSETS_DIR}" ]] || { |
| 8 | + echo 'One or more output directories already exist.' |
| 9 | + printf 'Please delete the following directories to avoid errors:\n %s\n %s\n' "${ARTIFACTS_DIR}" "${ASSETS_DIR}" |
| 10 | + exit 2 |
| 11 | +} |
| 12 | +printf 'Creating output directories:\n %s\n %s\n' "${ARTIFACTS_DIR}" "${ASSETS_DIR}" |
| 13 | +mkdir -p "${ARTIFACTS_DIR}" "${ASSETS_DIR}" |
| 14 | + |
| 15 | +# Fetch the workflow runs for the tag. |
| 16 | +echo "Fetching workflow run info for: ${TAG_NAME}" |
| 17 | +runsList=$(gh run list --branch "${TAG_NAME}" --json 'name,number,databaseId,status,url,displayTitle') |
| 18 | +[[ -n "${runsList}" && "${runsList}" != '[]' ]] || { |
| 19 | + echo "Found no workflow runs for: ${TAG_NAME}" |
| 20 | + exit 3 |
| 21 | +} |
| 22 | +title=$(jq --raw-output 'first.displayTitle' <<< "${runsList}") |
| 23 | +echo "Found workflow run info: ${title}" |
| 24 | + |
| 25 | +# Check all workflows have completed. |
| 26 | +incomplete=$(jq --raw-output '.[]|select(.status != "completed")|[" ",.url,.name,.status]|join(" - ")' <<< "${runsList}") |
| 27 | +[[ -z "${incomplete}" ]] || { |
| 28 | + printf 'The following workflows are incomplete:\n%s\n' "${incomplete}" |
| 29 | + exit 4 |
| 30 | +} |
| 31 | + |
| 32 | +# Fetch the build artifacts. |
| 33 | +buildRunId=$(jq --raw-output '.[]|select(.name == "Build and Test").databaseId' <<< "${runsList}") |
| 34 | +docRunId=$(jq --raw-output '.[]|select(.name == "Documentation").databaseId' <<< "${runsList}") |
| 35 | +[[ -n "${buildRunId}" && -n "${docRunId}" ]] || { |
| 36 | + echo "Failed to find run IDs for build (${buildRunId}) and/or doc (${docRunId}) workflow runs." |
| 37 | + exit 5 |
| 38 | +} |
| 39 | + |
| 40 | +echo "Fetching artifacts for build run: ${buildRunId}" |
| 41 | +gh run download "${buildRunId}" --dir "${ARTIFACTS_DIR}" |
| 42 | + |
| 43 | +echo "Fetching artifacts for docs run ${docRunId}" |
| 44 | +gh run download "${docRunId}" --dir "${ARTIFACTS_DIR}" |
| 45 | + |
| 46 | +# Process the build artifacts into release assets. |
| 47 | +echo 'Compressing Linux and macOS binaries' |
| 48 | +find "${ARTIFACTS_DIR}" -maxdepth 1 -type d -name 'dokit-*' \ |
| 49 | + -not -name '*-cov.*' -not -name '*.win.*' -not -name '*.AppImage' \ |
| 50 | + -execdir tar -cJvf "${ASSETS_DIR}/{}.txz" --transform 's|^\./||' '{}' \; |
| 51 | + |
| 52 | +echo 'Compressing Windows binaries' |
| 53 | +find "${ARTIFACTS_DIR}" -maxdepth 1 -type d -name 'dokit-*.win.*' -not -name '*-cov.*' \ |
| 54 | + -execdir zip -9 -r "${ASSETS_DIR}/{}.zip" '{}' \; |
| 55 | + |
| 56 | +echo 'Compressing test results' |
| 57 | +( cd "${ARTIFACTS_DIR}"; zip -9 -r "${ASSETS_DIR}/test-results.zip" 'coverage-report' 'test-results-'* ) |
| 58 | + |
| 59 | +echo 'Copying AppImages' |
| 60 | +find "${ARTIFACTS_DIR}" -type f -name '*.AppImage' -not -name '*-cov.*AppImage' -exec cp -av {} "${ASSETS_DIR}" \; |
| 61 | + |
| 62 | +echo 'Compressing docs' |
| 63 | +find "${ARTIFACTS_DIR}" -maxdepth 1 -type d -name '*-docs' -execdir zip -9 -r "${ASSETS_DIR}/{}.zip" '{}' \; |
| 64 | + |
| 65 | +# Create a new (draft) release. |
| 66 | +echo "Creating new draft release, with $(ls -1a "${ASSETS_DIR}" | wc -l) assets" |
| 67 | +lin=$(find "$ASSETS_DIR" -name '*.gcc.*.AppImage' -printf '%f\n' | sort -V | tail -n1) |
| 68 | +mac=$(find "$ASSETS_DIR" -name '*.macos-*.arm64-x86_64.clang.*' -printf '%f\n' | sort -V | tail -n1) |
| 69 | +win=$(find "$ASSETS_DIR" -name '*.win.x86-64.msvc.*.portable.zip' -printf '%f\n' | sort -V | tail -n1) |
| 70 | +readonly baseUrl="https://github.com/pcolby/dokit/releases/download/${TAG_NAME}" lin mac win |
| 71 | +gh release create "${TAG_NAME}" --draft --generate-notes --notes-file <(cat <<-- |
| 72 | + _Add release notes here._ |
| 73 | +
|
| 74 | + ### Recommended Downloads |
| 75 | +
|
| 76 | + Feel free to download any of the assets below, but the recommended starting point would be: |
| 77 | +
|
| 78 | + * Linux: [${lin}](${baseUrl}/${lin}) |
| 79 | + * macOS: [${mac}](${baseUrl}/${mac}) - tip: \`brew install qt6\` |
| 80 | + * Windows: [${win}](${baseUrl}/${win}) - tip: run the included \`vc_redist.x64.exe\` if you don't have the necessary Microsoft Visual C++ runtime installed already. |
| 81 | + - |
| 82 | +) --verify-tag "${ASSETS_DIR}/"* |
| 83 | +echo 'Done' |
0 commit comments