generated from matrix-org/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
196 lines (182 loc) · 9.13 KB
/
single_sdk_tests.yml
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# This reusable workflow runs complement-crypto against _either_ a specific rust SDK commit or JS SDK commit.
#
# It does this by checking out the 'main' branch of complement-crypto then checking out the specific commit
# in the input. It runs single SDK only tests (e.g all JS clients _or_ all Rust clients, not a mixture).
name: 'Complement Crypto'
run-name: "Running Complement-Crypto"
permissions: read-all
on:
workflow_call:
inputs:
# TODO: we should improve the inputs here. We should also allow caller workflows the
# ability to run x-client tests if they wish.
use_js_sdk:
description: 'tag/commit/branch of the JS SDK to test against. If "." then the caller checkout is used. If "MATCHING_BRANCH" then it tries to use the same branch as another "." input, falling back to the default branch.'
required: false
default: ''
type: string
use_rust_sdk:
description: 'tag/commit/branch of the Rust SDK to test against. If "." then the caller checkout is used. If "MATCHING_BRANCH" then it tries to use the same branch as another "." input, falling back to the default branch.'
required: false
default: ''
type: string
use_complement_crypto:
description: 'tag/commit/branch of Complement Crypto to test against. If "." then the caller checkout is used. If "MATCHING_BRANCH" then it tries to use the same branch as another "." input, falling back to the default branch.'
required: false
default: 'main'
type: string
jobs:
tests:
runs-on: ubuntu-22.04
steps:
# At this stage we don't know which repo we have just checked out. We will reference this repo
# if the workflow uses '.'
- name: Checkout repo
uses: actions/checkout@v3
- name: Resolve branches
shell: bash
# these env vars will be modified and used in subsequent steps
env:
JS_SDK: ${{ inputs.use_js_sdk }}
RUST_SDK: ${{ inputs.use_rust_sdk }}
COMPLEMENT_CRYPTO: ${{ inputs.use_complement_crypto }}
run: |
# only 1 '.' is supported. Check it now.
count=0
input_name=""
for var_name in JS_SDK RUST_SDK COMPLEMENT_CRYPTO; do
if [ "${!var_name}" = "." ]; then
count=$((count + 1))
input_name=$var_name
echo "$var_name="${!var_name}"" >> $GITHUB_ENV
fi
done
if [ "$count" -gt 1 ]; then
echo "Error: this workflow does not support > 1 '.' input for use_js_sdk, use_rust_sdk, use_complement_crypto"
exit 1
elif [ "$count" -eq 0 ]; then
echo "No variables are set to '.' so skipping check for MATCHING_BRANCH"
exit 0
fi
# we need to run the resolve_branch.sh script but that's inside complement-crypto, and we don't
# know which branch to use of complement-crypto yet => chicken and egg problem. To break it, let's
# just always use the resolve_branch.sh script from 'main'
curl -o $PWD/resolve_branch.sh "https://raw.githubusercontent.com/matrix-org/complement-crypto/main/.github/workflows/resolve_branch.sh"
chmod +x $PWD/resolve_branch.sh
declare -A input_to_repo_url
input_to_repo_url["JS_SDK"]="matrix-org/matrix-js-sdk"
input_to_repo_url["RUST_SDK"]="matrix-org/matrix-rust-sdk"
input_to_repo_url["COMPLEMENT_CRYPTO"]="matrix-org/complement-crypto"
for var_name in JS_SDK RUST_SDK COMPLEMENT_CRYPTO; do
if [ "${!var_name}" = "MATCHING_BRANCH" ]; then
BRANCH=$(./resolve_branch.sh ${input_to_repo_url["$var_name"]})
echo "$var_name=$BRANCH" >> $GITHUB_ENV
else
echo "Using ${!var_name} for ${input_to_repo_url["$var_name"]}"
echo "$var_name=${!var_name}" >> $GITHUB_ENV
fi
done
# The aim of these two steps is to guarantee that complement-crypto is at `./complement-crypto`
- name: Checkout complement-crypto
if: ${{ inputs.use_complement_crypto != '.'}}
run: |
mkdir complement-crypto
(wget -O - "https://github.com/matrix-org/complement-crypto/archive/$COMPLEMENT_CRYPTO.tar.gz" | tar -xz --strip-components=1 -C complement-crypto)
- name: Symlink complement-crypto
if: ${{ inputs.use_complement_crypto == '.'}}
run: |
ln -s . complement-crypto
# Setup code we always need
- name: Pull synapse service v1.115.0 and mitmproxy
shell: bash
run: |
docker pull ghcr.io/matrix-org/synapse-service:v1.115.0
docker pull mitmproxy/mitmproxy:10.1.5
docker tag ghcr.io/matrix-org/synapse-service:v1.115.0 homeserver:latest
- name: Setup | Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: "Install Complement Dependencies"
shell: bash
run: |
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
# JS SDK only steps
# The aim is to provide the right location of the JS SDK to rebuild_js_sdk.sh
- name: Setup | Node.js LTS
if: ${{ inputs.use_js_sdk != '' }}
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: "Install JS SDK"
if: ${{ inputs.use_js_sdk != '' }}
shell: bash
run: |
echo "Installing matrix-js-sdk @ $JS_SDK"
YARN_PATH="https://github.com/matrix-org/matrix-js-sdk#$JS_SDK"
if [ "$JS_SDK" = "." ]; then
YARN_PATH="file:${{ github.workspace }}"
fi
(cd complement-crypto && ./rebuild_js_sdk.sh "matrix-js-sdk@$YARN_PATH")
# Rust SDK only steps.
# The aim is to guarantee that rust-sdk is either at '.' or './complement-crypto/rust-sdk'
# which we then pass to rebuild_rust_sdk.sh
- name: Setup | Rust
if: ${{ inputs.use_rust_sdk != '' }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: "Download Rust SDK" # no need to download rust SDK if we are using the local checkout.
if: ${{ inputs.use_rust_sdk != '' && inputs.use_rust_sdk != '.'}}
run: |
cd complement-crypto
mkdir rust-sdk
(wget -O - "https://github.com/matrix-org/matrix-rust-sdk/archive/$RUST_SDK.tar.gz" | tar -xz --strip-components=1 -C rust-sdk)
- name: Build Rust SDK
if: ${{ inputs.use_rust_sdk != '' }}
env:
RUST_SDK_DIR: ${{ inputs.use_rust_sdk == '.' && '..' || './rust-sdk' }}
run: |
echo "Compiling matrix-rust-sdk @ $RUST_SDK"
cd complement-crypto && ./install_uniffi_bindgen_go.sh && ./rebuild_rust_sdk.sh $RUST_SDK_DIR
- name: Build RPC client (rust)
if: ${{ inputs.use_rust_sdk != '' }}
env:
RUST_SDK_LIB_RELATIVE: ${{ inputs.use_rust_sdk == '.' && '/target/debug' || '/complement-crypto/rust-sdk/target/debug'}}
run: |
export LIBRARY_PATH="$(pwd)$RUST_SDK_LIB_RELATIVE"
export LD_LIBRARY_PATH="$(pwd)$RUST_SDK_LIB_RELATIVE"
cd complement-crypto && go build -tags=rust ./cmd/rpc
- name: Build RPC client (js)
if: ${{ inputs.use_js_sdk != '' }}
run: |
cd complement-crypto && go build -tags=jssdk ./cmd/rpc
# Run the tests
- name: Run Complement Crypto Tests
run: |
export LIBRARY_PATH="$(pwd)$RUST_SDK_LIB_RELATIVE"
export LD_LIBRARY_PATH="$(pwd)$RUST_SDK_LIB_RELATIVE"
export COMPLEMENT_CRYPTO_RPC_BINARY="$(pwd)/complement-crypto/rpc"
cd complement-crypto &&
set -o pipefail &&
go test -v -p 2 -count=1 -json -tags=$GO_TAGS -timeout 15m ./tests ./tests/$LANG_SPECIFIC_TESTS | gotestfmt
shell: bash # required for pipefail to be A Thing. pipefail is required to stop gotestfmt swallowing non-zero exit codes
env:
COMPLEMENT_BASE_IMAGE: homeserver
COMPLEMENT_ENABLE_DIRTY_RUNS: 1
COMPLEMENT_CRYPTO_MITMDUMP: mitm.dump
COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX: ${{ inputs.use_js_sdk != '' && 'jj' || 'rr' }} # TODO: brittle, we don't check rust-sdk input
COMPLEMENT_SHARE_ENV_PREFIX: PASS_
PASS_SYNAPSE_COMPLEMENT_DATABASE: sqlite
DOCKER_BUILDKIT: 1
GO_TAGS: ${{ inputs.use_js_sdk != '' && 'jssdk' || 'rust'}}
LANG_SPECIFIC_TESTS: ${{ inputs.use_js_sdk != '' && 'js' || 'rust'}}
RUST_SDK_LIB_RELATIVE: ${{ inputs.use_rust_sdk == '.' && '/target/debug' || '/complement-crypto/rust-sdk/target/debug'}}
- name: Upload logs
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: Logs - ${{ inputs.use_js_sdk != '' && 'jssdk' || 'rust'}}
path: |
./complement-crypto/**/logs/*
./complement-crypto/**/mitm.dump