Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from thecodingmachine/develop
Browse files Browse the repository at this point in the history
[pull] develop from thecodingmachine:develop
  • Loading branch information
basisbit authored Jan 5, 2022
2 parents f51af6f + c46882e commit 6a8c8c3
Show file tree
Hide file tree
Showing 308 changed files with 22,491 additions and 5,961 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
working-directory: "messages"

- name: "Build proto messages"
run: yarn run proto && yarn run copy-to-front
run: yarn run ts-proto && yarn run copy-to-front-ts-proto && yarn run json-copy-to-front
working-directory: "messages"

- name: "Create index.html"
Expand All @@ -62,18 +62,13 @@ jobs:
working-directory: "front"

- name: "Pretty"
run: yarn run pretty
run: yarn run pretty-check
working-directory: "front"

- name: "Jasmine"
run: yarn test
working-directory: "front"

# We will enable prettier checks on front in a few month, when most PRs without prettier have been merged
# - name: "Prettier"
# run: yarn run pretty-check
# working-directory: "front"

continuous-integration-pusher:
name: "Continuous Integration Pusher"

Expand Down Expand Up @@ -102,7 +97,7 @@ jobs:
working-directory: "messages"

- name: "Build proto messages"
run: yarn run proto && yarn run copy-to-pusher
run: yarn run proto && yarn run copy-to-pusher && yarn run json-copy-to-pusher
working-directory: "messages"

- name: "Build"
Expand Down
126 changes: 126 additions & 0 deletions .github/workflows/end_to_end_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "End to end tests"

on:
push:
branches:
- master
- develop
pull_request:

jobs:

start-runner:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
name: Start self-hosted EC2 runner
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
uses: machulav/ec2-github-runner@v2
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
ec2-image-id: ami-094dbcc53250a2480
ec2-instance-type: t3.xlarge
subnet-id: subnet-0ac40025f559df1bc
security-group-id: sg-0e36e96e3b8ed2d64
#iam-role-name: my-role-name # optional, requires additional permissions
#aws-resource-tags: > # optional, requires additional permissions
# [
# {"Key": "Name", "Value": "ec2-github-runner"},
# {"Key": "GitHubRepository", "Value": "${{ github.repository }}"}
# ]


end-to-end-tests:
name: "End-to-end testcafe tests"

needs: start-runner # required to start the main job when the runner is ready
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner

steps:
- name: "Checkout"
uses: "actions/checkout@v2.0.0"

- name: "Setup NodeJS"
uses: actions/setup-node@v1
with:
node-version: '14.x'

- name: "Install dependencies"
run: npm install
working-directory: "tests"

- name: "Setup .env file"
run: cp .env.template .env

- name: "Edit ownership of file for test cases"
run: sudo chown 1000:1000 -R .

- name: "Start environment"
run: LIVE_RELOAD=0 docker-compose up -d

- name: "Wait for environment to build (and downloading testcafe image)"
run: (docker-compose -f docker-compose.testcafe.yml build &) && docker-compose logs -f --tail=0 front | grep -q "Compiled successfully"

# - name: "temp debug: display logs"
# run: docker-compose logs
#
# - name: "Wait for back start"
# run: docker-compose logs -f back | grep -q "WorkAdventure HTTP API starting on port"
#
# - name: "Wait for pusher start"
# run: docker-compose logs -f pusher | grep -q "WorkAdventure starting on port"

- name: "Run tests"
run: PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up --exit-code-from testcafe

- name: Upload failed tests
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: my-artifact
path: './tests/screenshots/'

- name: Display state
if: ${{ failure() }}
run: docker-compose ps

- name: Display logs
if: ${{ failure() }}
run: docker-compose logs

stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- end-to-end-tests # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
steps:
- name: Configure AWS credentials
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop EC2 runner
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
uses: machulav/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
2 changes: 1 addition & 1 deletion .github/workflows/push-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
working-directory: "messages"

- name: "Build proto messages"
run: yarn run proto && yarn run copy-to-front
run: yarn run ts-proto && yarn run copy-to-front-ts-proto && yarn run json-copy-to-front
working-directory: "messages"

- name: "Create index.html"
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

(
cd messages || exit
yarn run precommit
)
(
cd front || exit
yarn run precommit
Expand Down
48 changes: 45 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ We love to receive contributions from our community — you!
There are many ways to contribute, from writing tutorials or blog posts, improving the documentation,
submitting bug reports and feature requests or writing code which can be incorporated into WorkAdventure itself.

## Contributing external resources

You can share your work on maps / articles / videos related to WorkAdventure on our [awesome-workadventure](https://github.com/workadventure/awesome-workadventure) list.

## Developer documentation

Documentation targeted at developers can be found in the [`/docs/dev`](docs/dev/)

## Using the issue tracker

First things first: **Do NOT report security vulnerabilities in public issues!**.
Expand Down Expand Up @@ -59,9 +67,43 @@ $ docker-compose exec back yarn run pretty

WorkAdventure is based on a video game engine (Phaser), and video games are not the easiest programs to unit test.

Nevertheless, if your code can be unit tested, please provide a unit test (we use Jasmine).
Nevertheless, if your code can be unit tested, please provide a unit test (we use Jasmine), or an end-to-end test (we use Testcafe).

If you are providing a new feature, you should setup a test map in the `maps/tests` directory. The test map should contain
some description text describing how to test the feature. Finally, you should modify the `maps/tests/index.html` file
to add a reference to your newly created test map.
some description text describing how to test the feature.

* if the features is meant to be manually tested, you should modify the `maps/tests/index.html` file to add a reference
to your newly created test map
* if the features can be automatically tested, please provide a testcafe test

#### Running testcafe tests

End-to-end tests are available in the "/tests" directory.

To run these tests locally:

```console
$ LIVE_RELOAD=0 docker-compose up -d
$ cd tests
$ npm install
$ npm run test
```

Note: If your tests fail on a Javascript error in "sockjs", this is due to the
Webpack live reload. The Webpack live reload feature is conflicting with testcafe. This is why we recommend starting
WorkAdventure with the `LIVE_RELOAD=0` environment variable.

End-to-end tests can take a while to run. To run only one test, use:

```console
$ npm run test -- tests/[name of the test file].ts
```

You can also run the tests inside a container (but you will not have visual feedbacks on your test, so we recommend using
the local tests).

```console
$ LIVE_RELOAD=0 docker-compose up -d
# Wait 2-3 minutes for the environment to start, then:
$ PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up
```
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ In WorkAdventure you can move around your office and talk to your colleagues (us

See more features for your virtual office: https://workadventu.re/virtual-office

## Community resources

Check out resources developed by the WorkAdventure community at [awesome-workadventure](https://github.com/workadventure/awesome-workadventure)

## Setting up a development environment

Install Docker.
Expand Down
6 changes: 3 additions & 3 deletions back/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# protobuf build
FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder
FROM node:14.18.2-buster-slim@sha256:20bedf0c09de887379e59a41c04284974f5fb529cf0e13aab613473ce298da3d as builder
WORKDIR /usr/src
COPY messages .
RUN yarn install && yarn proto

# typescript build
FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2
FROM node:14.18.2-buster-slim@sha256:20bedf0c09de887379e59a41c04284974f5fb529cf0e13aab613473ce298da3d as builder2
WORKDIR /usr/src
COPY back/yarn.lock back/package.json ./
RUN yarn install
Expand All @@ -15,7 +15,7 @@ ENV NODE_ENV=production
RUN yarn run tsc

# final production image
FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76
FROM node:14.18.2-buster-slim@sha256:20bedf0c09de887379e59a41c04284974f5fb529cf0e13aab613473ce298da3d
WORKDIR /usr/src
COPY back/yarn.lock back/package.json ./
COPY --from=builder2 /usr/src/dist /usr/src/dist
Expand Down
10 changes: 5 additions & 5 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
"@types/mkdirp": "^1.0.1",
"@types/redis": "^2.8.31",
"@types/uuidv4": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"eslint": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"eslint": "^8.5.0",
"jasmine": "^3.5.0",
"lint-staged": "^11.0.0",
"prettier": "^2.3.1",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3"
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.4"
},
"lint-staged": {
"*.ts": [
Expand Down
12 changes: 6 additions & 6 deletions back/server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// lib/server.ts
import App from "./src/App";
import grpc from "grpc";
import {roomManager} from "./src/RoomManager";
import {IRoomManagerServer, RoomManagerService} from "./src/Messages/generated/messages_grpc_pb";
import {HTTP_PORT, GRPC_PORT} from "./src/Enum/EnvironmentVariable";
import { roomManager } from "./src/RoomManager";
import { IRoomManagerServer, RoomManagerService } from "./src/Messages/generated/messages_grpc_pb";
import { HTTP_PORT, GRPC_PORT } from "./src/Enum/EnvironmentVariable";

App.listen(HTTP_PORT, () => console.log(`WorkAdventure HTTP API starting on port %d!`, HTTP_PORT))
App.listen(HTTP_PORT, () => console.log(`WorkAdventure HTTP API starting on port %d!`, HTTP_PORT));

const server = new grpc.Server();
server.addService<IRoomManagerServer>(RoomManagerService, roomManager);

server.bind('0.0.0.0:'+GRPC_PORT, grpc.ServerCredentials.createInsecure());
server.bind(`0.0.0.0:${GRPC_PORT}`, grpc.ServerCredentials.createInsecure());
server.start();
console.log('WorkAdventure HTTP/2 API starting on port %d!', GRPC_PORT);
console.log("WorkAdventure HTTP/2 API starting on port %d!", GRPC_PORT);
Loading

0 comments on commit 6a8c8c3

Please sign in to comment.