#!/bin/sh # Provision the ios-smoke account the live UI smoke suite runs as. Run as # an instance admin where the gitbay CLI is signed in; every step skips # what already exists, so a failed run is rerun as is. It creates the # account with a fresh SSH key (~/.ssh/gitbay-ios-smoke), makes it a krz # admin, sets its profile description, registers a PGP key, and pushes # the ios-smoke/ui-smoke-edit fixture the write flows work in: notes.txt # for testBlameAndEditFlows, and a ui-smoke branch divergent from main # for the merge-request flows. # LiveSmokeUITests asserts on the same values, so keep the two in step. set -eu user=ios-smoke key=$HOME/.ssh/gitbay-$user description='Live UI smoke account for gitbay-ios' pgp_email="$user+pgp@gitbay.org" [ -f "$key" ] || ssh-keygen -q -t ed25519 -N '' -C "$user" -f "$key" if ! gitbay admin user show "$user" --json > /dev/null 2>&1; then gitbay admin user create "$user" --email "$user@gitbay.org" --verified --key - < "$key.pub" fi gitbay org members add krz "$user" --role admin # Everything below runs as the account. The user's ssh config is ignored: # its identities and control socket would answer as the admin. smoke_ssh="ssh -F /dev/null -i $key -o IdentitiesOnly=yes" as_smoke() { $smoke_ssh git@gitbay.org "$@" } as_smoke profile set --description "'$description'" # The PGP key is a display fixture; its private half is discarded. if ! as_smoke pgp list --json | grep -q "$pgp_email"; then gnupg=$(mktemp -d /tmp/pgp.XXXXXX) GNUPGHOME=$gnupg gpg --batch --quiet --pinentry-mode loopback --passphrase '' \ --quick-generate-key "$user <$pgp_email>" ed25519 sign never GNUPGHOME=$gnupg gpg --armor --export "$pgp_email" | as_smoke pgp add GNUPGHOME=$gnupg gpgconf --kill all rm -rf "$gnupg" fi repo=$user/ui-smoke-edit url=ssh://git@gitbay.org/$repo.git work=$(mktemp -d) trap 'rm -rf "$work"' EXIT commit_in_work() { git -C "$work" add -A git -C "$work" -c user.name="$user" -c user.email="$user@gitbay.org" \ -c commit.gpgsign=false commit -q -m "$1" } push_work() { GIT_SSH_COMMAND="$smoke_ssh" git -C "$work" push -q "$url" "$1" } if as_smoke repo show "$repo" --json > /dev/null 2>&1; then echo "$repo exists" GIT_SSH_COMMAND="$smoke_ssh" git clone -q "$url" "$work" else as_smoke repo create "$repo" git -C "$work" init -q -b main cat > "$work/README.md" <<'EOF' # ui-smoke-edit A fixture repository for the gitbay-ios live UI smoke suite. `notes.txt` is edited by `testBlameAndEditFlows` on every run, and the `ui-smoke` branch is what the merge-request flows open merge requests from. Nothing in the app or the JSON API can seed a repository's first commit (that is a push), so the suite only checks that this repo exists and skips when it does not. `gitbayUITests/smoke-account.sh` in krz/gitbay-ios is what created it. EOF cat > "$work/notes.txt" <<'EOF' Scratch content for the live UI smoke suite. testBlameAndEditFlows opens this file and saves an edit through the app, which is how the file-editing path is verified end to end. The text does not matter; the file existing does. EOF commit_in_work 'fixture repo for the live smoke suite' push_work main fi # The MR flows open one merge request each way between ui-smoke and # main, so each side needs a commit the other lacks. Only a push can # make a branch, which is why this lives here and not in the suite. if ! as_smoke repo refs "$repo" --json | grep -q '"ui-smoke"'; then git -C "$work" checkout -q -b ui-smoke cat > "$work/ui-smoke.md" <<'EOF' This branch exists so the live UI smoke suite has a merge request to open. It is never merged: the suite opens merge requests both ways between it and main, and closes them again. EOF commit_in_work 'ui-smoke: a commit main does not have' push_work ui-smoke git -C "$work" checkout -q main cat > "$work/main.md" <<'EOF' The counterpart of ui-smoke.md: a commit on main that the ui-smoke branch does not have, so a merge request from main to ui-smoke has something to carry. EOF commit_in_work 'main: a commit ui-smoke does not have' push_work main fi echo "Mint the suite's token with:" echo " $smoke_ssh git@gitbay.org token create --name ui-smoke --scope full --ttl 30d"