Skip to content

Commit bb2a4ac

Browse files
authored
Install using poetry (#66)
* Allow a poetry type build
1 parent 07b137d commit bb2a4ac

File tree

9 files changed

+158
-1380
lines changed

9 files changed

+158
-1380
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ jobs:
2222
uploadLogs: true
2323
httpPort: 8008
2424

25+
test-poetry:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.x"
32+
- name: Run synapse
33+
uses: ./
34+
with:
35+
uploadLogs: true
36+
httpPort: 8008
37+
installer: "poetry"
38+
2539
test-baseurl:
2640
runs-on: ubuntu-latest
2741
steps:

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: 'Setup Synapse'
22
description: 'Deploys a synapse test server'
33
inputs:
4+
installer:
5+
description: 'Install method (options "poetry", "venv" [default])'
6+
default: 'venv'
47
uploadLogs:
58
description: 'Upload synapse logs at end'
69
required: true

create.js

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,63 @@ async function run() {
1010
try {
1111

1212
core.info(`Installing synapse...`);
13+
let installer = core.getInput("installer");
14+
if (installer == "")
15+
installer = "pip"
16+
1317

14-
// Lots of stuff here, from the setting up synapse page.
15-
await exec.exec("mkdir", ["-p", "synapse"]);
16-
process.chdir("synapse");
17-
await exec.exec("python", ["-m", "venv", "env"]);
18-
await exec.exec("env/bin/pip", ["install", "-q", "--upgrade", "pip"]);
19-
await exec.exec("env/bin/pip", ["install", "-q", "--upgrade", "setuptools"]);
20-
await exec.exec("env/bin/pip", ["install", "-q", "matrix-synapse"]);
18+
if (installer == "poetry") {
19+
// poetry requires a git checkout first
20+
await exec.exec("git", ["clone", "https://github.com/matrix-org/synapse"]);
21+
process.chdir("synapse");
22+
await exec.exec("python", ["-m", "pip", "install","pipx"]);
23+
await exec.exec("python", ["-m", "pipx", "ensurepath"]);
24+
await exec.exec("pipx", ["install", "poetry"]);
25+
await exec.exec("poetry", ["install", "--extras", "all"]);
26+
}
27+
else {
28+
// installing from pypi does not need the checkout.
29+
// Lots of stuff here, from the setting up synapse page.
30+
await exec.exec("mkdir", ["-p", "synapse"]);
31+
process.chdir("synapse");
32+
await exec.exec("python", ["-m", "venv", "env"]);
33+
await exec.exec("env/bin/pip", ["install", "-q", "--upgrade", "pip"]);
34+
await exec.exec("env/bin/pip", ["install", "-q", "--upgrade", "setuptools"]);
35+
await exec.exec("env/bin/pip", ["install", "-q", "matrix-synapse"]);
36+
}
2137
const customModules = core.getInput("customModules")
2238
if (customModules.length > 0) {
2339
const toLoad = customModules.split(',');
2440
for (let module of toLoad) {
25-
await exec.exec("env/bin/pip", ["install", "-q", module]);
41+
if (installer == "poetry") {
42+
await exec.exec("poetry", ["install", module]);
43+
} else {
44+
await exec.exec("env/bin/pip", ["install", "-q", module]);
45+
}
2646
}
27-
}
47+
}
2848
// homeserver.yaml is the default server config from synapse
2949

3050
core.info("Generating config...");
51+
if (installer == "poetry") {
52+
await exec.exec("poetry", [
53+
"run", "python",
54+
"-m", "synapse.app.homeserver",
55+
"--server-name", "localhost",
56+
"--config-path", "homeserver.yaml",
57+
"--generate-config",
58+
"--report-stats=no"
59+
]);
3160

32-
await exec.exec("env/bin/python3", [
33-
"-m", "synapse.app.homeserver",
34-
"--server-name", "localhost",
35-
"--config-path", "homeserver.yaml",
36-
"--generate-config",
37-
"--report-stats=no"
38-
]);
39-
61+
} else {
62+
await exec.exec("env/bin/python3", [
63+
"-m", "synapse.app.homeserver",
64+
"--server-name", "localhost",
65+
"--config-path", "homeserver.yaml",
66+
"--generate-config",
67+
"--report-stats=no"
68+
]);
69+
}
4070

4171
const port = core.getInput("httpPort");
4272
var public_baseurl = core.getInput("public_baseurl");
@@ -150,20 +180,29 @@ async function run() {
150180
detached: true,
151181
stdio: [ 'ignore', out, err ]
152182
}
153-
var child = spawn("env/bin/python3", [
154-
"-m", "synapse.app.homeserver",
155-
"--config-path", "homeserver.yaml",
156-
"--config-path", "additional.yaml",
157-
"--config-path", "custom.yaml"
158-
], options);
159-
183+
if (installer == "poetry" ) {
184+
var child = spawn("poetry", [
185+
"run", "python",
186+
"-m", "synapse.app.homeserver",
187+
"--config-path", "homeserver.yaml",
188+
"--config-path", "additional.yaml",
189+
"--config-path", "custom.yaml"
190+
], options);
191+
} else {
192+
var child = spawn("env/bin/python3", [
193+
"-m", "synapse.app.homeserver",
194+
"--config-path", "homeserver.yaml",
195+
"--config-path", "additional.yaml",
196+
"--config-path", "custom.yaml"
197+
], options);
198+
}
160199
core.saveState("synapse-pid", child.pid);
161200
core.info(`Waiting until C-S api is available`);
162201

163202

164203
const url = `http://localhost:${ port }/_matrix/client/versions`;
165204
var retry = 0;
166-
while (true) {
205+
while (retry < 20) {
167206
core.info("Checking endpoint...");
168207
const response = await checkFor200(url);
169208
core.info(`.. got ${response}`);
@@ -194,16 +233,16 @@ async function run() {
194233
// Short timeout because we have a larger retry loop around it
195234
// And the server should respond within ~500ms or is generally unhappy anyway
196235
async function checkFor200(target) {
197-
return new Promise((resolve, reject) => {
236+
return new Promise((resolve) => {
198237

199238
const req = http.get(target, {timeout: 500}, (res) => {
200239
resolve(res.statusCode);
201-
}).on('timeout', (e) => {
240+
}).on('timeout', () => {
202241
req.abort();
203242
resolve(0);
204-
}).on('error', (e) => {
243+
}).on('error', () => {
205244
resolve(0);
206-
});;
245+
});
207246
req.end();
208247
});
209248
}

destroy.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const core = require('@actions/core');
2-
const exec = require('@actions/exec');
32
const process = require('process');
43
const artifact = require('@actions/artifact');
54

@@ -42,7 +41,7 @@ async function run() {
4241
const options = {
4342
continueOnError: true
4443
}
45-
const uploadResult = await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
44+
await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
4645
}
4746
} catch (error) {
4847
core.setFailed(error.message);

dist/create/index.js

Lines changed: 69 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/create/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)