2022-06-14 23:59:41 -06:00
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
2022-06-15 01:28:18 -06:00
build-test-synapse-image :
2022-06-14 23:59:41 -06:00
runs-on : ubuntu-latest
permissions :
contents : read
packages : write
outputs :
# Make the Docker image name available to use in other jobs as `${{
2022-06-15 01:28:18 -06:00
# needs.build-test-synapse-image.outputs.docker_image_name }}`. Also see
2022-06-14 23:59:41 -06:00
# 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
2022-06-15 01:28:18 -06:00
- 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 }}`
2022-06-14 23:59:41 -06:00
id : save_var
2022-06-15 01:28:18 -06:00
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
2022-06-14 23:59:41 -06:00
- name : Build and push Docker image
uses : docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with :
push : true
context : test/dockerfiles/
file : 'test/dockerfiles/Synapse.Dockerfile'
2022-06-15 01:28:18 -06:00
tags : ${{ steps.meta.outputs.tags }}
labels : ${{ steps.meta.outputs.labels }}
2022-06-14 23:59:41 -06:00
tests :
2022-06-15 01:28:18 -06:00
needs : [ build-test-synapse-image]
2022-06-14 23:59:41 -06:00
runs-on : ubuntu-latest
strategy :
matrix :
node-version : [ 16. x]
services :
# We need two homeservers that federate with each other to test with
hs1 :
2022-06-15 01:28:18 -06:00
image : ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }}
2022-06-14 23:59:41 -06:00
credentials :
username : ${{ github.actor }}
password : ${{ secrets.GITHUB_TOKEN }}
ports :
- 11008 : 8008
env :
SERVER_NAME : hs1
hs2 :
2022-06-15 01:28:18 -06:00
image : ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }}
2022-06-14 23:59:41 -06:00
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 }}
2022-09-27 21:21:00 -06:00
cache : 'npm'
2022-06-14 23:59:41 -06:00
- name : Install dependencies
run : npm ci
- name : Run build
run : npm run build
- name : Test!
run : npm test