matrix-public-archive/.github/workflows/tests.yaml

107 lines
3.3 KiB
YAML
Raw Normal View History

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