summaryrefslogtreecommitdiff
path: root/.github/scripts/macos-qt-cache-key.sh
blob: 06359737ae37686f4514275f2bbe642351c8d3ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
set -euo pipefail

QT_VERSION=5.15.18
QT_SOURCE_SHA256=cea1fbabf02455f3f0e8eaa839f5d6f45cdb56b62c8a83af5c1d00ac05f912ea
QT_CACHE_EPOCH=1
QT_SOURCE_URL="https://download.qt.io/archive/qt/5.15/${QT_VERSION}/single/qt-everywhere-opensource-src-${QT_VERSION}.tar.xz"

macos_qt_script_dir() {
  cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
  pwd
}

macos_qt_sha256_file() {
  if command -v shasum >/dev/null 2>&1; then
    shasum -a 256 "$1" | awk '{print $1}'
  elif command -v sha256sum >/dev/null 2>&1; then
    sha256sum "$1" | awk '{print $1}'
  else
    echo "No SHA-256 tool found; expected shasum or sha256sum" >&2
    return 1
  fi
}

macos_qt_sha256_stream() {
  if command -v shasum >/dev/null 2>&1; then
    shasum -a 256 | awk '{print $1}'
  elif command -v sha256sum >/dev/null 2>&1; then
    sha256sum | awk '{print $1}'
  else
    echo "No SHA-256 tool found; expected shasum or sha256sum" >&2
    return 1
  fi
}

macos_qt_script_hash() {
  local script_dir
  script_dir="$(macos_qt_script_dir)"

  {
    for script in build-qt-macos.sh macos-qt-cache-key.sh; do
      local path="${script_dir}/${script}"
      if [ ! -f "$path" ]; then
        echo "Missing Qt cache input script: $path" >&2
        return 1
      fi
      printf '%s  %s\n' "$(macos_qt_sha256_file "$path")" "$script"
    done
  } | macos_qt_sha256_stream
}

macos_qt_cache_key() {
  local arch="$1"
  local runner="$2"
  local deployment_target="$3"
  local script_hash
  script_hash="$(macos_qt_script_hash)"

  printf 'qt-macos-%s-%s-%s-min%s-epoch%s-%s\n' \
    "$arch" \
    "$runner" \
    "$QT_VERSION" \
    "$deployment_target" \
    "$QT_CACHE_EPOCH" \
    "$script_hash"
}

usage() {
  cat <<'USAGE'
Usage: macos-qt-cache-key.sh --arch ARCH --runner RUNNER --deployment-target VERSION [--github-output]

Prints the exact GitHub Actions cache key for the pinned macOS Qt build.
USAGE
}

main() {
  local arch=""
  local runner=""
  local deployment_target=""
  local github_output=0

  while [ "$#" -gt 0 ]; do
    case "$1" in
      --arch)
        arch="$2"
        shift 2
        ;;
      --runner)
        runner="$2"
        shift 2
        ;;
      --deployment-target)
        deployment_target="$2"
        shift 2
        ;;
      --github-output)
        github_output=1
        shift
        ;;
      --help|-h)
        usage
        exit 0
        ;;
      *)
        echo "Unknown argument: $1" >&2
        usage >&2
        exit 2
        ;;
    esac
  done

  if [ -z "$arch" ] || [ -z "$runner" ] || [ -z "$deployment_target" ]; then
    usage >&2
    exit 2
  fi

  case "${arch}:${runner}:${deployment_target}" in
    arm64:macos-15:11.0|x86_64:macos-15-intel:10.13)
      ;;
    *)
      echo "Unsupported macOS Qt build tuple: arch=${arch}, runner=${runner}, deployment_target=${deployment_target}" >&2
      exit 2
      ;;
  esac

  local key
  key="$(macos_qt_cache_key "$arch" "$runner" "$deployment_target")"
  printf '%s\n' "$key"

  if [ "$github_output" -eq 1 ]; then
    if [ -z "${GITHUB_OUTPUT:-}" ]; then
      echo "--github-output requires GITHUB_OUTPUT to be set" >&2
      exit 2
    fi
    {
      printf 'key=%s\n' "$key"
      printf 'version=%s\n' "$QT_VERSION"
      printf 'source_url=%s\n' "$QT_SOURCE_URL"
      printf 'source_sha256=%s\n' "$QT_SOURCE_SHA256"
      printf 'cache_epoch=%s\n' "$QT_CACHE_EPOCH"
    } >> "$GITHUB_OUTPUT"
  fi
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
  main "$@"
fi