E2e tests for adding a post to a collection #4785
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test & Ship | |
on: | |
- push | |
- pull_request | |
env: | |
CYPRESS_PROJECT_ID: '43gftm' | |
DEFAULT_NODE_VERSION: '16' | |
LC_ALL: en_US.UTF-8 | |
TZ: UTC | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
## While tests are not fixed | |
continue-on-error: false | |
strategy: | |
matrix: | |
node_version: | |
- '14' | |
- '16' | |
- '18' | |
include: | |
- node_version: '16' # update along with DEFAULT_NODE_VERSION | |
run_lint_tests: 'True' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node_version }} | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
run: | | |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
id: npm-cache | |
with: | |
path: ${{ steps.npm-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: | | |
set -e; | |
npm install; | |
- name: List installed dependencies | |
run: | | |
npm ls || true; | |
- uses: actions/cache@v3 | |
id: eslint-cache | |
with: | |
path: ./.eslintcache | |
key: ${{ runner.os }}-eslint-${{ hashFiles('.eslintrc.js', './apps/**/.eslintrc.js') }}-${{ github.ref_name }} | |
restore-keys: | | |
${{ runner.os }}-eslint-${{ hashFiles('.eslintrc.js', './apps/**/.eslintrc.js') }}-${{ github.event.repository.default_branch }} | |
- name: Run lint tests (web) | |
if: ${{ matrix.run_lint_tests }} | |
run: | | |
npm run lint; | |
- name: Run lint tests (mobile) | |
if: ${{ matrix.run_lint_tests }} | |
run: | | |
npm run mobile:lint; | |
# TBD: we need to make tests runnable in a CI environment | |
# currently Karma doesn't finish | |
# - name: Run tests | |
# run: | | |
# npm run test; | |
e2e-test: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
continue-on-error: true | |
services: | |
mysql: | |
image: mariadb:10.11 | |
ports: | |
- '33061:3306' | |
env: | |
MARIADB_ROOT_PASSWORD: root | |
MARIADB_DATABASE: ushahidi | |
MARIADB_USER: ushahidi | |
MARIADB_PASSWORD: ushahidi | |
LC_ALL: ${{ env.LC_ALL }} | |
TZ: ${{ env.TZ }} | |
redis: | |
image: redis:4-alpine | |
platform: | |
image: ghcr.io/ushahidi/platform:develop | |
credentials: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
ports: | |
- '8080:8080' | |
env: | |
APP_KEY: SomeRandomKey!!!SomeRandomKey!!! | |
DOCKERIZE_TIMEOUT: 180s | |
DOCKERIZE_WAIT_FOR_mysql: tcp://mysql:3306 | |
DOCKERIZE_WAIT_FOR_redis: tcp://redis:6379 | |
ENABLE_NGINX: 'true' | |
ENABLE_PHPFPM: 'true' | |
ENABLE_PLATFORM_TASKS: 'false' | |
DB_MIGRATIONS_HANDLED: 'false' | |
RUN_PLATFORM_MIGRATIONS: 'false' | |
DB_CONNECTION: mysql | |
DB_DATABASE: ushahidi | |
DB_HOST: mysql | |
DB_PORT: 3306 | |
DB_USERNAME: ushahidi | |
DB_PASSWORD: ushahidi | |
REDIS_HOST: redis | |
CACHE_DRIVER: redis | |
QUEUE_DRIVER: redis | |
LC_ALL: ${{ env.LC_ALL }} | |
TZ: ${{ env.TZ }} | |
steps: | |
- uses: actions/checkout@v3 | |
## set up API endpoint | |
- name: Setup API endpoint | |
run: | | |
set -ex; | |
SNAPSHOT_URL="https://ushahidi-static-web-assets.s3.eu-west-1.amazonaws.com/ushahidi-e2e-data.sql.gz" | |
wget -O sql-snapshot.sql.gz ${SNAPSHOT_URL} 2>/dev/null || { echo "Failed downloading snapshot!" && exit 1; } | |
tmp_defaults=`mktemp` | |
echo -e "[client]\nhost=127.0.0.1\nuser=ushahidi\nport=33061\npassword=ushahidi" > $tmp_defaults | |
zcat sql-snapshot.sql.gz | mysql --defaults-extra-file=$tmp_defaults ushahidi | |
echo '!! Snapshot restored !!' | |
while ! docker exec ${{ job.services.platform.id }} /bin/true ; do | |
echo "Waiting for platform container to start..." | |
sleep 1 | |
done | |
while ! docker exec ${{ job.services.platform.id }} util wait_bootstrap 60; do | |
echo "Platform still bootstrapping (logs follow)..." | |
docker logs ${{ job.services.platform.id }} | |
done | |
echo "Waiting for MySQL to be ready..." | |
docker exec ${{ job.services.platform.id }} util wait_for_mysql | |
echo "Running migrations..." | |
docker exec ${{ job.services.platform.id }} util run_migrations | |
- name: Verify and setup API endpoint | |
run: | | |
set -ex; | |
curl --fail http://localhost:8080/api/v3/config || \ | |
{ echo "Failed getting API config!"; | |
sleep 5; | |
docker logs ${{ job.services.platform.id }}; | |
exit 1; } | |
env_file=./apps/web-mzima-client/src/env.json | |
env_json="$(jq '.backend_url = "http://localhost:8080"' $env_file)" && | |
echo -E "${env_json}" > $env_file | |
## same as above step | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
run: | | |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
id: npm-cache | |
with: | |
path: ${{ steps.npm-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install; | |
- name: Run server | |
run: | | |
npm run web:serve & | |
- name: Wait until the front-end is ready | |
run: | | |
retry() { | |
local -r -i max_attempts="$1"; shift | |
local -r cmd="$@" | |
local -i attempt_num=1 | |
until $cmd | |
do | |
if (( attempt_num == max_attempts )) | |
then | |
echo "Attempt $attempt_num failed and there are no more attempts left!" | |
return 1 | |
else | |
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." | |
sleep $(( attempt_num++ )) | |
fi | |
done; | |
} | |
server='http://localhost:4200' | |
retry 60 timeout 1 curl --silent ${server}/index.html || { echo "Failed getting index.html!" && exit 1; } | |
- name: Cypress run | |
uses: cypress-io/github-action@v5 | |
with: | |
record: true | |
working-directory: e2e-testing | |
env: | |
CYPRESS_ush_admin_email: '${{secrets.e2e_ush_admin_email}}' | |
CYPRESS_ush_admin_pwd: '${{secrets.e2e_ush_admin_pwd}}' | |
CYPRESS_ush_admin_name: '${{secrets.e2e_ush_admin_name}}' | |
CYPRESS_ush_user_name: '${{secrets.e2e_ush_user_name}}' | |
CYPRESS_ush_user_email: '${{secrets.e2e_ush_user_email}}' | |
CYPRESS_ush_user_pwd: '${{secrets.e2e_ush_user_pwd}}' | |
CYPRESS_RECORD_KEY: ${{ secrets.E2E_CYPRESS_RECORD_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
ship: | |
needs: [test, e2e-test] | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Login to AWS Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: 513259414768.dkr.ecr.eu-west-1.amazonaws.com | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: | | |
513259414768.dkr.ecr.eu-west-1.amazonaws.com/platform-client-mzima | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=ref,event=tag | |
type=semver,pattern={{version}} | |
type=sha | |
- name: Build and push to Amazon ECR | |
uses: docker/build-push-action@v2 | |
with: | |
pull: true | |
push: ${{ github.event_name != 'pull_request' }} | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
gh-release: | |
needs: [test] | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.DEFAULT_NODE_VERSION }} | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
run: | | |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
id: npm-cache | |
with: | |
path: ${{ steps.npm-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: | | |
set -e; | |
npm install; | |
- name: prod build | |
id: bin_build | |
run: | | |
npm run web:build; | |
FILENAME="platform-client-mzima-${GITHUB_REF##*/}-bin.tar.gz" | |
tar -czv -f ${FILENAME} -C dist/apps/web-mzima-client/ . ; | |
rm -fr dist/apps/web-mzima-client; | |
echo "tarball=${FILENAME}" >> "$GITHUB_OUTPUT" | |
- name: dev build | |
id: bindev_build | |
run: | | |
npm run web:devbuild; | |
FILENAME="platform-client-mzima-${GITHUB_REF##*/}-bin-dev.tar.gz" ; | |
tar -czv -f ${FILENAME} -C dist/apps/web-mzima-client/ . ; | |
rm -fr dist/apps/web-mzima-client; | |
echo "tarball=${FILENAME}" >> "$GITHUB_OUTPUT" | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
draft: true | |
files: | | |
${{steps.bin_build.outputs.tarball}} | |
${{steps.bindev_build.outputs.tarball}} |