~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
57 lines · 2.3 KB Raw History
#!/bin/sh
set -eu

fail() {
  printf '%s\n' "$1" >&2
  exit 1
}

# Knotless mounts the checkout from the runner into the container.
checkout=$(pwd -P)
. "$checkout/scripts/release-tags.sh"
repo_git() {
  git -c "safe.directory=$checkout" "$@"
}

ref=${KNOTLESS_RUN_REF:?Knotless did not provide a Git ref.}
run_object=${KNOTLESS_RUN_SHA:?Knotless did not provide a Git object ID.}
head_commit=$(repo_git rev-parse --verify HEAD)

case "$ref" in
  refs/heads/main)
    [ "$run_object" = "$head_commit" ] || fail "The main checkout does not match the Knotless run."
    object=$head_commit
    ;;
  refs/tags/v*|refs/tags/testflight/v*)
    if ! git check-ref-format "$ref" ||
      ! printf '%s\n' "${ref#refs/tags/}" | LC_ALL=C grep -Eq -e "$app_store_tag_pattern" -e "$testflight_tag_pattern"; then
      fail "Use an App Store tag such as v0.1.0 or a TestFlight tag such as testflight/v0.1.0-beta.1."
    fi
    object=$(repo_git rev-parse --verify "$ref") || fail "The checkout does not contain the release tag."
    tag_commit=$(repo_git rev-parse --verify "${object}^{commit}") || fail "The release tag does not point to a commit."
    [ "$tag_commit" = "$head_commit" ] || fail "The release tag does not point to the checked-out commit."
    if [ "$run_object" != "$object" ] && [ "$run_object" != "$tag_commit" ]; then
      fail "The release tag does not match the Knotless run."
    fi
    ;;
  *)
    fail "The workflow can push main and version tags."
    ;;
esac

: "${GITHUB_MIRROR_KEY:?Set the GITHUB_MIRROR_KEY secret in Knotless.}"
umask 077
ssh_dir=$(mktemp -d /tmp/oldfella-mirror.XXXXXX)
trap 'rm -rf "$ssh_dir"' EXIT
trap 'exit 1' HUP INT TERM
printf '%s\n' "$GITHUB_MIRROR_KEY" > "$ssh_dir/key"
unset GITHUB_MIRROR_KEY

# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
cat > "$ssh_dir/known_hosts" <<'EOF'
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
EOF
export GIT_SSH_COMMAND="ssh -F /dev/null -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
  -o HostKeyAlgorithms=ssh-ed25519 -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=$ssh_dir/known_hosts -i $ssh_dir/key"

repo_git push --no-follow-tags --porcelain git@github.com:geesawra/old-fella-mirror.git "$object:$ref"