Skip to content

Merge pull request #41 from sirchnik-xitaso/ci/fix-matrix-testing #200

Merge pull request #41 from sirchnik-xitaso/ci/fix-matrix-testing

Merge pull request #41 from sirchnik-xitaso/ci/fix-matrix-testing #200

Workflow file for this run

name: Docker
on:
push:
branches: ['main', 'dev', 'staging']
tags: ['v*.*.*']
pull_request:
branches: ['main', 'dev', 'staging']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# github.repository as <account>/<repo>
IMAGE_NAME: mnestix-browser
IMAGE_TAG: latest
# Update the version manually
IMAGE_TAG_VERSION: 1.3.2
REGISTRY_USER: ${{ secrets.DOCKER_USERNAME }}
REGISTRY_PASS: ${{ secrets.DOCKER_API_TOKEN }}
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run unit tests
id: test_units
run: yarn install && npx jest
build-browser-image:
name: Build browser image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build image
id: build
run: docker compose build mnestix-browser
- name: Save mnestix-browser image
run: docker save mnestix/mnestix-browser:latest -o mnestix-browser.tar
- name: Upload mnestix-browser artifact
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: mnestix-browser
path: mnestix-browser.tar
e2e-tests:
name: e2e test matrix
runs-on: ubuntu-latest
needs: ['build-browser-image']
permissions:
contents: read
strategy:
fail-fast: false
matrix:
# add more containers to run more tests in parallel
containers: [1, 2, 3, 4]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download mnestix-browser artifact
uses: actions/download-artifact@v4
with:
name: mnestix-browser
- name: Load mnestix-browser image
run: docker load -i mnestix-browser.tar
# image too big to be reused
- name: prepare tests
run: |
docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests build cypress-test
docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests pull
- name: Run e2e tests
id: test
run: |
docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests up -d &&
docker compose -f compose.yml -f docker-compose/compose.test.yml attach cypress-test
env:
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
- name: E2E test collect artifact
id: test_artifact
uses: actions/upload-artifact@v4
with:
name: cypress-artifacts-${{ matrix.containers }}
path: cypress-artifacts/
push-image:
name: Push image to registry
needs: ['build-browser-image', 'unit-tests', 'e2e-tests']
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/dev'
permissions:
contents: read
packages: write
steps:
- name: Extract branch name
id: extract_branch
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
- name: Download mnestix-browser artifact
uses: actions/download-artifact@v4
with:
name: mnestix-browser
- name: Load mnestix-browser image
run: docker load -i mnestix-browser.tar
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into docker hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASS }}
- name: Push Image to Production
id: push-prod
if: github.ref == 'refs/heads/main'
run: docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$IMAGE_TAG &&
docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$IMAGE_TAG_VERSION &&
docker push mnestix/$IMAGE_NAME:$IMAGE_TAG &&
docker push mnestix/$IMAGE_NAME:$IMAGE_TAG_VERSION
- name: Push Image to development
id: push-dev
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/staging'
env:
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
run: docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$BRANCH_NAME &&
docker push mnestix/$IMAGE_NAME:$BRANCH_NAME