DV-000298: Improve the GitHub action file. #2
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: CI Pipeline | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
backend: | |
runs-on: ubuntu-latest | |
services: | |
mariadb: | |
image: mariadb:10.8.2 | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_USER: ${{ secrets.MYSQL_USER }} | |
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} | |
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }} | |
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} | |
options: --health-cmd="mysqladmin ping --silent" --health-interval=5s --health-timeout=2s --health-retries=3 | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Wait for MariaDB to be ready | |
run: | | |
for i in {1..30}; do | |
if mysqladmin ping -h127.0.0.1 --silent; then | |
echo "MariaDB is up!"; | |
break; | |
fi | |
echo "Waiting for MariaDB..."; | |
sleep 1; | |
done | |
- name: Setup Java 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
cache: gradle | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
gradle-version: 7.4.2 | |
- name: Build and Test Backend | |
env: | |
MYSQL_USER: ${{ secrets.MYSQL_USER }} | |
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} | |
REACT_APP_API_KEY: ${{ secrets.REACT_APP_API_KEY }} | |
REACT_APP_TOKEN: ${{ secrets.REACT_APP_TOKEN }} | |
run: ./gradlew clean build test # Use wrapper for consistent Gradle version | |
frontend: | |
runs-on: ubuntu-latest | |
needs: backend # Ensure frontend job only starts after backend job completes successfully | |
strategy: | |
matrix: | |
node-version: [ 18.x ] | |
os: [ ubuntu-latest ] | |
browser: [ chrome, firefox ] | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install Dependencies | |
run: npm ci # `npm ci` is recommended for CI environments as it installs exact versions from package-lock.json | |
- name: Install Docker Compose | |
uses: docker/compose-action@v2 | |
with: | |
version: 'v2.1.0' | |
- name: Start Docker Containers | |
run: | | |
docker-compose up --detach --build | |
docker-compose exec -T app wait-for-it localhost:3000 # Replace with appropriate service and port | |
- name: Run Cypress Smoke Tests | |
uses: cypress-io/github-action@v4 | |
with: | |
command: npm run cypress:run:smoke:test -- --browser ${{ matrix.browser }} | |
parallel: true | |
- name: Run Cypress Sanity Tests | |
uses: cypress-io/github-action@v4 | |
with: | |
command: npm run cypress:run:sanity:test -- --browser ${{ matrix.browser }} | |
parallel: true | |
- name: Generate Allure Report | |
uses: simple-elf/allure-report-action@master | |
if: always() | |
with: | |
allure_results: allure-results | |
- name: Deploy Allure Report to GitHub Pages | |
if: always() | |
uses: peaceiris/actions-gh-pages@v3 # Updated version | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: gh-pages | |
publish_dir: allure-report | |
- name: Stop Docker Containers | |
if: always() | |
run: docker-compose down |