gitbayUITests/smoke-account.sh
112 lines · 4192 bytes · executable
3 symbols in this file
1#!/bin/sh
2# Provision the ios-smoke account the live UI smoke suite runs as. Run as
3# an instance admin where the gitbay CLI is signed in; every step skips
4# what already exists, so a failed run is rerun as is. It creates the
5# account with a fresh SSH key (~/.ssh/gitbay-ios-smoke), makes it a krz
6# admin, sets its profile description, registers a PGP key, and pushes
7# the ios-smoke/ui-smoke-edit fixture the write flows work in: notes.txt
8# for testBlameAndEditFlows, and a ui-smoke branch divergent from main
9# for the merge-request flows.
10# LiveSmokeUITests asserts on the same values, so keep the two in step.
11set -eu
12
13user=ios-smoke
14key=$HOME/.ssh/gitbay-$user
15description='Live UI smoke account for gitbay-ios'
16pgp_email="$user+pgp@gitbay.org"
17
18[ -f "$key" ] || ssh-keygen -q -t ed25519 -N '' -C "$user" -f "$key"
19
20if ! gitbay admin user show "$user" --json > /dev/null 2>&1; then
21 gitbay admin user create "$user" --email "$user@gitbay.org" --verified --key - < "$key.pub"
22fi
23gitbay org members add krz "$user" --role admin
24
25# Everything below runs as the account. The user's ssh config is ignored:
26# its identities and control socket would answer as the admin.
27smoke_ssh="ssh -F /dev/null -i $key -o IdentitiesOnly=yes"
28as_smoke() {
29 $smoke_ssh git@gitbay.org "$@"
30}
31
32as_smoke profile set --description "'$description'"
33
34# The PGP key is a display fixture; its private half is discarded.
35if ! as_smoke pgp list --json | grep -q "$pgp_email"; then
36 gnupg=$(mktemp -d /tmp/pgp.XXXXXX)
37 GNUPGHOME=$gnupg gpg --batch --quiet --pinentry-mode loopback --passphrase '' \
38 --quick-generate-key "$user <$pgp_email>" ed25519 sign never
39 GNUPGHOME=$gnupg gpg --armor --export "$pgp_email" | as_smoke pgp add
40 GNUPGHOME=$gnupg gpgconf --kill all
41 rm -rf "$gnupg"
42fi
43
44repo=$user/ui-smoke-edit
45url=ssh://git@gitbay.org/$repo.git
46work=$(mktemp -d)
47trap 'rm -rf "$work"' EXIT
48
49commit_in_work() {
50 git -C "$work" add -A
51 git -C "$work" -c user.name="$user" -c user.email="$user@gitbay.org" \
52 -c commit.gpgsign=false commit -q -m "$1"
53}
54
55push_work() {
56 GIT_SSH_COMMAND="$smoke_ssh" git -C "$work" push -q "$url" "$1"
57}
58
59if as_smoke repo show "$repo" --json > /dev/null 2>&1; then
60 echo "$repo exists"
61 GIT_SSH_COMMAND="$smoke_ssh" git clone -q "$url" "$work"
62else
63 as_smoke repo create "$repo"
64 git -C "$work" init -q -b main
65 cat > "$work/README.md" <<'EOF'
66# ui-smoke-edit
67
68A fixture repository for the gitbay-ios live UI smoke suite. `notes.txt`
69is edited by `testBlameAndEditFlows` on every run, and the `ui-smoke`
70branch is what the merge-request flows open merge requests from.
71
72Nothing in the app or the JSON API can seed a repository's first commit
73(that is a push), so the suite only checks that this repo exists and
74skips when it does not. `gitbayUITests/smoke-account.sh` in krz/gitbay-ios
75is what created it.
76EOF
77 cat > "$work/notes.txt" <<'EOF'
78Scratch content for the live UI smoke suite.
79
80testBlameAndEditFlows opens this file and saves an edit through the app,
81which is how the file-editing path is verified end to end. The text does
82not matter; the file existing does.
83EOF
84 commit_in_work 'fixture repo for the live smoke suite'
85 push_work main
86fi
87
88# The MR flows open one merge request each way between ui-smoke and
89# main, so each side needs a commit the other lacks. Only a push can
90# make a branch, which is why this lives here and not in the suite.
91if ! as_smoke repo refs "$repo" --json | grep -q '"ui-smoke"'; then
92 git -C "$work" checkout -q -b ui-smoke
93 cat > "$work/ui-smoke.md" <<'EOF'
94This branch exists so the live UI smoke suite has a merge request to
95open. It is never merged: the suite opens merge requests both ways
96between it and main, and closes them again.
97EOF
98 commit_in_work 'ui-smoke: a commit main does not have'
99 push_work ui-smoke
100
101 git -C "$work" checkout -q main
102 cat > "$work/main.md" <<'EOF'
103The counterpart of ui-smoke.md: a commit on main that the ui-smoke
104branch does not have, so a merge request from main to ui-smoke has
105something to carry.
106EOF
107 commit_in_work 'main: a commit ui-smoke does not have'
108 push_work main
109fi
110
111echo "Mint the suite's token with:"
112echo " $smoke_ssh git@gitbay.org token create --name ui-smoke --scope full --ttl 30d"