From cda2d98df0b8b953ff996749d5b0bf215cc87b0a Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 15 Jun 2022 00:59:41 -0500 Subject: [PATCH] Add testing to CI (#20) 1. Build test homeserver Docker images which can federate with each other 2. Run end-to-end (e2e) tests #### Dev notes Sharing variables across jobs when the `services` field can't access the `env` context, https://github.community/t/how-to-use-env-with-container-image/17252/24 ```yaml env: FOO: bar jobs: set_env: outputs: var: ${{ steps.save_var.outputs.var }} steps: - id: save_var run: echo "::set-output name=var::${{ env.FOO }}" actual_job: needs: set_env container: image: ...whatever_you_need_here...${{ needs.set_env.outputs.var }} ``` --- .github/workflows/tests.yaml | 106 ++++++++++++++++++++++++++++ package-lock.json | 52 +++++++++++--- package.json | 3 +- test/dockerfiles/Synapse.Dockerfile | 17 ++--- 4 files changed, 157 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..da2f6f6 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,106 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + REGISTRY: ghcr.io + GHCR_NAMESPACE: matrix-org/matrix-public-archive + IMAGE_NAME: matrix-public-archive-test-homeserver + +jobs: + # Create and publish a Docker image for a Synapse test instance that can + # federate with each other. + # + # Based off of + # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages + deploy-test-synapse-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + outputs: + # Make the Docker image name available to use in other jobs as `${{ + # needs.deploy-test-synapse-image.outputs.docker_image_name }}`. Also see + # the `save_var` step below for how this works. + docker_image_name: ${{ steps.save_var.outputs.docker_image_name }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the GitHub Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Trick to get env variables available in `needs` context which is + # available to use in almost everywhere + # (https://docs.github.com/en/actions/learn-github-actions/contexts). This + # is so that we can reference the same Docker image name in the `services` of + # the next job. + # + # via https://github.community/t/how-to-use-env-with-container-image/17252/25 + - name: Save the Docker image name to a variable so we can share and re-use it in other jobs via `${{ needs.deploy-test-synapse-image.outputs.docker_image_name }}` + id: save_var + run: echo "::set-output name=docker_image_name::${{ env.REGISTRY }}/${{ env.GHCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}" + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + push: true + tags: | + ${{ steps.save_var.outputs.docker_image_name }} + context: test/dockerfiles/ + file: 'test/dockerfiles/Synapse.Dockerfile' + + tests: + needs: [deploy-test-synapse-image] + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + services: + # We need two homeservers that federate with each other to test with + hs1: + image: ${{ needs.deploy-test-synapse-image.outputs.docker_image_name }} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + ports: + - 11008:8008 + env: + SERVER_NAME: hs1 + hs2: + image: ${{ needs.deploy-test-synapse-image.outputs.docker_image_name }} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + ports: + - 12008:8008 + env: + SERVER_NAME: hs2 + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm ci + + - name: Run build + run: npm run build + + - name: Test! + run: npm test diff --git a/package-lock.json b/package-lock.json index 2143f0a..e91256d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "dependencies": { "express": "^4.17.2", - "hydrogen-view-sdk": "^0.0.4", + "hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.0.12", "linkedom": "^0.14.1", "matrix-public-archive-shared": "file:./shared/", "nconf": "^0.11.3", @@ -621,6 +621,16 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "node_modules/core-js": { + "version": "3.23.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.23.1.tgz", + "integrity": "sha512-wfMYHWi1WQjpgZNC9kAlN4ut04TM9fUTdi7CqIoTVM7yaiOUQTklOzfb+oWH3r9edQcT3F887swuVmxrV+CC8w==", + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -1979,14 +1989,16 @@ } }, "node_modules/hydrogen-view-sdk": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.4.tgz", - "integrity": "sha512-HAqs1Fp0TK2n5UhfEPEl6fPCTV3O7MkBMEjZNbDZ32sqDUCs4iGtyvxy+2lZpifsWq463siB8FoH7725DCCMTA==", + "name": "@mlm/hydrogen-view-sdk", + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@mlm/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.12.tgz", + "integrity": "sha512-zPmJJVUKQCIxw9vAwcTzwU9OT/U/9Gvspafx10l8a2flguj8BLBOorYw0EghBK/MdSsc//b+GRwpYqrvz8VAfQ==", "dependencies": { "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz", "another-json": "^0.2.0", "base64-arraybuffer": "^0.2.0", - "dompurify": "^2.3.0" + "dompurify": "^2.3.0", + "off-color": "^2.0.0" } }, "node_modules/iconv-lite": { @@ -2775,6 +2787,14 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, + "node_modules/off-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/off-color/-/off-color-2.0.0.tgz", + "integrity": "sha512-JJ9ObbY2CzgT7F8PpdpHGNjQa7QbU8f4DkY3cCxYUq9NezYUMmL/oSofCc5MMaiUnNNBEFCc4w1unMA+R8syvw==", + "dependencies": { + "core-js": "^3.6.5" + } + }, "node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -4335,6 +4355,11 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "core-js": { + "version": "3.23.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.23.1.tgz", + "integrity": "sha512-wfMYHWi1WQjpgZNC9kAlN4ut04TM9fUTdi7CqIoTVM7yaiOUQTklOzfb+oWH3r9edQcT3F887swuVmxrV+CC8w==" + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -5240,14 +5265,15 @@ } }, "hydrogen-view-sdk": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.4.tgz", - "integrity": "sha512-HAqs1Fp0TK2n5UhfEPEl6fPCTV3O7MkBMEjZNbDZ32sqDUCs4iGtyvxy+2lZpifsWq463siB8FoH7725DCCMTA==", + "version": "npm:@mlm/hydrogen-view-sdk@0.0.12", + "resolved": "https://registry.npmjs.org/@mlm/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.12.tgz", + "integrity": "sha512-zPmJJVUKQCIxw9vAwcTzwU9OT/U/9Gvspafx10l8a2flguj8BLBOorYw0EghBK/MdSsc//b+GRwpYqrvz8VAfQ==", "requires": { "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz", "another-json": "^0.2.0", "base64-arraybuffer": "^0.2.0", - "dompurify": "^2.3.0" + "dompurify": "^2.3.0", + "off-color": "^2.0.0" } }, "iconv-lite": { @@ -5817,6 +5843,14 @@ "boolbase": "^1.0.0" } }, + "off-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/off-color/-/off-color-2.0.0.tgz", + "integrity": "sha512-JJ9ObbY2CzgT7F8PpdpHGNjQa7QbU8f4DkY3cCxYUq9NezYUMmL/oSofCc5MMaiUnNNBEFCc4w1unMA+R8syvw==", + "requires": { + "core-js": "^3.6.5" + } + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", diff --git a/package.json b/package.json index bab172c..18f7c6d 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "scripts": { "start-dev": "node server/start-dev.js", "lint": "eslint **/*.js", + "build": "vite build", "test": "npm run mocha -- test/e2e-tests.js --timeout 15000", "test-interactive": "npm run mocha -- test/e2e-tests.js --timeout 15000 --interactive", "nodemon": "nodemon", @@ -29,7 +30,7 @@ }, "dependencies": { "express": "^4.17.2", - "hydrogen-view-sdk": "^0.0.4", + "hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.0.12", "linkedom": "^0.14.1", "matrix-public-archive-shared": "file:./shared/", "nconf": "^0.11.3", diff --git a/test/dockerfiles/Synapse.Dockerfile b/test/dockerfiles/Synapse.Dockerfile index 85f76cd..bbc9339 100644 --- a/test/dockerfiles/Synapse.Dockerfile +++ b/test/dockerfiles/Synapse.Dockerfile @@ -1,15 +1,8 @@ -# A dockerfile which builds an image suitable for testing Synapse under -# complement. +# A dockerfile which builds an image suitable for creating test Synapse +# instances which federate with each other. # -# Currently this is based on the published 'synapse:latest' image -- ie, the -# most recent Synapse release. -# -# Also... none of the tests seem to pass yet. They do run though. -# -# To use it: -# -# (cd dockerfiles && docker build -t complement-synapse -f Synapse.Dockerfile .) -# COMPLEMENT_BASE_IMAGE=complement-synapse go test -v ./tests +# Currently this is based on Complement Synapse images which are based on the +# published 'synapse:latest' image -- ie, the most recent Synapse release. ARG SYNAPSE_VERSION=latest @@ -30,6 +23,8 @@ WORKDIR /data EXPOSE 8008 8448 +# Make sure the entrypoint is executable +RUN ["chmod", "+x", "/conf/start.sh"] ENTRYPOINT ["/conf/start.sh"] HEALTHCHECK --start-period=5s --interval=1s --timeout=1s \