Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run tests on GitHub actions #805

Open
wants to merge 46 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b7f111f
try running tests on github actions
dmou May 31, 2021
10c972d
use non-interactive exec commands
dmou May 31, 2021
2beccdb
simplify docker push actions
dmou Jun 1, 2021
5b6fd11
load to local docker client
dmou Jun 1, 2021
a4e07e6
use docker ecr login
dmou Jun 1, 2021
bcb2fa4
use the right aws account
dmou Jun 1, 2021
773fc8f
don't retag image for local client
dmou Jun 1, 2021
6d1dc3e
remove travis
dmou Jun 1, 2021
babbb8f
fix typo
dmou Jun 1, 2021
a3bbee2
fix teardown step
dmou Jun 1, 2021
133efc8
use docker image instead of rebuilding if possible
dmou Jun 1, 2021
c692d9c
delete this too
dmou Jun 2, 2021
30b966b
add code coverage report
dmou Jun 2, 2021
d132efd
use local registry for cacheing
dmou Jun 2, 2021
d9055aa
fine be slow
dmou Jun 2, 2021
290d91f
remove volume mount so we don't rm -rf between tests
dmou Jun 11, 2021
bfa601a
try running tests in parallel
dmou Jun 11, 2021
8a8c298
cleanup workflow config
dmou Jun 11, 2021
7243591
restore volumes to docker-compose.yml
dmou Jun 11, 2021
649c765
try with different slack notify action
dmou Jun 11, 2021
1f6a0f5
tab to space
dmou Jun 11, 2021
bdae1b9
retry coverage report upload
dmou Jun 15, 2021
c3eb266
fix yaml typo
dmou Jun 15, 2021
685f7ec
fix coverage script aws install
dmou Jun 19, 2021
c6beb39
move coverage report to proper place
dmou Jun 27, 2021
4fed80c
use full path for aws command
dmou Jun 28, 2021
436e39e
do not mount app
dmou Jun 28, 2021
7325210
pass run_id as job_number
dmou Jun 28, 2021
aa572ef
temporary step to clear gha buildx cache
dmou Jun 28, 2021
c33d42c
add debug messages
dmou Jun 28, 2021
6a279f3
add git_committed_at env var for cc
dmou Jun 28, 2021
383ad6b
parse commit time locally
dmou Jun 28, 2021
8e90598
parse local branch commit time
dmou Jun 29, 2021
f5f51cc
force rm tmp/cache even on fresh start
dmou Jun 29, 2021
b8e43c2
initialize git info in upload step
dmou Jun 30, 2021
9dfa7f0
remove debug messages
dmou Jul 7, 2021
6629bbd
set aws default region to avoid botocore error
dmou Jul 7, 2021
5b1c4a8
specify region in s3 command
dmou Jul 7, 2021
b993376
pass aws creds to docker container
dmou Jul 9, 2021
7c25c97
wait for ES cluster to be responsive before starting tests
dmou Jul 13, 2021
3942283
set job name for unit tests
dmou Jul 13, 2021
308663d
loop for ES cluster response at startup
dmou Jul 14, 2021
342aea7
check ES availability before running setup-parallel-env.sh
dmou Jul 14, 2021
16ca6dc
don't wrap curl command
dmou Jul 14, 2021
9b174d9
don't wrap that other curl command
dmou Jul 14, 2021
cc50cb5
remove second check for ES status
dmou Jul 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 272 additions & 0 deletions .github/workflows/ci-test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
name: Build and Run Tests

on:
push

jobs:
setup:
runs-on: ubuntu-latest

env:
AWS_ACCOUNT_NUMBER: '848416313321'
AWS_REGION: 'eu-west-1'

outputs:
image: ${{ steps.build-image.outputs.image }}

steps:
- uses: actions/checkout@v2

- 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 }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ env.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Docker Build And Push To ECR
id: docker-build-ecr
uses: docker/build-push-action@v2
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
with:
push: true
tags: |
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

-
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache


test-functional:
runs-on: ubuntu-latest

needs: setup

env:
AWS_DEFAULT_REGION: 'eu-west-1'

steps:
- uses: actions/checkout@v2

- 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 }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Setup Functional Tests
id: setup-functional-tests
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker tag ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} api:latest

- name: Run Functional Tests
id: run-functional-tests
env:
GITHUB_JOB_NAME: functional-tests
run: |
DEPLOY_ENV=test docker-compose -f docker-compose.yml -f docker-test.yml up -d
until curl --silent -I -f --fail http://localhost:3000 ; do printf .; sleep 1; done
until curl -I -f --silent -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s'; do printf '.'; sleep 1; done
docker-compose exec -T api rm -r tmp/cache tmp/cache1 tmp/cache2 tmp/cache3 tmp/cache4 tmp/cache5 || true
docker-compose exec -T api mkdir -p tmp/cache tmp/cache1 tmp/cache2 tmp/cache3 tmp/cache4 tmp/cache5
docker-compose exec -T api test/setup-parallel-env.sh
docker-compose exec -T api bundle exec rake assets:precompile
docker-compose exec -T -e GITHUB_JOB_NAME=${{ env.GITHUB_JOB_NAME }} api test/run-tests.sh

- name: Save Coverage
id: functional-coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}
GITHUB_JOB_NAME: functional-tests
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
GIT_COMMITTED_AT=$(git log -1 --format=%ct)
docker-compose exec -T \
-e GIT_COMMIT_SHA=${{ env.GIT_COMMIT_SHA }} \
-e GIT_BRANCH=${{ env.GIT_BRANCH }} \
-e GITHUB_JOB_NAME=${{ env.GITHUB_JOB_NAME }} \
-e GITHUB_RUN_ID=${{ env.GITHUB_RUN_ID }} \
-e CC_TEST_REPORTER_ID=${{ env.CC_TEST_REPORTER_ID }} \
-e GIT_COMMITTED_AT=${GIT_COMMITTED_AT} \
-e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
-e AWS_REGION=${{ env.AWS_REGION }} \
api test/test-coverage.sh


test-unit:
runs-on: ubuntu-latest

needs: setup

env:
AWS_DEFAULT_REGION: 'eu-west-1'

steps:
- uses: actions/checkout@v2

- 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 }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Setup Unit Tests
id: setup-unit-tests
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker tag ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} api:latest

- name: Run Unit Tests
id: run-unit-tests
env:
GITHUB_JOB_NAME: unit-tests
run: |
DEPLOY_ENV=test docker-compose -f docker-compose.yml -f docker-test.yml up -d
until curl --silent -I -f --fail http://localhost:3000 ; do printf .; sleep 1; done
until curl -I -f --silent -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s'; do printf '.'; sleep 1; done
docker-compose exec -T api mkdir -p tmp/cache tmp/cache1 tmp/cache2 tmp/cache3 tmp/cache4 tmp/cache5
docker-compose exec -T api test/setup-parallel-env.sh
docker-compose exec -T api bundle exec rake assets:precompile
docker-compose exec -T -e GITHUB_JOB_NAME=${{ env.GITHUB_JOB_NAME }} api test/run-tests.sh

- name: Save Coverage
id: unit-coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}
GITHUB_JOB_NAME: unit-tests
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
GIT_COMMITTED_AT=$(git log -1 --format=%ct)
docker-compose exec -T \
-e GIT_COMMIT_SHA=${{ env.GIT_COMMIT_SHA }} \
-e GIT_BRANCH=${{ env.GIT_BRANCH }} \
-e GITHUB_JOB_NAME=${{ env.GITHUB_JOB_NAME }} \
-e GITHUB_RUN_ID=${{ env.GITHUB_RUN_ID }} \
-e CC_TEST_REPORTER_ID=${{ env.CC_TEST_REPORTER_ID }} \
-e GIT_COMMITTED_AT=${GIT_COMMITTED_AT} \
-e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
-e AWS_REGION=${{ env.AWS_REGION }} \
api test/test-coverage.sh

cleanup-and-notify:
runs-on: ubuntu-latest

needs:
- test-unit
- test-functional

env:
AWS_DEFAULT_REGION: 'eu-west-1'

steps:
- uses: actions/checkout@v2

- 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 }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1

- name: Upload Coverage
id: upload-coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
GIT_COMMITTED_AT=$(git log -1 --format=%ct)
docker-compose exec -T \
-e GIT_COMMIT_SHA=${{ env.GIT_COMMIT_SHA }} \
-e GIT_BRANCH=${{ env.GIT_BRANCH }} \
-e GITHUB_RUN_ID=${{ env.GITHUB_RUN_ID }} \
-e CC_TEST_REPORTER_ID=${{ env.CC_TEST_REPORTER_ID }} \
-e GIT_COMMITTED_AT=${GIT_COMMITTED_AT} \
-e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
-e AWS_REGION=${{ env.AWS_REGION }} \
api test/upload-coverage.sh

- name: Notify Slack
id: slack-notify
uses: 8398a7/action-slack@v3
if: ${{ always() }}
with:
status: custom
fields: workflow,job,commit,repo,ref,author,took,message
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_REPO} @ ${process.env.AS_REF}: ${process.env.AS_WORKFLOW}\n${process.env.AS_MESSAGE} (${process.env.AS_COMMIT})\nby ${process.env.AS_AUTHOR}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
ffmpegthumbnailer \
git \
graphicsmagick \
libidn11-dev \
inotify-tools \
libidn11-dev \
libpq-dev \
libtag1-dev \
libsqlite3-dev \
libtag1-dev \
lsof \
lz4 \
nodejs \
python-pip \
rename \
sqlite3 \
lsof \
python-pip
unzip

RUN python -m pip install -U setuptools wheel

Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ services:
- postgres
- redis
- minio
volumes:
- ".:/app"
environment:
RAILS_ENV: development
SERVER_PORT: 3000
networks:
- dev
- dev
12 changes: 11 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
# Wait for Elasticsearch
until curl --silent -XGET --fail http://elasticsearch:9200; do printf '.'; sleep 1; done

set_config() {
find config/ -iname \*.example | rename -v "s/.example//g"
}

if [[ "${DEPLOY_ENV}" == "test" ]]; then
set_config
touch tmp/parallel_runtime_test.log
chmod +w tmp/parallel_runtime_test.log
fi

# Rake tasks
if [ "$RAILS_ENV" == "test" ]
then
Expand All @@ -25,4 +35,4 @@ else
echo "pidfile '/app/tmp/pids/server-$RAILS_ENV.pid'" >> $puma
echo "port $SERVER_PORT" >> $puma
bundle exec puma -C $puma
fi
fi
2 changes: 2 additions & 0 deletions docker-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version: "2.2"
services:
api:
image: api
environment:
RAILS_ENV: test
DEPLOY_ENV: test
Loading