name: Tests on: push: branches: [main] env: REGISTRY: ghcr.io GHCR_NAMESPACE: matrix-org/matrix-viewer IMAGE_NAME: matrix-viewer-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 build-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.build-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.build-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 }}" - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ steps.save_var.outputs.docker_image_name }} # Defaults (as indicated by https://github.com/docker/metadata-action/tree/97c170d70b5f8bfc77e6b23e68381f217cb64ded#tags-input). # Plus custom tags: # - Full length sha tags: | type=schedule type=ref,event=branch type=ref,event=tag type=ref,event=pr type=sha,format=long - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: push: true context: test/dockerfiles/ file: 'test/dockerfiles/Synapse.Dockerfile' tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} tests: needs: [build-test-synapse-image] runs-on: ubuntu-latest strategy: matrix: node-version: [18.x] services: # We need two homeservers that federate with each other to test with hs1: image: ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }} credentials: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} ports: - 11008:8008 env: SERVER_NAME: hs1 hs2: image: ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }} 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 }} cache: 'npm' - name: Install dependencies run: npm ci - name: Run build run: npm run build - name: Test! run: npm test