Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scx1332/goth test #599

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
99d42ff
test(examples): docs-examples and test script draft
mgordel Sep 18, 2023
4a299d6
test(examples): docs-examples and test script draft
mgordel Sep 18, 2023
416bf53
test(examples): goth ci debug
mgordel Sep 18, 2023
3e42743
test(examples): goth ci debug
mgordel Sep 18, 2023
79cf8c1
test(examples): goth ci debug
mgordel Sep 19, 2023
9ca29d4
test(examples): goth ci debug
mgordel Sep 19, 2023
cba57b2
test(examples): goth ci debug
mgordel Sep 19, 2023
0bd7202
test(examples): goth ci debug
mgordel Sep 19, 2023
330ae8b
test(examples): goth ci debug
mgordel Sep 19, 2023
60805a7
test(examples): goth ci debug 2
mgordel Sep 19, 2023
9a29755
test(examples): ci debug
mgordel Sep 19, 2023
0931959
test(examples): added assertions for errors
mgordel Sep 19, 2023
0392f13
test(examples): added assertions for errors
mgordel Sep 19, 2023
e366264
test(examples): added assertions for errors
mgordel Sep 19, 2023
a13c7bf
test(examples): added assertions for errors
mgordel Sep 19, 2023
b042be5
test(examples): added assertions for errors
mgordel Sep 19, 2023
9098abb
test(examples): added assertions for errors
mgordel Sep 19, 2023
a8d0632
test(examples): added chalk for logging
mgordel Sep 20, 2023
ea7ce19
test(examples): added no-goth arg
mgordel Sep 20, 2023
5f7f65a
test(examples): fixed formatting
mgordel Sep 20, 2023
56fe571
test(examples): added examples index
mgordel Sep 20, 2023
96435ee
test(examples): fixed examples
mgordel Sep 20, 2023
9f08e13
test(examples): fixed examples
mgordel Sep 20, 2023
bf1cf03
test(examples): fixed examples
mgordel Sep 20, 2023
51a22d4
test(examples): fixed examples
mgordel Sep 20, 2023
d850b47
test(examples): fixed examples
mgordel Sep 20, 2023
3c7f7bf
test(examples): fixed examples
mgordel Sep 20, 2023
9032f3a
test(examples): fixed examples
mgordel Sep 20, 2023
6158a74
test(examples): fixed examples
mgordel Sep 20, 2023
94dfdfd
test(examples): fixed examples
mgordel Sep 20, 2023
88909e0
test(examples): fixed examples
mgordel Sep 20, 2023
2ad34c2
test(examples): fixed yacat examples
mgordel Sep 21, 2023
c90975d
test(examples): skip examples with batch bug
mgordel Sep 21, 2023
7495e54
test(examples): added skipping feat
mgordel Sep 21, 2023
97d69ff
test(examples): removed rinkeby from goth setup
mgordel Sep 21, 2023
15fa554
test(examples): removed rinkeby from goth setup
mgordel Sep 21, 2023
32fce05
test(examples): removed rinkeby from goth setup
mgordel Sep 21, 2023
2abb16d
test(examples): fixed list
mgordel Sep 21, 2023
b61b408
test(examples): fixed yacat args
mgordel Sep 21, 2023
cd55201
test(examples): fixed yacat args
mgordel Sep 21, 2023
3cc8907
test(examples): fixed yacat args
mgordel Sep 21, 2023
92c584f
test(examples): rollback rinkeby for goth
mgordel Sep 22, 2023
ef62fdc
test(examples): goth debug
mgordel Sep 22, 2023
8df194f
test(examples): goth debug
mgordel Sep 22, 2023
b0b6c3f
test(examples): goth debug
mgordel Sep 22, 2023
07b1a27
test(examples): goth debug
mgordel Sep 25, 2023
77a2671
test(examples): goth debug
mgordel Sep 25, 2023
a57d8d2
test(examples): goth debug
mgordel Sep 25, 2023
7f1e3fd
test(examples): goth debug
mgordel Sep 25, 2023
25787ec
test(examples): goth debug
mgordel Sep 25, 2023
a9f0019
test(examples): goth debug
mgordel Sep 25, 2023
b830493
test(examples): goth min ver
mgordel Sep 25, 2023
0b43366
test(examples): fixed regexp matching
mgordel Sep 25, 2023
3395e34
test(examples): fixed regexp matching
mgordel Sep 25, 2023
36c0e3a
test(examples): fixed ci config
mgordel Sep 25, 2023
6aa1e91
test(examples): fixed ci config
mgordel Sep 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/examples-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Nightly Examples Tests

on:
schedule:
# run this workflow every day at 2:00 AM UTC
- cron: "0 4 * * *"

# Allows triggering the workflow manually
workflow_dispatch:

push:
branches:
- "test/JST-363/example-tests"

jobs:
prepare-matrix-master-only:
name: Prepare matrix JSON
runs-on: ubuntu-latest
outputs:
matrix-json: ${{ steps.get-matrix.outputs.matrix }}
steps:
# prepares JSON object representing strategy matrix with only the master branch
- name: Get matrix JSON
id: get-matrix
run: echo "::set-output name=matrix::{\"include\":[{\"branch\":\"master\"}]}"

goth-tests:
runs-on: goth
needs: prepare-matrix-master-only
strategy:
matrix: ${{ fromJson(needs.prepare-matrix-master-only.outputs.matrix-json) }}
fail-fast: false
name: Run example tests (nightly) on ${{ matrix.branch }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Build golem-js
run: |
sudo apt-get update -y
sudo apt-get install -y build-essential
npm install
npm run build
npm install --prefix examples
npm install ts-node

- name: Configure python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install goth
run: |
pip install goth>=0.15.3
rm -rf ../goth/assets
python -m goth create-assets ../goth/assets
sed -Ezi 's/(use\-proxy:\s)(True)/\1False/mg' ../goth/assets/goth-config.yml
sed -Ezi 's/(use\-prerelease:\s)(false)/\1true\n release-tag: "0.13.0-rc21"/mg' ../goth/assets/goth-config.yml
sed -i '/^ENTRYPOINT/i ENV YAGNA_AUTOCONF_APPKEY=try_golem' ../goth/assets/docker/yagna-goth-deb.Dockerfile

- name: Disconnect Docker containers from default network
continue-on-error: true
# related to this issue: https://github.com/moby/moby/issues/23302
run: |
docker network inspect docker_default
sudo apt-get install -y jq
docker network inspect docker_default | jq ".[0].Containers | map(.Name)[]" | tee /dev/stderr | xargs --max-args 1 -- docker network disconnect -f docker_default

- name: Remove Docker containers
continue-on-error: true
run: docker rm -f $(docker ps -a -q)

- name: Restart Docker daemon
# related to this issue: https://github.com/moby/moby/issues/23302
run: sudo systemctl restart docker

- name: Log in to GitHub Docker repository
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{github.actor}} --password-stdin

- name: Run test suite
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm run test:examples

- name: Upload test logs
uses: actions/upload-artifact@v2
if: always()
with:
name: goth-logs
path: /tmp/goth-tests

# Only relevant for self-hosted runners
- name: Remove test logs
if: always()
run: rm -rf /tmp/goth-tests
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ jobs:
run: rm -rf .cypress
#endregion

#region Examples test execution
- name: Run the Examples tests using Goth
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm run test:examples

- name: Upload test logs
uses: actions/upload-artifact@v2
if: always()
with:
name: goth-logs
path: /tmp/goth-tests

# Only relevant for self-hosted runners
- name: Remove test logs
if: always()
run: rm -rf /tmp/goth-tests
#endregion

release:
name: Release the SDK to NPM and GitHub
needs: run-integration-and-e2e-tests
Expand Down
24 changes: 24 additions & 0 deletions examples/docs-examples/examples/composing-tasks/batch-end.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => {
const res = await ctx
.beginBatch()
.uploadFile("./worker.mjs", "/golem/input/worker.mjs")
.run("node /golem/input/worker.mjs > /golem/input/output.txt")
.run("cat /golem/input/output.txt")
.downloadFile("/golem/input/output.txt", "./output.txt")
.end()
.catch((error) => console.error(error)); // to be removed and replaced with try & catch

return res[2]?.stdout;
});

console.log(result);
await executor.end();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => {
const res = await ctx
.beginBatch()
.uploadFile("./worker.mjs", "/golem/input/worker.mjs")
.run("node /golem/input/worker.mjs > /golem/input/output.txt")
.run("cat /golem/input/output.txt")
.downloadFile("/golem/input/output.txt", "./output.txt")
.endStream();

res.on("data", (data) => (data.index == 2 ? console.log(data.stdout) : ""));
res.on("error", (error) => console.error(error));
res.on("close", () => executor.end());
});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => {
const res = await ctx
.beginBatch()
.uploadFile("./worker.mjs", "/golem/input/worker.mjs")
.run("node /golem/input/worker.mjs > /golem/input/output.txt")
.run("cat /golem/input/output.txt")
.downloadFile("/golem/input/output.txt", "./output.txt")
.endStream();

for await (const chunk of res) {
console.log(chunk.stdout);
}
});

await executor.end();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => {
await ctx.uploadFile("./worker.mjs", "/golem/input/worker.mjs");
await ctx.run("node /golem/input/worker.mjs > /golem/input/output.txt");
const result = await ctx.run("cat /golem/input/output.txt");
await ctx.downloadFile("/golem/input/output.txt", "./output.txt");
return result.stdout;
});

console.log(result);

await executor.end();
})();
13 changes: 13 additions & 0 deletions examples/docs-examples/examples/composing-tasks/single-command.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { TaskExecutor } = require("@golem-sdk/golem-js");

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => (await ctx.run("node -v")).stdout);
await executor.end();

console.log("Task result:", result);
})();
13 changes: 13 additions & 0 deletions examples/docs-examples/examples/composing-tasks/single-command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => (await ctx.run("node -v")).stdout);
await executor.end();

console.log("Task result:", result);
})();
13 changes: 13 additions & 0 deletions examples/docs-examples/examples/composing-tasks/single-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run<string | unknown>(async (ctx) => (await ctx.run("node -v")).stdout);
await executor.end();

console.log("Task result:", result);
})();
1 change: 1 addition & 0 deletions examples/docs-examples/examples/composing-tasks/worker.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello World");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some action log
24 changes: 24 additions & 0 deletions examples/docs-examples/examples/executing-tasks/before-each.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
maxParallelTasks: 3,
});

executor.beforeEach(async (ctx) => {
console.log(ctx.provider.name + " is downloading action_log file");
await ctx.uploadFile("./action_log.txt", "/golem/input/action_log.txt");
});

await executor.forEach([1, 2, 3, 4, 5], async (ctx, item) => {
await ctx
.beginBatch()
.run(`echo ` + `'processing item: ` + item + `' >> /golem/input/action_log.txt`)
.downloadFile("/golem/input/action_log.txt", "./output_" + ctx.provider.name + ".txt")
.end();
});

await executor.end();
})();
16 changes: 16 additions & 0 deletions examples/docs-examples/examples/executing-tasks/foreach.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const data = [1, 2, 3, 4, 5];

await executor.forEach(data, async (ctx, item) => {
console.log((await ctx.run(`echo "${item}"`)).stdout);
});

await executor.end();
})();
16 changes: 16 additions & 0 deletions examples/docs-examples/examples/executing-tasks/map.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const data = [1, 2, 3, 4, 5];

const results = executor.map(data, (ctx, item) => ctx.run(`echo "${item}"`));

for await (const result of results) console.log(result.stdout);

await executor.end();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
maxParallelTasks: 3, // default is 5
});

const data = [1, 2, 3, 4, 5];

const results = executor.map(data, (ctx, item) => ctx.run(`echo "${item}"`));

for await (const result of results) console.log(result.stdout);

await executor.end();
})();
14 changes: 14 additions & 0 deletions examples/docs-examples/examples/executing-tasks/single-run.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TaskExecutor } from "@golem-sdk/golem-js";

(async () => {
const executor = await TaskExecutor.create({
package: "529f7fdaf1cf46ce3126eb6bbcd3b213c314fe8fe884914f5d1106d4",
yagnaOptions: { apiKey: "try_golem" },
});

const result = await executor.run(async (ctx) => (await ctx.run("node -v")).stdout);

await executor.end();

console.log("Task result:", result);
})();
Loading
Loading