| 1 | #!/usr/bin/env bash |
| 2 | # Resolve tag/version/channel/prerelease for one desktop release run, shared by the |
| 3 | # build, publish, and mirror jobs so they agree on a single value. Reads the run's |
| 4 | # context from env and writes the four outputs to $GITHUB_OUTPUT. |
| 5 | # |
| 6 | # stable: from a historical desktop-v* run, an official manual recovery with |
| 7 | # `tag`, or the stable release orchestrator's workflow_call input. |
| 8 | # preview: public publication requires the approved Preview orchestrator; |
| 9 | # standalone Preview is limited to non-publishing signing checks. |
| 10 | # Legacy canary input is accepted for those checks. The version uses |
| 11 | # the orchestrator ordinal or, for a signing check, the run number. |
| 12 | set -euo pipefail |
| 13 | |
| 14 | stable_semver_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' |
| 15 | release_semver_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([0-9A-Za-z-]+)(\.[0-9A-Za-z-]+)*)?$' |
| 16 | preview_semver_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-preview\.(0|[1-9][0-9]*)$' |
| 17 | |
| 18 | if [ "${IN_CHANNEL:-stable}" = "preview" ] || [ "${IN_CHANNEL:-stable}" = "canary" ]; then |
| 19 | if [ "${IN_ORCHESTRATED:-false}" != "true" ] && \ |
| 20 | [ "${IN_PRODUCTION_SIGNING_SMOKE:-false}" != "true" ] && \ |
| 21 | [ "${IN_SIGNING_PREFLIGHT:-false}" != "true" ]; then |
| 22 | echo "::error::public Desktop Preview releases must be dispatched by release-preview.yml" >&2 |
| 23 | exit 1 |
| 24 | fi |
| 25 | if [ -n "${IN_TAG:-}" ]; then |
| 26 | echo "::error::Desktop Preview versions are synthesized from protected main-v2; tag must be empty" >&2 |
| 27 | exit 1 |
| 28 | fi |
| 29 | base="${IN_BASE_VERSION:?preview dispatch requires base_version}" |
| 30 | base="${base#v}" |
| 31 | base="${base#desktop-v}" |
| 32 | if [[ ! "$base" =~ $stable_semver_re ]]; then |
| 33 | echo "::error::preview base version must be MAJOR.MINOR.PATCH, got: $base" >&2 |
| 34 | exit 1 |
| 35 | fi |
| 36 | preview_number="${IN_PREVIEW_NUMBER:-${RUN_NUMBER:-}}" |
| 37 | if [[ ! "$preview_number" =~ ^(0|[1-9][0-9]*)$ ]]; then |
| 38 | echo "::error::preview number must be a non-negative integer, got: $preview_number" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | version="v${base}-preview.${preview_number}" |
| 42 | tag="desktop-${version}" |
| 43 | channel="preview" |
| 44 | prerelease="true" |
| 45 | notes_version="$version" |
| 46 | else |
| 47 | if [ -n "${IN_TAG:-}" ]; then |
| 48 | tag="${IN_TAG}" |
| 49 | elif [ "${EVENT_NAME:-}" = "workflow_dispatch" ]; then |
| 50 | echo "::error::stable dispatch requires tag" >&2 |
| 51 | exit 1 |
| 52 | else |
| 53 | tag="${REF_NAME:?stable release requires a tag input or ref name}" |
| 54 | fi |
| 55 | if [[ ! "$tag" =~ ^desktop-v(.+)$ ]] || [[ ! "${BASH_REMATCH[1]}" =~ $release_semver_re ]]; then |
| 56 | echo "::error::desktop release tag must be desktop-vMAJOR.MINOR.PATCH[-PRERELEASE], got: $tag" >&2 |
| 57 | exit 1 |
| 58 | fi |
| 59 | version="${tag#desktop-}" |
| 60 | if [[ "${version#v}" =~ $preview_semver_re ]]; then |
| 61 | echo "::error::Desktop Preview versions must use channel=preview without a Git tag, got: $tag" >&2 |
| 62 | exit 1 |
| 63 | fi |
| 64 | channel="stable" |
| 65 | case "$version" in |
| 66 | *-*) |
| 67 | prerelease="true" |
| 68 | notes_version="${version%%-*}" |
| 69 | ;; |
| 70 | *) |
| 71 | prerelease="false" |
| 72 | notes_version="$version" |
| 73 | ;; |
| 74 | esac |
| 75 | if [ "${EVENT_NAME:-}" = "workflow_dispatch" ] && \ |
| 76 | [ "${IN_ORCHESTRATED:-false}" != "true" ] && [ "$prerelease" = "true" ]; then |
| 77 | echo "::error::manual Desktop recovery accepts only desktop-vMAJOR.MINOR.PATCH" >&2 |
| 78 | exit 1 |
| 79 | fi |
| 80 | fi |
| 81 | |
| 82 | { |
| 83 | echo "tag=$tag" |
| 84 | echo "version=$version" |
| 85 | echo "channel=$channel" |
| 86 | echo "prerelease=$prerelease" |
| 87 | echo "notes_version=$notes_version" |
| 88 | } >>"$GITHUB_OUTPUT" |
| 89 | |
| 90 | echo "resolved: tag=$tag version=$version channel=$channel prerelease=$prerelease" |
| 91 |