Skip to content

Nightly tests and report #188

Nightly tests and report

Nightly tests and report #188

# This workflow aim to run all UI tests on active branches
# and upload the report on Google cloud platform storage
name: Nightly tests and report
on:
workflow_run:
workflows: [ 'Nightly Build' ]
types:
- requested
env:
GC_PROJECT_ID: ${{ secrets.GC_PROJECT_ID }} # GCP project id
GC_SERVICE_KEY: ${{ secrets.GC_SERVICE_KEY }} # GCP service key
NODE_VERSION: '14' # Node version on this workflow (For all jobs)
API_NIGHTLY_IMPORT_HOOK: 'https://api-nightly.prestashop.com/hook/reports/import' # Nightly hook to import report
NIGHTLY_TOKEN: ${{ secrets.NIGHTLY_TOKEN }} # Nightly token to validate the import
TESTS_DIR: 'tests/UI' # Where UI tests are
permissions:
contents: read
jobs:
# First job: Run tests in parallel
test:
name: Nightly tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
BRANCH:
- develop
- 8.1.x
- 8.0.x
CAMPAIGN:
- 'sanity'
- 'sanity:productV2'
- 'regression'
- 'functional:BO:login'
- 'functional:BO:orders'
- 'functional:BO:catalog'
- 'functional:productV2'
- 'functional:BO:customer'
- 'functional:BO:customer-service'
- 'functional:BO:modules'
- 'functional:BO:design'
- 'functional:BO:shipping'
- 'functional:BO:payment'
- 'functional:BO:international'
- 'functional:BO:shop-parameters'
- 'functional:BO:advanced-parameters'
- 'functional:BO:header'
- 'functional:FO'
exclude:
- BRANCH: 8.0.x
CAMPAIGN: 'functional:productV2'
env:
GH_BRANCH: ${{ matrix.BRANCH }} # Branch to test
REPORTS_DIR: 'reports_${{ matrix.BRANCH }}' # Where to move test's reports
TEST_CAMPAIGN: 'test:${{ matrix.CAMPAIGN }}' # Command to execute from the matrix
PS_LANGUAGE: 'en'
PS_INSTALL_AUTO: 1
PS_DEV_MODE: 0
DB_SERVER: 'mysql'
DB_NAME: 'prestashop'
DB_PREFIX: 'tst_'
DB_USER: 'root'
DB_PASSWD: 'prestashop'
ADMIN_PASSWD: 'Correct Horse Battery Staple'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.GH_BRANCH }}
# Use docker to create shop
- name: Build and run shop with docker
timeout-minutes: 15
run: |
USER_ID=$(id -u) GROUP_ID=$(id -g) \
docker-compose -f docker-compose.yml up -d --build
bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/en/)" != "200" ]]; do sleep 5; done'
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
working-directory: ${{ env.TESTS_DIR }}
run: npm install
- name: Run tests
continue-on-error: true
working-directory: ${{ env.TESTS_DIR }}
env:
URL_FO: 'http://localhost:8001/'
SMTP_SERVER: '172.17.0.1'
run: npm run ${{ env.TEST_CAMPAIGN }}
# Rename and upload report as artifact
- name: Rename file reports
working-directory: ${{ env.TESTS_DIR }}
env:
REPORTS_DIR_PATH: ${{ github.workspace }}/${{ env.REPORTS_DIR }}
run: |
mkdir -p ${{ env.REPORTS_DIR_PATH }}
FILENAME="$( echo -e '${{ env.TEST_CAMPAIGN }}' | tr ':' '-' )"
mv ./mochawesome-report/mochawesome.json ${{ env.REPORTS_DIR_PATH }}/${FILENAME}.json
- uses: actions/upload-artifact@v3
name: Upload report
with:
name: reports_${{ env.GH_BRANCH }}
path: ${{ env.REPORTS_DIR }}
# Second job: Merge Mochawesome reports and upload them on GCP
merge-upload-reports:
name: Combine all reports and upload them
if: ${{ always() }}
needs:
- test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
BRANCH:
- develop
- 8.1.x
- 8.0.x
env:
GH_BRANCH: ${{ matrix.branch }} # Branch to test
REPORTS_DIR: 'reports_${{ matrix.BRANCH }}' # Where to move test's reports
COMBINED_REPORT_DIR: 'combined_reports' # Where to store the combined report
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.GH_BRANCH }}
- uses: actions/download-artifact@v3
name: Download reports
with:
name: reports_${{ env.GH_BRANCH }}
path: ${{ env.REPORTS_DIR }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
working-directory: ${{ env.TESTS_DIR }}
run: npm install
- name: Combine reports
working-directory: ${{ env.TESTS_DIR }}
env:
REPORTS_DIR_PATH: ${{ github.workspace }}/${{ env.REPORTS_DIR }}
COMBINED_REPORT_DIR_PATH: ${{ github.workspace }}/${{ env.COMBINED_REPORT_DIR }}
run: |
mkdir -p ${{ env.COMBINED_REPORT_DIR_PATH }}
REPORT_NAME="$(date +%Y-%m-%d)-${{ env.GH_BRANCH }}"
npx mochawesome-merge "${{ env.REPORTS_DIR_PATH }}/*.json" -o "${{ env.COMBINED_REPORT_DIR_PATH }}/${REPORT_NAME}.json"
- uses: google-github-actions/setup-gcloud@v0
name: Setup Cloud Sdk
with:
service_account_key: ${{ env.GC_SERVICE_KEY }}
project_id: ${{ env.GC_PROJECT_ID }}
- name: Upload to Google Cloud Storage (GCS)
run: gsutil cp -r "${{ env.COMBINED_REPORT_DIR }}/**" gs://prestashop-core-nightly/reports
# Add pushed reports to GCp on nightly
push-nightly-reports:
permissions:
contents: none
name: Push reports to nightly.prestashop.com
if: ${{ always() }}
needs:
- merge-upload-reports
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
BRANCH:
- develop
- 8.1.x
- 8.0.x
env:
GH_BRANCH: ${{ matrix.branch }}
steps:
- name: Push reports
run: |
REPORT_NAME="$(date +%Y-%m-%d)-${{ env.GH_BRANCH }}"
curl -v "${{ env.API_NIGHTLY_IMPORT_HOOK }}?token=${{ env.NIGHTLY_TOKEN }}&filename=${REPORT_NAME}.json"